Device Drivers
NuttX supports a variety of device drivers, which can be broadly divided in three classes:
Note
Device driver support depends on the in-memory, pseudo file system that is enabled by default.
Lower-half and upper-half
Drivers in NuttX generally work in two distinct layers:
An upper half which registers itself to NuttX using a call such as
register_driver()
orregister_blockdriver()
and implements the corresponding high-level interface (read, write, close, etc.). implements the interface. This upper half calls into the lower half via callbacks.A “lower half” which is typically hardware-specific. This is usually implemented at the architecture or board level.
Details about drivers implementation can be found in OS Drivers Design and Device Drivers.
Subdirectories of nuttx/drivers
1wire/
One Wire Drivers1wire device drivers.
analog/
Analog (ADC/DAC) DriversThis directory holds implementations of analog device drivers. This includes drivers for Analog to Digital Conversion (ADC) as well as drivers for Digital to Analog Conversion (DAC).
audio/
Audio Device DriversAudio device drivers.
bch/
Block Driver to Character DriverContains logic that may be used to convert a block driver into a character driver. This is the complementary conversion as that performed by loop.c.
can/
CAN DriversThis is the CAN drivers and logic support.
-
Clock management (CLK) device drivers.
contactless/
Constactless DevicesContactless devices are related to wireless devices. They are not communication devices with other similar peers, but couplers/interfaces to contactless cards and tags.
crypto/
Crypto DriversContains crypto drivers and support logic, including the
/dev/urandom
device.devicetree/
Device Tree supportDevice Tree support.
dma/
DMA DriversDMA drivers support.
eeprom/
EEPROMAn EEPROM is a form of Memory Technology Device (see
drivers/mtd
). EEPROMs are non-volatile memory like FLASH, but differ in underlying memory technology and differ in usage in many respects: They may not be organized into blocks (at least from the standpoint of the user) and it is not necessary to erase the EEPROM memory before re-writing it. In addition, EEPROMs tend to be much smaller than FLASH parts, usually only a few kilobytes vs megabytes for FLASH. EEPROM tends to be used to retain a small amount of device configuration information; FLASH tends to be used for program or massive data storage. For these reasons, it may not be convenient to use the more complex MTD interface but instead use the simple character interface provided by the EEPROM drivers.efuse/
EFUSE DriversEFUSE drivers support.
i2c/
I2C Device DriversI2C drivers and support logic.
i2s/
I2S DriversI2S drivers and support logic.
i3c/
I3C Device DriversI3C drivers and support logic.
input/
Input DevicesThis directory holds implementations of human input device (HID) drivers. This includes such things as mouse, touchscreen, joystick, keyboard and keypad drivers.
Note that USB HID devices are treated differently. These can be found under
usbdev/
orusbhost/
.ioexpander/
IO Expander Device DriversIO Expander drivers.
ipcc/
IPCC (Inter Processor Communication Controller) DriverIPCC (Inter Processor Communication Controller) driver.
-
Drivers for parallel and serial LCD and OLED type devices.
leds/
LEDSVarious LED-related drivers including discrete as well as PWM- driven LEDs.
loop/
Loop DeviceSupports the standard loop device that can be used to export a file (or character device) as a block device.
See
losetup()
andloteardown()
ininclude/nuttx/fs/fs.h
.math/
Math Acceleration DriversMATH Acceleration drivers.
misc/
dev_null.c and dev_zero.c rwbuffer.c ramdisk.cVarious drivers that don’t fit elsewhere.
mmcsd/
SDIO Device Drivers MMCSD Device DriversSupport for MMC/SD block drivers. MMC/SD block drivers based on SPI and SDIO/MCI interfaces are supported.
modem/
Modem DeviceModem Support.
motor/
Motor DriversMotor control drivers.
mtd/
Memory Technology Device DriversMemory Technology Device (MTD) drivers. Some simple drivers for memory technologies like FLASH, EEPROM, NVRAM, etc.
(Note: This is a simple memory interface and should not be confused with the “real” MTD developed at infradead.org. This logic is unrelated; I just used the name MTD because I am not aware of any other common way to refer to this class of devices).
net/
Network interface driversNetwork interface drivers.
notes/
Note Driver InterfaceNote Driver Support.
pinctrl/
Pinctrl Device DriversConfigure and manage pin.
pipes/
FIFO and named pipe driversFIFO and named pipe drivers. Standard interfaces are declared in
include/unistd.h
power/
Power-related DriversVarious drivers related to power management.
-
Remote Control Device Support.
regmap/
drivers/regmapRegmap Subsystems Support.
reset/
Reset DriverReset Driver Support.
rf/
RF DevicesRF Device Support.
rptun/
Remote Proc Tunnel DriversRemote Proc Tunnel Driver Support.
segger/
Segger RTT driversSegger RTT drivers.
sensors/
Sensor DriversDrivers for various sensors. A sensor driver differs little from other types of drivers other than they are use to provide measurements of things in environment like temperature, orientation, acceleration, altitude, direction, position, etc.
DACs might fit this definition of a sensor driver as well since they measure and convert voltage levels. DACs, however, are retained in the
analog/
sub-directory.serial/
Serial Device DriversFront-end character drivers for chip-specific UARTs. This provide some TTY-like functionality and are commonly used (but not required for) the NuttX system console.
spi/
SPI Device DriversSPI drivers and support logic.
syslog/
SYSLOGSystem logging devices.
timers/
Timers DriversIncludes support for various timer devices.
usbdev/
USB Device-Side DriversUSB device drivers.
usbhost/
USB Host-Side DriversUSB host drivers.
usbmisc/
USB Miscellaneous DriversUSB Miscellaneous drivers.
usbmonitor/
USB Monitor supportUSB Monitor support.
usrsock/
Usrsock DriverUsrsock Driver Support.
video/
Video Device DriversVideo-related drivers.
virtio/
Virtio Device DriversVirtio Device Support.
wireless/
Wireless DriversDrivers for various wireless devices.
Skeleton Files
Skeleton files are “empty” frameworks for NuttX drivers. They are provided to give you a good starting point if you want to create a new NuttX driver. The following skeleton files are available:
drivers/lcd/skeleton.c
Skeleton LCD driverdrivers/mtd/skeleton.c
Skeleton memory technology device driversdrivers/net/skeleton.c
Skeleton network/Ethernet driversdrivers/usbhost/usbhost_skeleton.c
Skeleton USB host class driver
Drivers Early Initialization
To initialize drivers early in the boot process, the drivers_early_initialize()
function is introduced. This is particularly beneficial for certain drivers,
such as SEGGER SystemView, or others that require initialization before the
system is fully operational.
It is important to note that during this early initialization phase, system resources are not yet available for use. This includes memory allocation, file systems, and any other system resources.