Difference between revisions of "Zephyr drivers"
m (Add notes on sensor_attr_set and sensor enums for channels and attributes) |
m (Add notes about driver API sensor_attr_set()) |
||
| Line 35: | Line 35: | ||
<pre> | <pre> | ||
sensor_attr_set() | sensor_attr_set() | ||
| − | int sensor_attr_set ( const struct device * dev, | + | int sensor_attr_set(const struct device* dev, |
| − | enum sensor_channel chan, | + | enum sensor_channel chan, |
| − | enum sensor_attribute attr, | + | enum sensor_attribute attr, |
| − | const struct sensor_value * val ) | + | const struct sensor_value* val) |
</pre> | </pre> | ||
. . . whose typedef is at https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/sensor.h#L431. | . . . whose typedef is at https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/sensor.h#L431. | ||
| + | Bosch sensor driver for the BMI323 implements its sensor attribute setter in bmi323.c as follows: | ||
| + | <pre> | ||
| + | static DEVICE_API(sensor, bosch_bmi323_api) = { | ||
| + | .attr_set = bosch_bmi323_driver_api_attr_set, | ||
| + | .attr_get = bosch_bmi323_driver_api_attr_get, | ||
| + | .trigger_set = bosch_bmi323_driver_api_trigger_set, | ||
| + | .sample_fetch = bosch_bmi323_driver_api_sample_fetch, | ||
| + | .channel_get = bosch_bmi323_driver_api_channel_get, | ||
| + | }; | ||
| + | |||
| + | |||
| + | </pre> | ||
== [[#top|^]] References == | == [[#top|^]] References == | ||
Revision as of 22:33, 21 February 2026
Keywords: sensor interrupts : sensor triggers : Zephyr triggers : sensor interrupt support
OVERVIEW
This page a stash point to hold Zephyr driver notes. Zephyr RTOS project includes a range of types of drivers. First type referenced by this page will be Zephyr's sensor drivers.
^ Zephyr Sensor Model
Zephyr 4.3.0 device driver documentation:
Zephyr 4.3.0 sensor model:
"Sensor attribute get" function prototype. This prototype reveals Zephyr's enumerations for sensor yyy . . .
Zephyr's sensor model plays a big role in the design of sensor drivers for this RTOS. Zephyr's [... sensor.h] header defines many things. Two important enums from this header file are:
_ Sensor channel enum _
_ Sensor attribute enum _
Sensor channels generally correspond to readings of a quantity in specific units, like degrees centigrade and acceleration in the x-axis. Sensor attributes generally corrrespond to configuration settings for a sensor, where these settings modify the way in which readings are taken and reported.
For a Zephyr driver to support configuration of a sensor's attributes, it must implement a function of the form:
sensor_attr_set()
int sensor_attr_set(const struct device* dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value* val)
. . . whose typedef is at https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/sensor.h#L431.
Bosch sensor driver for the BMI323 implements its sensor attribute setter in bmi323.c as follows:
static DEVICE_API(sensor, bosch_bmi323_api) = {
.attr_set = bosch_bmi323_driver_api_attr_set,
.attr_get = bosch_bmi323_driver_api_attr_get,
.trigger_set = bosch_bmi323_driver_api_trigger_set,
.sample_fetch = bosch_bmi323_driver_api_sample_fetch,
.channel_get = bosch_bmi323_driver_api_channel_get,
};
^ References
1. https://github.com/zephyrproject-rtos/zephyr/issues/30133