Zephyr API Documentation
3.6.99
A Scalable Open Source RTOS
|
Public APIs for the sensor driver. More...
#include <errno.h>
#include <stdlib.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor_data_types.h>
#include <zephyr/dsp/types.h>
#include <zephyr/rtio/rtio.h>
#include <zephyr/sys/iterable_sections.h>
#include <zephyr/types.h>
#include <syscalls/sensor.h>
Go to the source code of this file.
Data Structures | |
struct | sensor_value |
Representation of a sensor readout value. More... | |
struct | sensor_trigger |
Sensor trigger spec. More... | |
struct | sensor_chan_spec |
Sensor Channel Specification. More... | |
struct | sensor_decoder_api |
Decodes a single raw data buffer. More... | |
struct | sensor_decode_context |
Used for iterating over the data frames via the sensor_decoder_api. More... | |
struct | sensor_stream_trigger |
struct | sensor_read_config |
struct | sensor_driver_api |
struct | sensor_data_generic_header |
Macros | |
#define | SENSOR_DECODE_CONTEXT_INIT(decoder_, buffer_, channel_type_, channel_index_) |
Initialize a sensor_decode_context. | |
#define | SENSOR_STREAM_TRIGGER_PREP(_trigger, _opt) |
#define | SENSOR_DT_READ_IODEV(name, dt_node, ...) |
Define a reading instance of a sensor. | |
#define | SENSOR_DT_STREAM_IODEV(name, dt_node, ...) |
Define a stream instance of a sensor. | |
#define | SENSOR_CHANNEL_3_AXIS(chan) |
checks if a given channel is a 3-axis channel | |
#define | SENSOR_G 9806650LL |
The value of gravitational constant in micro m/s^2. | |
#define | SENSOR_PI 3141592LL |
The value of constant PI in micros. | |
#define | SENSOR_INFO_DEFINE(name, ...) |
#define | SENSOR_INFO_DT_DEFINE(node_id) |
#define | SENSOR_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, data_ptr, cfg_ptr, level, prio, api_ptr, ...) |
Like DEVICE_DT_DEFINE() with sensor specifics. | |
#define | SENSOR_DEVICE_DT_INST_DEFINE(inst, ...) SENSOR_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__) |
Like SENSOR_DEVICE_DT_DEFINE() for an instance of a DT_DRV_COMPAT compatible. | |
#define | SENSOR_DECODER_NAME() UTIL_CAT(DT_DRV_COMPAT, __decoder_api) |
Get the decoder name for the current driver. | |
#define | SENSOR_DECODER_DT_GET(node_id) &UTIL_CAT(DT_STRING_TOKEN_BY_IDX(node_id, compatible, 0), __decoder_api) |
Statically get the decoder for a given node. | |
#define | SENSOR_DECODER_API_DT_DEFINE() |
Define a decoder API. | |
Typedefs | |
typedef void(* | sensor_trigger_handler_t) (const struct device *dev, const struct sensor_trigger *trigger) |
Callback API upon firing of a trigger. | |
typedef int(* | sensor_attr_set_t) (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) |
Callback API upon setting a sensor's attributes. | |
typedef int(* | sensor_attr_get_t) (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val) |
Callback API upon getting a sensor's attributes. | |
typedef int(* | sensor_trigger_set_t) (const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) |
Callback API for setting a sensor's trigger and handler. | |
typedef int(* | sensor_sample_fetch_t) (const struct device *dev, enum sensor_channel chan) |
Callback API for fetching data from a sensor. | |
typedef int(* | sensor_channel_get_t) (const struct device *dev, enum sensor_channel chan, struct sensor_value *val) |
Callback API for getting a reading from a sensor. | |
typedef int(* | sensor_get_decoder_t) (const struct device *dev, const struct sensor_decoder_api **api) |
Get the decoder associate with the given device. | |
typedef int(* | sensor_submit_t) (const struct device *sensor, struct rtio_iodev_sqe *sqe) |
typedef void(* | sensor_processing_callback_t) (int result, uint8_t *buf, uint32_t buf_len, void *userdata) |
Callback function used with the helper processing function. | |
Functions | |
static bool | sensor_chan_spec_eq (struct sensor_chan_spec chan_spec0, struct sensor_chan_spec chan_spec1) |
Check if channel specs are equivalent. | |
static int | sensor_decode (struct sensor_decode_context *ctx, void *out, uint16_t max_count) |
Decode N frames using a sensor_decode_context. | |
int | sensor_natively_supported_channel_size_info (struct sensor_chan_spec channel, size_t *base_size, size_t *frame_size) |
int | sensor_attr_set (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) |
Set an attribute for a sensor. | |
int | sensor_attr_get (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val) |
Get an attribute for a sensor. | |
static int | sensor_trigger_set (const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) |
Activate a sensor's trigger and set the trigger handler. | |
int | sensor_sample_fetch (const struct device *dev) |
Fetch a sample from the sensor and store it in an internal driver buffer. | |
int | sensor_sample_fetch_chan (const struct device *dev, enum sensor_channel type) |
Fetch a sample from the sensor and store it in an internal driver buffer. | |
int | sensor_channel_get (const struct device *dev, enum sensor_channel chan, struct sensor_value *val) |
Get a reading from a sensor device. | |
int | sensor_get_decoder (const struct device *dev, const struct sensor_decoder_api **decoder) |
Get the sensor's decoder API. | |
int | sensor_reconfigure_read_iodev (struct rtio_iodev *iodev, const struct device *sensor, const struct sensor_chan_spec *channels, size_t num_channels) |
Reconfigure a reading iodev. | |
static int | sensor_stream (struct rtio_iodev *iodev, struct rtio *ctx, void *userdata, struct rtio_sqe **handle) |
static int | sensor_read (struct rtio_iodev *iodev, struct rtio *ctx, void *userdata) |
Read data from a sensor. | |
void | sensor_processing_with_callback (struct rtio *ctx, sensor_processing_callback_t cb) |
Helper function for common processing of sensor data. | |
static int32_t | sensor_ms2_to_g (const struct sensor_value *ms2) |
Helper function to convert acceleration from m/s^2 to Gs. | |
static void | sensor_g_to_ms2 (int32_t g, struct sensor_value *ms2) |
Helper function to convert acceleration from Gs to m/s^2. | |
static int32_t | sensor_ms2_to_ug (const struct sensor_value *ms2) |
Helper function to convert acceleration from m/s^2 to micro Gs. | |
static void | sensor_ug_to_ms2 (int32_t ug, struct sensor_value *ms2) |
Helper function to convert acceleration from micro Gs to m/s^2. | |
static int32_t | sensor_rad_to_degrees (const struct sensor_value *rad) |
Helper function for converting radians to degrees. | |
static void | sensor_degrees_to_rad (int32_t d, struct sensor_value *rad) |
Helper function for converting degrees to radians. | |
static int32_t | sensor_rad_to_10udegrees (const struct sensor_value *rad) |
Helper function for converting radians to 10 micro degrees. | |
static void | sensor_10udegrees_to_rad (int32_t d, struct sensor_value *rad) |
Helper function for converting 10 micro degrees to radians. | |
static double | sensor_value_to_double (const struct sensor_value *val) |
Helper function for converting struct sensor_value to double. | |
static float | sensor_value_to_float (const struct sensor_value *val) |
Helper function for converting struct sensor_value to float. | |
static int | sensor_value_from_double (struct sensor_value *val, double inp) |
Helper function for converting double to struct sensor_value. | |
static int | sensor_value_from_float (struct sensor_value *val, float inp) |
Helper function for converting float to struct sensor_value. | |
static int64_t | sensor_value_to_milli (const struct sensor_value *val) |
Helper function for converting struct sensor_value to integer milli units. | |
static int64_t | sensor_value_to_micro (const struct sensor_value *val) |
Helper function for converting struct sensor_value to integer micro units. | |
static int | sensor_value_from_milli (struct sensor_value *val, int64_t milli) |
Helper function for converting integer milli units to struct sensor_value. | |
static int | sensor_value_from_micro (struct sensor_value *val, int64_t micro) |
Helper function for converting integer micro units to struct sensor_value. | |
Public APIs for the sensor driver.
#define SENSOR_DECODER_API_DT_DEFINE | ( | ) |
Define a decoder API.
This macro should be created once per compatible string of a sensor and will create a statically referenceable decoder API.
#define SENSOR_DECODER_DT_GET | ( | node_id | ) | &UTIL_CAT(DT_STRING_TOKEN_BY_IDX(node_id, compatible, 0), __decoder_api) |
Statically get the decoder for a given node.
#define SENSOR_DECODER_NAME | ( | ) | UTIL_CAT(DT_DRV_COMPAT, __decoder_api) |
Get the decoder name for the current driver.
This function depends on DT_DRV_COMPAT
being defined.