Driver Code
An Embedd device driver consists of a set of files generated from a device datasheet. It allows users to access the functionality of the device. The final archive contains two types of files:
- Library files providing common structures, data types, etc.
- Generated files providing specific device implementation
Get Started
To get started with generated driver perform the following actions:
- Unzip the downloaded archive to a preferable location in your project and add them to your build system.
- Include the main driver’s header file. It is named like device_class.h. For example: the name of this file for TMP112 looks like tmp112_temperature_sensors.h
- Init device’s bus object.
- Check all “weak” functions and add implementation if it is needed.
Device Usage
Registers
Registers are small storage locations that manage specific functions or data within the device. Each register has a unique address that allows it to be accessed and modified. These registers can store configuration settings, calibration data, or measurement outputs, controlling device behavior and facilitating communication between the peripheral device and the processor it’s connected to. They play a crucial role in setting operational modes, initiating actions, and reading sensor data, effectively acting as the interface for the internal state and operations of the device.
The file device_class_registers.h provides information about all the reagisters a device has. Let’s take HDC2080 as shown in the example, and write data to the HUM_OFFSET_ADJUST register and then read it back. The file hdc2080_humidity_moisture_sensors_data_types.h contains all the information about the type of data a register contains. Here is the information about data type contained in HUM_OFFSET_ADJUST register:
The file hdc2080_humidity_moisture_sensors_registers.h contains all the information about the registers device has. Here is information about HUM_OFFSET_ADJUST register and its declaration:
Here are the Macros providing an access to the device’s registers:
Finally, to demonstrate writing to and reading from the HUM_OFFSET_ADJUST register, consider the following C code snippet: