2020-10-20 16:40:45 +08:00
|
|
|
.. _chardev:
|
|
|
|
|
2020-09-06 05:36:36 +08:00
|
|
|
========================
|
|
|
|
Character Device Drivers
|
|
|
|
========================
|
|
|
|
|
|
|
|
Character device drivers have these properties:
|
|
|
|
|
|
|
|
- ``include/nuttx/fs/fs.h``. All structures and APIs needed
|
|
|
|
to work with character drivers are provided in this header
|
|
|
|
file.
|
|
|
|
|
|
|
|
- ``struct file_operations``. Each character device driver
|
|
|
|
must implement an instance of ``struct file_operations``. That
|
|
|
|
structure defines a call table with the following methods:
|
|
|
|
|
|
|
|
- ``int register_driver(const char *path, const struct file_operations *fops, mode_t mode, void *priv);``.
|
|
|
|
Each character driver registers itself by calling
|
|
|
|
``register_driver()``, passing it the ``path`` where it will
|
2020-10-20 16:40:45 +08:00
|
|
|
appear in the :ref:`pseudo file system <file_system_overview>` and it's
|
2020-09-06 05:36:36 +08:00
|
|
|
initialized instance of ``struct file_operations``.
|
|
|
|
|
|
|
|
- **User Access**. After it has been registered, the character
|
2020-10-20 16:40:45 +08:00
|
|
|
driver can be accessed by user code using the standard driver
|
|
|
|
operations including
|
2020-09-06 05:36:36 +08:00
|
|
|
``open()``, ``close()``, ``read()``, ``write()``, etc.
|
|
|
|
|
|
|
|
- **Specialized Character Drivers**. Within the common character
|
|
|
|
driver framework, there are different specific varieties of
|
|
|
|
*specialized* character drivers. The unique requirements of the
|
|
|
|
underlying device hardware often mandates some customization of
|
|
|
|
the character driver. These customizations tend to take the
|
|
|
|
form of:
|
|
|
|
|
|
|
|
- Device-specific ``ioctl()`` commands used to performed
|
|
|
|
specialized operations on the device. These ``ioctl()`` will
|
|
|
|
be documented in header files under ``include/nuttx`` that
|
|
|
|
detail the specific device interface.
|
|
|
|
- Specialized I/O formats. Some devices will require that
|
|
|
|
``read()`` and/or ``write()`` operations use data conforming
|
|
|
|
to a specific format, rather than a plain stream of bytes.
|
|
|
|
These specialized I/O formats will be documented in header
|
|
|
|
files under ``include/nuttx`` that detail the specific
|
|
|
|
device interface. The typical representation of the I/O
|
|
|
|
format will be a C structure definition.
|
|
|
|
|
|
|
|
The specialized character drivers support by NuttX are
|
|
|
|
documented in the following paragraphs.
|
|
|
|
|
|
|
|
- **Examples**: ``drivers/dev_null.c``, ``drivers/fifo.c``,
|
|
|
|
``drivers/serial.c``, etc.
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:caption: Supported Drivers
|
2020-10-19 00:48:44 +08:00
|
|
|
|
2020-09-06 05:36:36 +08:00
|
|
|
serial.rst
|
|
|
|
touchscreen.rst
|
|
|
|
analog.rst
|
|
|
|
pwm.rst
|
|
|
|
can.rst
|
|
|
|
quadrature.rst
|
|
|
|
timer.rst
|
|
|
|
rtc.rst
|
|
|
|
watchdog.rst
|
|
|
|
keypad.rst
|
2020-10-19 00:33:54 +08:00
|
|
|
note.rst
|
2021-03-29 18:18:07 +08:00
|
|
|
foc.rst
|
2022-10-10 06:57:44 +08:00
|
|
|
ws2812.rst
|
2020-09-06 05:36:36 +08:00
|
|
|
|