The following diagram highlights the different devices accessible by your application:
These devices can be on-chip sensors (temperature, battery), interface to external sensors and actuators (e.g. GPIO, SPI, I2C), or miscellaneous devices (e.g. the random number generator).
All these devices are accessed through the same set of 5 functions, which define the Device API. This API is designed to make the devices look like files. Having a common interface greatly simplifies your application.
- dn_open() is used to open a device. The exact arguments to pass to this functions depends on the device that is opened. Some devices require no arguments. Others, such as the I2C device, require you to pass an pass an argument (e.g. the baudrate).
- dn_close() is used to close a previously opened device. Once it is closed, this device can be re-opened and re-used, for example, by a different task.
- dn_ioctl() is used to configure a previously opened device, and is only available on select devices. An example use case is re-configuring the baudrate on the UART device.
- dn_read() is used to read a value from a previously opened device, and is only available on select devices. An example use case is retrieving the voltage from an ADC channel.
- dn_write() is used to write a value to a previously opened device, and is only available on select devices. An example use case is setting the output state of a GPIO.
The Device API is documented for each device in the Doxygen-based documentation inside your
Unable to render {include} The included page could not be found.
file.