6#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_
7#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_
269#define SENSOR_CHANNEL_3_AXIS(chan) \
270 ((chan) == SENSOR_CHAN_ACCEL_XYZ || (chan) == SENSOR_CHAN_GYRO_XYZ || \
271 (chan) == SENSOR_CHAN_MAGN_XYZ || (chan) == SENSOR_CHAN_POS_DXYZ)
281#define SENSOR_CHANNEL_IS_ACCEL(chan) \
282 ((chan) == SENSOR_CHAN_ACCEL_XYZ || (chan) == SENSOR_CHAN_ACCEL_X || \
283 (chan) == SENSOR_CHAN_ACCEL_Y || (chan) == SENSOR_CHAN_ACCEL_Z)
293#define SENSOR_CHANNEL_IS_GYRO(chan) \
294 ((chan) == SENSOR_CHAN_GYRO_XYZ || (chan) == SENSOR_CHAN_GYRO_X || \
295 (chan) == SENSOR_CHAN_GYRO_Y || (chan) == SENSOR_CHAN_GYRO_Z)
588 "sensor_chan_spec size should be equal or less than the size of a machine word");
666 uint16_t max_count,
void *data_out);
712#define SENSOR_DECODE_CONTEXT_INIT(decoder_, buffer_, channel_type_, channel_index_) \
714 .decoder = (decoder_), \
715 .buffer = (buffer_), \
716 .channel = {.chan_type = (channel_type_), .chan_idx = (channel_index_)}, \
753#define SENSOR_STREAM_TRIGGER_PREP(_trigger, _opt) \
755 .trigger = (_trigger), .opt = (_opt), \
788#define SENSOR_DT_READ_IODEV(name, dt_node, ...) \
789 static struct sensor_chan_spec _CONCAT(__channel_array_, name)[] = {__VA_ARGS__}; \
790 static struct sensor_read_config _CONCAT(__sensor_read_config_, name) = { \
791 .sensor = DEVICE_DT_GET(dt_node), \
792 .is_streaming = false, \
793 .channels = _CONCAT(__channel_array_, name), \
794 .count = ARRAY_SIZE(_CONCAT(__channel_array_, name)), \
795 .max = ARRAY_SIZE(_CONCAT(__channel_array_, name)), \
797 RTIO_IODEV_DEFINE(name, &__sensor_iodev_api, _CONCAT(&__sensor_read_config_, name))
818#define SENSOR_DT_STREAM_IODEV(name, dt_node, ...) \
819 static struct sensor_stream_trigger _CONCAT(__trigger_array_, name)[] = {__VA_ARGS__}; \
820 static struct sensor_read_config _CONCAT(__sensor_read_config_, name) = { \
821 .sensor = DEVICE_DT_GET(dt_node), \
822 .is_streaming = true, \
823 .triggers = _CONCAT(__trigger_array_, name), \
824 .count = ARRAY_SIZE(_CONCAT(__trigger_array_, name)), \
825 .max = ARRAY_SIZE(_CONCAT(__trigger_array_, name)), \
827 RTIO_IODEV_DEFINE(name, &__sensor_iodev_api, &_CONCAT(__sensor_read_config_, name))
852static inline int z_impl_sensor_attr_set(
const struct device *dev,
863 return api->
attr_set(dev, chan, attr, val);
883static inline int z_impl_sensor_attr_get(
const struct device *dev,
894 return api->
attr_get(dev, chan, attr, val);
952static inline int z_impl_sensor_sample_fetch(
const struct device *dev)
981static inline int z_impl_sensor_sample_fetch_chan(
const struct device *dev,
1012static inline int z_impl_sensor_channel_get(
const struct device *dev,
1019#if defined(CONFIG_SENSOR_ASYNC_API) || defined(__DOXYGEN__)
1056static inline int z_impl_sensor_get_decoder(
const struct device *dev,
1061 __ASSERT_NO_MSG(api != NULL);
1064 *decoder = &__sensor_default_decoder;
1090 const struct device *sensor,
1092 size_t num_channels);
1094static inline int z_impl_sensor_reconfigure_read_iodev(
const struct rtio_iodev *iodev,
1095 const struct device *sensor,
1097 size_t num_channels)
1101 if (cfg->max < num_channels || cfg->is_streaming) {
1107 cfg->count = num_channels;
1125 if (handle != NULL) {
1170 "consumed non-matching completion for sensor read into buffer %p\n", buf);
1241#define SENSOR_G 9806650LL
1246#define SENSOR_PI 3141592LL
1260 if (micro_ms2 > 0) {
1310 return (micro_ms2 * 1000000LL) /
SENSOR_G;
1336 if (micro_rad_s > 0) {
1370 return (micro_rad_s * 180LL * 100000LL) /
SENSOR_PI;
1393 return (
double)val->
val1 + (double)val->
val2 / 1000000;
1404 return (
float)val->
val1 + (float)val->
val2 / 1000000;
1435 uint8_t num_bits = m + n + (is_signed ? 1U : 0U);
1517 uint8_t num_bits = m + n + (is_signed ? 1U : 0U);
1530 inp_int64 *= 1000000LL;
1537#ifdef CONFIG_SENSOR_INFO
1540 const struct device *dev;
1543 const char *friendly_name;
1546#define SENSOR_INFO_INITIALIZER(_dev, _vendor, _model, _friendly_name) \
1549 .vendor = _vendor, \
1551 .friendly_name = _friendly_name, \
1554#define SENSOR_INFO_DEFINE(name, ...) \
1555 static const STRUCT_SECTION_ITERABLE(sensor_info, name) = \
1556 SENSOR_INFO_INITIALIZER(__VA_ARGS__)
1558#define SENSOR_INFO_DT_NAME(node_id) \
1559 _CONCAT(__sensor_info, DEVICE_DT_NAME_GET(node_id))
1561#define SENSOR_INFO_DT_DEFINE(node_id) \
1562 SENSOR_INFO_DEFINE(SENSOR_INFO_DT_NAME(node_id), \
1563 DEVICE_DT_GET(node_id), \
1564 DT_NODE_VENDOR_OR(node_id, NULL), \
1565 DT_NODE_MODEL_OR(node_id, NULL), \
1566 DT_PROP_OR(node_id, friendly_name, NULL)) \
1570#define SENSOR_INFO_DEFINE(name, ...)
1571#define SENSOR_INFO_DT_DEFINE(node_id)
1602#define SENSOR_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
1603 data_ptr, cfg_ptr, level, prio, \
1605 DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
1606 data_ptr, cfg_ptr, level, prio, \
1607 api_ptr, __VA_ARGS__); \
1609 SENSOR_INFO_DT_DEFINE(node_id);
1620#define SENSOR_DEVICE_DT_INST_DEFINE(inst, ...) \
1621 SENSOR_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1721 if (val2 >= 1000000LL || (val1 < 0 && val2 > 0)) {
1724 }
else if (val2 <= -1000000LL || (val1 > 0 && val2 < 0)) {
1753 if (val2 >= 1000000LL || (val1 < 0 && val2 > 0)) {
1756 }
else if (val2 <= -1000000LL || (val1 > 0 && val2 < 0)) {
1786 val1 += val2 / 1000000LL;
1813 val1 += val2 / 1000000LL;
1831#define SENSOR_DECODER_NAME() UTIL_CAT(DT_DRV_COMPAT, __decoder_api)
1840#define SENSOR_DECODER_DT_GET(node_id) \
1841 &UTIL_CAT(DT_STRING_TOKEN_BY_IDX(node_id, compatible, 0), __decoder_api)
1858#define SENSOR_DECODER_API_DT_DEFINE() \
1859 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), (), (static)) \
1860 const STRUCT_SECTION_ITERABLE(sensor_decoder_api, SENSOR_DECODER_NAME())
1866#define Z_MAYBE_SENSOR_DECODER_DECLARE_INTERNAL_IDX(node_id, prop, idx) \
1867 extern const struct sensor_decoder_api UTIL_CAT( \
1868 DT_STRING_TOKEN_BY_IDX(node_id, prop, idx), __decoder_api);
1870#define Z_MAYBE_SENSOR_DECODER_DECLARE_INTERNAL(node_id) \
1871 COND_CODE_1(DT_NODE_HAS_PROP(node_id, compatible), \
1872 (DT_FOREACH_PROP_ELEM(node_id, compatible, \
1873 Z_MAYBE_SENSOR_DECODER_DECLARE_INTERNAL_IDX)), \
1882#include <zephyr/syscalls/sensor.h>
APIs and macros for the Zephyr device model.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1505
#define DT_FOREACH_STATUS_OKAY_NODE(fn)
Invokes fn for every status okay node in the tree.
Definition devicetree.h:3593
int32_t q31_t
32-bit fractional data type in 1.31 format.
Definition types.h:35
#define RTIO_PRIO_NORM
Normal priority.
Definition sqe.h:56
static void rtio_sqe_prep_read_with_pool(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Prepare a read op submission with context's mempool.
Definition sqe.h:577
static rtio_sqe_handle_t rtio_sqe_handle(const struct rtio *r, const struct rtio_sqe *sqe)
Capture an opaque, validatable handle for a live submission.
Definition rtio.h:948
static int rtio_sqe_copy_in(struct rtio *r, const struct rtio_sqe *sqes, size_t sqe_count)
Copy an array of SQEs into the queue.
Definition rtio.h:1142
int rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes, rtio_sqe_handle_t *handles, size_t sqe_count)
Copy an array of SQEs into the queue and get resulting handles back.
uint32_t rtio_sqe_handle_t
Opaque identity for a submission queue entry.
Definition sqe.h:331
static void rtio_sqe_prep_read(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *buf, uint32_t len, void *userdata)
Prepare a read op submission.
Definition sqe.h:560
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition rtio.h:365
static void rtio_sqe_prep_read_multishot(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Prepare a multishot read op submission with context's mempool.
Definition sqe.h:592
static void rtio_cqe_release(struct rtio *r, struct rtio_cqe *cqe)
Release consumed completion queue event.
Definition rtio.h:573
static struct rtio_cqe * rtio_cqe_consume_block(struct rtio *r)
Wait for and consume a single completion queue event.
Definition rtio.h:549
int rtio_submit(struct rtio *r, uint32_t wait_count)
Submit I/O requests to the underlying executor.
int(* sensor_attr_get_t)(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val)
Callback API to get a sensor attribute.
Definition sensor.h:487
int(* sensor_get_decoder_t)(const struct device *dev, const struct sensor_decoder_api **api)
Callback API to get the sensor decoder implementation.
Definition sensor.h:522
int(* sensor_attr_set_t)(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val)
Callback API to set a sensor attribute.
Definition sensor.h:478
int(* sensor_channel_get_t)(const struct device *dev, enum sensor_channel chan, struct sensor_value *val)
Callback API to read a sensor channel from the driver buffer.
Definition sensor.h:511
int(* sensor_sample_fetch_t)(const struct device *dev, enum sensor_channel chan)
Callback API to fetch a sensor sample into the driver buffer.
Definition sensor.h:504
void(* sensor_submit_t)(const struct device *sensor, struct rtio_iodev_sqe *sqe)
Callback API to service an RTIO submission for a sensor device.
Definition sensor.h:533
int(* sensor_trigger_set_t)(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler)
Callback API to set a sensor trigger and handler.
Definition sensor.h:496
#define SENSOR_G
The value of gravitational constant in micro m/s^2.
Definition sensor.h:1241
static int sensor_decode(struct sensor_decode_context *ctx, void *out, uint16_t max_count)
Decode N frames using a sensor_decode_context.
Definition sensor.h:728
static int32_t sensor_rad_to_degrees(const struct sensor_value *rad)
Helper function for converting radians to degrees.
Definition sensor.h:1332
sensor_trigger_type
Sensor trigger types.
Definition sensor.h:300
sensor_attribute
Sensor attribute types.
Definition sensor.h:384
int sensor_get_decoder(const struct device *dev, const struct sensor_decoder_api **decoder)
Get the sensor's decoder API.
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.
Definition sensor.h:1319
static double sensor_value_to_double(const struct sensor_value *val)
Helper function for converting struct sensor_value to double.
Definition sensor.h:1391
static float sensor_value_to_float(const struct sensor_value *val)
Helper function for converting struct sensor_value to float.
Definition sensor.h:1402
int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel, size_t *base_size, size_t *frame_size)
static void sensor_degrees_to_rad(int32_t d, struct sensor_value *rad)
Helper function for converting degrees to radians.
Definition sensor.h:1349
static int32_t sensor_ms2_to_ug(const struct sensor_value *ms2)
Helper function to convert acceleration from m/s^2 to micro Gs.
Definition sensor.h:1306
static int sensor_value_add(const struct sensor_value *inp1, const struct sensor_value *inp2, struct sensor_value *out)
Helper function for adding two struct sensor_value.
Definition sensor.h:1715
static int sensor_stream(const struct rtio_iodev *iodev, struct rtio *ctx, void *userdata, rtio_sqe_handle_t *handle)
Definition sensor.h:1111
static int sensor_value_from_float(struct sensor_value *val, float inp)
Helper function for converting float to struct sensor_value.
Definition sensor.h:1489
static void sensor_g_to_ms2(int32_t g, struct sensor_value *ms2)
Helper function to convert acceleration from Gs to m/s^2.
Definition sensor.h:1273
static int64_t sensor_value_to_milli(const struct sensor_value *val)
Helper function for converting struct sensor_value to integer milli units.
Definition sensor.h:1651
#define SENSOR_PI
The value of constant PI in micros.
Definition sensor.h:1246
static int sensor_value_multiply(const struct sensor_value *inp1, const struct sensor_value *inp2, struct sensor_value *out)
Helper function for multiplying two struct sensor_value.
Definition sensor.h:1779
int sensor_reconfigure_read_iodev(const 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_value_from_fixed_point(struct sensor_value *val, uint32_t inp, uint8_t m, uint8_t n, bool is_signed)
Helper function for converting fixed-point to struct sensor_value.
Definition sensor.h:1514
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.
Definition sensor.h:919
sensor_stream_data_opt
Options for what to do with the associated data when a trigger is consumed.
Definition sensor.h:739
static int sensor_value_from_milli(struct sensor_value *val, int64_t milli)
Helper function for converting integer milli units to struct sensor_value.
Definition sensor.h:1674
void(* sensor_trigger_handler_t)(const struct device *dev, const struct sensor_trigger *trigger)
Callback API upon firing of a trigger.
Definition sensor.h:466
static int64_t sensor_value_to_micro(const struct sensor_value *val)
Helper function for converting struct sensor_value to integer micro units.
Definition sensor.h:1662
int sensor_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val)
Get a reading from a sensor device.
static int32_t sensor_ms2_to_mg(const struct sensor_value *ms2)
Helper function to convert acceleration from m/s^2 to milli Gs.
Definition sensor.h:1287
int sensor_sample_fetch(const struct device *dev)
Fetch a sample from the sensor and store it in an internal driver buffer.
void(* sensor_processing_callback_t)(int result, uint8_t *buf, uint32_t buf_len, void *userdata)
Callback function used with the helper processing function.
Definition sensor.h:1220
sensor_channel
Sensor channels.
Definition sensor.h:66
static int sensor_value_to_fixed_point(uint32_t *val, struct sensor_value *inp, uint8_t m, uint8_t n, bool is_signed)
Helper function for converting struct sensor_value to fixed-point.
Definition sensor.h:1432
static void sensor_10udegrees_to_rad(int32_t d, struct sensor_value *rad)
Helper function for converting 10 micro degrees to radians.
Definition sensor.h:1379
static int32_t sensor_ms2_to_g(const struct sensor_value *ms2)
Helper function to convert acceleration from m/s^2 to Gs.
Definition sensor.h:1256
void sensor_processing_with_callback(struct rtio *ctx, sensor_processing_callback_t cb)
Helper function for common processing of sensor data.
static int64_t sensor_value_to_deci(const struct sensor_value *val)
Helper function for converting struct sensor_value to integer deci units.
Definition sensor.h:1629
static int sensor_value_from_micro(struct sensor_value *val, int64_t micro)
Helper function for converting integer micro units to struct sensor_value.
Definition sensor.h:1694
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.
static int sensor_read(const struct rtio_iodev *iodev, struct rtio *ctx, uint8_t *buf, size_t buf_len)
Blocking one shot read of samples from a sensor into a buffer.
Definition sensor.h:1148
static int32_t sensor_rad_to_10udegrees(const struct sensor_value *rad)
Helper function for converting radians to 10 micro degrees.
Definition sensor.h:1366
static q31_t sensor_value_to_q31(const struct sensor_value *val, int8_t shift)
Helper function for converting struct sensor_value to q31.
Definition sensor.h:1414
static int sensor_value_subtract(const struct sensor_value *inp1, const struct sensor_value *inp2, struct sensor_value *out)
Helper function for subtracting two struct sensor_value.
Definition sensor.h:1747
static int64_t sensor_value_to_centi(const struct sensor_value *val)
Helper function for converting struct sensor_value to integer centi units.
Definition sensor.h:1640
static bool sensor_chan_spec_eq(struct sensor_chan_spec chan_spec0, struct sensor_chan_spec chan_spec1)
Check if channel specs are equivalent.
Definition sensor.h:599
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_value_from_double(struct sensor_value *val, double inp)
Helper function for converting double to struct sensor_value.
Definition sensor.h:1467
static int sensor_read_async_mempool(const struct rtio_iodev *iodev, struct rtio *ctx, void *userdata)
One shot non-blocking read with pool allocated buffer.
Definition sensor.h:1190
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.
static int sensor_value_scale(const struct sensor_value *inp, int32_t scalar, struct sensor_value *out)
Helper function for scaling a struct sensor_value.
Definition sensor.h:1807
@ SENSOR_TRIG_OVERFLOW
Trigger fires when data overflows.
Definition sensor.h:352
@ SENSOR_TRIG_DELTA
Trigger fires when the selected channel varies significantly.
Definition sensor.h:316
@ SENSOR_TRIG_NEAR_FAR
Trigger fires when a near/far event is detected.
Definition sensor.h:318
@ SENSOR_TRIG_FREEFALL
Trigger fires when a free fall is detected.
Definition sensor.h:334
@ SENSOR_TRIG_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:363
@ SENSOR_TRIG_FIFO_FULL
Trigger fires when the FIFO becomes full.
Definition sensor.h:346
@ SENSOR_TRIG_MOTION
Trigger fires when motion is detected.
Definition sensor.h:337
@ SENSOR_TRIG_STATIONARY
Trigger fires when no motion has been detected for a while.
Definition sensor.h:340
@ SENSOR_TRIG_COMMON_COUNT
Number of all common sensor triggers.
Definition sensor.h:357
@ SENSOR_TRIG_THRESHOLD
Trigger fires when channel reading transitions configured thresholds.
Definition sensor.h:325
@ SENSOR_TRIG_MAX
Maximum value describing a sensor trigger type.
Definition sensor.h:368
@ SENSOR_TRIG_DOUBLE_TAP
Trigger fires when a double tap is detected.
Definition sensor.h:331
@ SENSOR_TRIG_TILT
Trigger fires when a tilt is detected.
Definition sensor.h:349
@ SENSOR_TRIG_TIMER
Timer-based trigger, useful when the sensor does not have an interrupt line.
Definition sensor.h:305
@ SENSOR_TRIG_FIFO_WATERMARK
Trigger fires when the FIFO watermark has been reached.
Definition sensor.h:343
@ SENSOR_TRIG_TAP
Trigger fires when a single tap is detected.
Definition sensor.h:328
@ SENSOR_TRIG_DATA_READY
Trigger fires whenever new data is ready.
Definition sensor.h:307
@ SENSOR_ATTR_HYSTERESIS
Definition sensor.h:402
@ SENSOR_ATTR_FEATURE_MASK
Enable/disable sensor features.
Definition sensor.h:422
@ SENSOR_ATTR_CALIB_TARGET
Calibration target.
Definition sensor.h:416
@ SENSOR_ATTR_OFFSET
The sensor value returned will be altered by the amount indicated by offset: final_value = sensor_val...
Definition sensor.h:411
@ SENSOR_ATTR_BATCH_DURATION
Hardware batch duration in ticks.
Definition sensor.h:433
@ SENSOR_ATTR_OVERSAMPLING
Oversampling factor.
Definition sensor.h:404
@ SENSOR_ATTR_FIFO_WATERMARK
FIFO watermark threshold, expressed in driver-specific FIFO units.
Definition sensor.h:446
@ SENSOR_ATTR_FF_DUR
Free-fall duration represented in milliseconds.
Definition sensor.h:430
@ SENSOR_ATTR_UPPER_THRESH
Upper threshold for trigger.
Definition sensor.h:393
@ SENSOR_ATTR_CONFIGURATION
Configure the operating modes of a sensor.
Definition sensor.h:418
@ SENSOR_ATTR_RESOLUTION
Configure the resolution of a sensor.
Definition sensor.h:437
@ SENSOR_ATTR_CALIBRATION
Set a calibration value needed by a sensor.
Definition sensor.h:420
@ SENSOR_ATTR_CHIP_ID
Chip ID of a sensor.
Definition sensor.h:439
@ SENSOR_ATTR_COMMON_COUNT
Number of all common sensor attributes.
Definition sensor.h:443
@ SENSOR_ATTR_ALERT
Alert threshold or alert enable/disable.
Definition sensor.h:424
@ SENSOR_ATTR_SLOPE_TH
Threshold for any-motion (slope) trigger.
Definition sensor.h:395
@ SENSOR_ATTR_GAIN
Configure the gain of a sensor.
Definition sensor.h:435
@ SENSOR_ATTR_SAMPLING_FREQUENCY
Sensor sampling frequency, i.e.
Definition sensor.h:389
@ SENSOR_ATTR_FULL_SCALE
Sensor range, in SI units.
Definition sensor.h:406
@ SENSOR_ATTR_LOWER_THRESH
Lower threshold for trigger.
Definition sensor.h:391
@ SENSOR_ATTR_SLOPE_DUR
Duration for which the slope values needs to be outside the threshold for the trigger to fire.
Definition sensor.h:400
@ SENSOR_ATTR_MAX
Maximum value describing a sensor attribute type.
Definition sensor.h:457
@ SENSOR_ATTR_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:452
@ SENSOR_STREAM_DATA_INCLUDE
Include whatever data is associated with the trigger.
Definition sensor.h:741
@ SENSOR_STREAM_DATA_NOP
Do nothing with the associated trigger data, it may be consumed later.
Definition sensor.h:743
@ SENSOR_STREAM_DATA_DROP
Flush/clear whatever data is associated with the trigger.
Definition sensor.h:745
@ SENSOR_CHAN_GAUGE_STATE_OF_HEALTH
State of health measurement in %.
Definition sensor.h:215
@ SENSOR_CHAN_PM_1_0_CF
PM1.0 concentration (standard particle, CF=1), in µg/m³
Definition sensor.h:120
@ SENSOR_CHAN_PM_1_0
1.0 micro-meters Particulate Matter, in ug/m^3
Definition sensor.h:126
@ SENSOR_CHAN_DIE_TEMP
Device die temperature in degrees Celsius.
Definition sensor.h:92
@ SENSOR_CHAN_PRESS
Pressure in kilopascal.
Definition sensor.h:96
@ SENSOR_CHAN_GAUGE_TIME_TO_FULL
Time to full in minutes.
Definition sensor.h:219
@ SENSOR_CHAN_ACCEL_XYZ
Acceleration on the X, Y and Z axes.
Definition sensor.h:74
@ SENSOR_CHAN_MAGN_X
Magnetic field on the X axis, in G.
Definition sensor.h:84
@ SENSOR_CHAN_O2
O2 level, in parts per million (ppm).
Definition sensor.h:150
@ SENSOR_CHAN_CURRENT
Current, in amps.
Definition sensor.h:167
@ SENSOR_CHAN_GYRO_XYZ
Angular velocity around the X, Y and Z axes.
Definition sensor.h:82
@ SENSOR_CHAN_VSHUNT
Current Shunt Voltage in milli-volts.
Definition sensor.h:164
@ SENSOR_CHAN_GREEN
Illuminance in green spectrum, in lux.
Definition sensor.h:113
@ SENSOR_CHAN_GRAVITY_VECTOR
Gravity Vector (X/Y/Z components in m/s^2).
Definition sensor.h:231
@ SENSOR_CHAN_MAGN_Z
Magnetic field on the Z axis, in G.
Definition sensor.h:88
@ SENSOR_CHAN_MAGN_Y
Magnetic field on the Y axis, in G.
Definition sensor.h:86
@ SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE
Desired voltage of cell in V (nominal voltage).
Definition sensor.h:225
@ SENSOR_CHAN_POWER
Power in watts.
Definition sensor.h:169
@ SENSOR_CHAN_PM_2_5
2.5 micro-meters Particulate Matter, in ug/m^3
Definition sensor.h:128
@ SENSOR_CHAN_RESISTANCE
Resistance , in Ohm.
Definition sensor.h:172
@ SENSOR_CHAN_GAME_ROTATION_VECTOR
Game Rotation Vector (unit quaternion components X/Y/Z/W).
Definition sensor.h:229
@ SENSOR_CHAN_AMBIENT_LIGHT
Ambient illuminance in visible spectrum, in lux.
Definition sensor.h:105
@ SENSOR_CHAN_PM_0_5_COUNT
Number of particles ≥ 0.5 µm per 0.1 liter of air.
Definition sensor.h:134
@ SENSOR_CHAN_GAUGE_AVG_CURRENT
Average current, in amps (negative=discharging).
Definition sensor.h:195
@ SENSOR_CHAN_ENCODER_COUNT
Raw quadrature decoder count, in counts.
Definition sensor.h:236
@ SENSOR_CHAN_GYRO_Y
Angular velocity around the Y axis, in rad/s.
Definition sensor.h:78
@ SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT
Desired charging current in mA.
Definition sensor.h:227
@ SENSOR_CHAN_FREQUENCY
Frequency, in Hz.
Definition sensor.h:190
@ SENSOR_CHAN_PM_2_5_CF
PM2.5 concentration (standard particle, CF=1), in µg/m³
Definition sensor.h:122
@ SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY
Full Charge Capacity in mAh.
Definition sensor.h:205
@ SENSOR_CHAN_ROTATION
Angular rotation, in degrees.
Definition sensor.h:175
@ SENSOR_CHAN_AMBIENT_TEMP
Ambient temperature in degrees Celsius.
Definition sensor.h:94
@ SENSOR_CHAN_MAGN_XYZ
Magnetic field on the X, Y and Z axes.
Definition sensor.h:90
@ SENSOR_CHAN_GAUGE_STDBY_CURRENT
Standby current, in amps (negative=discharging).
Definition sensor.h:197
@ SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT
Max load current, in amps (negative=discharging).
Definition sensor.h:199
@ SENSOR_CHAN_ACCEL_Y
Acceleration on the Y axis, in m/s^2.
Definition sensor.h:70
@ SENSOR_CHAN_RPM
Revolutions per minute, in RPM.
Definition sensor.h:187
@ SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY
Full Available Capacity in mAh.
Definition sensor.h:211
@ SENSOR_CHAN_VOLTAGE
Voltage, in volts.
Definition sensor.h:161
@ SENSOR_CHAN_FLOW_RATE
Flow rate in liters per minute.
Definition sensor.h:156
@ SENSOR_CHAN_VOLUME
Flow volume in liters.
Definition sensor.h:158
@ SENSOR_CHAN_BLUE
Illuminance in blue spectrum, in lux.
Definition sensor.h:115
@ SENSOR_CHAN_LIGHT
Illuminance in visible spectrum, in lux.
Definition sensor.h:107
@ SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE
Design voltage of cell in V (max voltage).
Definition sensor.h:223
@ SENSOR_CHAN_PM_5_COUNT
Number of particles ≥ 5.0 µm per 0.1 liter of air.
Definition sensor.h:140
@ SENSOR_CHAN_ACCEL_Z
Acceleration on the Z axis, in m/s^2.
Definition sensor.h:72
@ SENSOR_CHAN_CO2
CO2 level, in parts per million (ppm).
Definition sensor.h:148
@ SENSOR_CHAN_GAUGE_STATE_OF_CHARGE
State of charge measurement in %.
Definition sensor.h:203
@ SENSOR_CHAN_POS_DXYZ
Position change on the X, Y and Z axis, in points.
Definition sensor.h:184
@ SENSOR_CHAN_GBIAS_XYZ
Gyroscope bias (X/Y/Z components in rad/s).
Definition sensor.h:233
@ SENSOR_CHAN_GAUGE_CYCLE_COUNT
Cycle count (total number of charge/discharge cycles).
Definition sensor.h:221
@ SENSOR_CHAN_GAUGE_TEMP
Gauge temperature.
Definition sensor.h:201
@ SENSOR_CHAN_POS_DY
Position change on the Y axis, in points.
Definition sensor.h:180
@ SENSOR_CHAN_GYRO_Z
Angular velocity around the Z axis, in rad/s.
Definition sensor.h:80
@ SENSOR_CHAN_PM_10_CF
PM10 concentration (standard particle, CF=1), in µg/m³
Definition sensor.h:124
@ SENSOR_CHAN_POS_DX
Position change on the X axis, in points.
Definition sensor.h:178
@ SENSOR_CHAN_GAUGE_AVG_POWER
Average power in mW.
Definition sensor.h:213
@ SENSOR_CHAN_GAUGE_TIME_TO_EMPTY
Time to empty in minutes.
Definition sensor.h:217
@ SENSOR_CHAN_PM_10
10 micro-meters Particulate Matter, in ug/m^3
Definition sensor.h:130
@ SENSOR_CHAN_ENCODER_REVOLUTIONS
Number of revolutions for quadrature decoder.
Definition sensor.h:239
@ SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY
Remaining Charge Capacity in mAh.
Definition sensor.h:207
@ SENSOR_CHAN_PM_1_0_COUNT
Number of particles ≥ 1.0 µm per 0.1 liter of air.
Definition sensor.h:136
@ SENSOR_CHAN_PM_0_3_COUNT
Number of particles ≥ 0.3 µm per 0.1 liter of air.
Definition sensor.h:132
@ SENSOR_CHAN_PM_10_COUNT
Number of particles ≥ 10.0 µm per 0.1 liter of air.
Definition sensor.h:142
@ SENSOR_CHAN_ALL
All channels.
Definition sensor.h:242
@ SENSOR_CHAN_GAUGE_VOLTAGE
Voltage, in volts.
Definition sensor.h:193
@ SENSOR_CHAN_PROX
Proximity.
Definition sensor.h:101
@ SENSOR_CHAN_COMMON_COUNT
Number of all common sensor channels.
Definition sensor.h:247
@ SENSOR_CHAN_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:253
@ SENSOR_CHAN_GYRO_X
Angular velocity around the X axis, in rad/s.
Definition sensor.h:76
@ SENSOR_CHAN_GAS_RES
Gas sensor resistance in ohms.
Definition sensor.h:154
@ SENSOR_CHAN_HUMIDITY
Humidity, in percent.
Definition sensor.h:103
@ SENSOR_CHAN_DISTANCE
Distance.
Definition sensor.h:145
@ SENSOR_CHAN_IR
Illuminance in infra-red spectrum, in lux.
Definition sensor.h:109
@ SENSOR_CHAN_MAX
Maximum value describing a sensor channel type.
Definition sensor.h:258
@ SENSOR_CHAN_PM_2_5_COUNT
Number of particles ≥ 2.5 µm per 0.1 liter of air.
Definition sensor.h:138
@ SENSOR_CHAN_POS_DZ
Position change on the Z axis, in points.
Definition sensor.h:182
@ SENSOR_CHAN_RED
Illuminance in red spectrum, in lux.
Definition sensor.h:111
@ SENSOR_CHAN_ALTITUDE
Altitude, in meters.
Definition sensor.h:117
@ SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY
Nominal Available Capacity in mAh.
Definition sensor.h:209
@ SENSOR_CHAN_ACCEL_X
Acceleration on the X axis, in m/s^2.
Definition sensor.h:68
@ SENSOR_CHAN_VOC
VOC level, in parts per billion (ppb).
Definition sensor.h:152
static int64_t sign_extend_64(uint64_t value, uint8_t index)
Sign extend a 64 bit value using the index bit as sign bit.
Definition util.h:768
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:166
#define BIT64_MASK(n)
64-bit bit mask with bits 0 through n-1 (inclusive) set, or 0 if n is 0.
Definition util_macro.h:80
static int64_t arithmetic_shift_right(int64_t value, uint8_t shift)
Arithmetic shift right.
Definition util.h:605
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define BIT_MASK(n)
Bit mask with bits 0 through n-1 (inclusive) set, or 0 if n is 0.
Definition util_macro.h:74
#define CLAMP(val, low, high)
Clamp a value to a given range.
Definition util.h:531
#define IN_RANGE(val, min, max)
Checks if a value is within range.
Definition util.h:546
#define EINVAL
Invalid argument.
Definition errno.h:61
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define ENOMEM
Not enough core.
Definition errno.h:51
#define ERANGE
Result too large.
Definition errno.h:73
Real-Time IO device API for moving bytes with low effort.
Decoded data types for the sensor API.
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
#define INT32_MAX
Definition stdint.h:18
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
#define INT32_MIN
Definition stdint.h:24
#define INT16_MAX
Definition stdint.h:17
__INT64_TYPE__ int64_t
Definition stdint.h:75
__INT8_TYPE__ int8_t
Definition stdint.h:72
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
A completion queue event.
Definition cqe.h:90
void * userdata
Associated userdata with operation.
Definition cqe.h:96
int32_t result
Result from operation.
Definition cqe.h:95
API that an RTIO IO device should implement.
Definition iodev.h:38
IO device submission queue entry.
Definition sqe.h:468
struct rtio_sqe sqe
The submission queue entry this wraps.
Definition sqe.h:470
An IO device with a function table for submitting requests.
Definition iodev.h:83
void * data
Data associated with this iodev.
Definition iodev.h:88
A submission queue event.
Definition sqe.h:346
void * userdata
User provided data which is returned upon operation completion.
Definition sqe.h:364
uint32_t buf_len
Length of buffer.
Definition sqe.h:371
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:355
const uint8_t * buf
Buffer to write from.
Definition sqe.h:372
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:85
Sensor Channel Specification.
Definition sensor.h:580
uint16_t chan_idx
A sensor channel index.
Definition sensor.h:582
uint16_t chan_type
A sensor channel type.
Definition sensor.h:581
Used for iterating over the data frames via the sensor_decoder_api.
Definition sensor.h:702
const struct sensor_decoder_api * decoder
Definition sensor.h:703
struct sensor_chan_spec channel
Definition sensor.h:705
const uint8_t * buffer
Definition sensor.h:704
uint32_t fit
Definition sensor.h:706
Decodes a single raw data buffer.
Definition sensor.h:612
int(* get_size_info)(struct sensor_chan_spec channel, size_t *base_size, size_t *frame_size)
Get the size required to decode a given channel.
Definition sensor.h:638
int(* get_frame_count)(const uint8_t *buffer, struct sensor_chan_spec chan_spec, uint16_t *frame_count)
Get the frame_count for a specified chan_spec from the buffer.
Definition sensor.h:623
int(* decode)(const uint8_t *buffer, struct sensor_chan_spec chan_spec, uint32_t *fit, uint16_t max_count, void *data_out)
Decode up to max_count frames specified by chan_spec from the buffer.
Definition sensor.h:665
bool(* has_trigger)(const uint8_t *buffer, enum sensor_trigger_type trigger)
Check if the given trigger type is present.
Definition sensor.h:675
<span class="mlabel">Driver Operations</span> Sensor driver operations
Definition sensor.h:538
sensor_get_decoder_t get_decoder
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sensor.h:562
sensor_attr_set_t attr_set
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sensor.h:542
sensor_attr_get_t attr_get
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sensor.h:546
sensor_trigger_set_t trigger_set
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sensor.h:550
sensor_sample_fetch_t sample_fetch
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition sensor.h:554
sensor_channel_get_t channel_get
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition sensor.h:558
sensor_submit_t submit
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sensor.h:566
struct sensor_chan_spec *const channels
Definition sensor.h:766
size_t count
Definition sensor.h:769
struct sensor_stream_trigger *const triggers
Definition sensor.h:767
const bool is_streaming
Definition sensor.h:764
const struct device * sensor
Definition sensor.h:763
const size_t max
Definition sensor.h:770
enum sensor_stream_data_opt opt
Definition sensor.h:750
enum sensor_trigger_type trigger
Definition sensor.h:749
Sensor trigger spec.
Definition sensor.h:374
enum sensor_trigger_type type
Trigger type.
Definition sensor.h:376
enum sensor_channel chan
Channel the trigger is set on.
Definition sensor.h:378
Representation of a sensor readout value.
Definition sensor.h:56
int32_t val2
Fractional part of the value (in one-millionth parts).
Definition sensor.h:60
int32_t val1
Integer part of the value.
Definition sensor.h:58
Iterable sections helpers.