Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sensor.h
Go to the documentation of this file.
1/*
2* Copyright (c) 2016 Intel Corporation
3*
4* SPDX-License-Identifier: Apache-2.0
5*/
6#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_
7#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_
8
14
27
28#include <errno.h>
29#include <stdlib.h>
30
31#include <zephyr/device.h>
33#include <zephyr/dsp/types.h>
34#include <zephyr/rtio/rtio.h>
36#include <zephyr/types.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
61
117
126
137
140
143
148
151
154
163
166
169
212
215
218
223
229
234};
235
309
319
393
401typedef void (*sensor_trigger_handler_t)(const struct device *dev,
402 const struct sensor_trigger *trigger);
403
410typedef int (*sensor_attr_set_t)(const struct device *dev,
411 enum sensor_channel chan,
412 enum sensor_attribute attr,
413 const struct sensor_value *val);
414
421typedef int (*sensor_attr_get_t)(const struct device *dev,
422 enum sensor_channel chan,
423 enum sensor_attribute attr,
424 struct sensor_value *val);
425
432typedef int (*sensor_trigger_set_t)(const struct device *dev,
433 const struct sensor_trigger *trig,
441typedef int (*sensor_sample_fetch_t)(const struct device *dev,
442 enum sensor_channel chan);
449typedef int (*sensor_channel_get_t)(const struct device *dev,
450 enum sensor_channel chan,
451 struct sensor_value *val);
452
465
467/* Ensure sensor_chan_spec is sensibly sized to pass by value */
468BUILD_ASSERT(sizeof(struct sensor_chan_spec) <= sizeof(uintptr_t),
469 "sensor_chan_spec size should be equal or less than the size of a machine word");
471
480static inline bool sensor_chan_spec_eq(struct sensor_chan_spec chan_spec0,
481 struct sensor_chan_spec chan_spec1)
482{
483 return chan_spec0.chan_type == chan_spec1.chan_type &&
484 chan_spec0.chan_idx == chan_spec1.chan_idx;
485}
486
504 int (*get_frame_count)(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
505 uint16_t *frame_count);
506
519 int (*get_size_info)(struct sensor_chan_spec channel, size_t *base_size,
520 size_t *frame_size);
521
546 int (*decode)(const uint8_t *buffer, struct sensor_chan_spec chan_spec, uint32_t *fit,
547 uint16_t max_count, void *data_out);
548
556 bool (*has_trigger)(const uint8_t *buffer, enum sensor_trigger_type trigger);
557};
558
589
593#define SENSOR_DECODE_CONTEXT_INIT(decoder_, buffer_, channel_type_, channel_index_) \
594 { \
595 .decoder = (decoder_), \
596 .buffer = (buffer_), \
597 .channel = {.chan_type = (channel_type_), .chan_idx = (channel_index_)}, \
598 .fit = 0, \
599 }
600
609static inline int sensor_decode(struct sensor_decode_context *ctx, void *out, uint16_t max_count)
610{
611 return ctx->decoder->decode(ctx->buffer, ctx->channel, &ctx->fit, max_count, out);
612}
613
615 size_t *frame_size);
616
623typedef int (*sensor_get_decoder_t)(const struct device *dev,
624 const struct sensor_decoder_api **api);
625
637
642
643#define SENSOR_STREAM_TRIGGER_PREP(_trigger, _opt) \
644 { \
645 .trigger = (_trigger), .opt = (_opt), \
646 }
647
648/*
649 * Internal data structure used to store information about the IODevice for async reading and
650 * streaming sensor data.
651 */
653 const struct device *sensor;
654 const bool is_streaming;
655 union {
658 };
659 size_t count;
660 const size_t max;
661};
662
678#define SENSOR_DT_READ_IODEV(name, dt_node, ...) \
679 static struct sensor_chan_spec _CONCAT(__channel_array_, name)[] = {__VA_ARGS__}; \
680 static struct sensor_read_config _CONCAT(__sensor_read_config_, name) = { \
681 .sensor = DEVICE_DT_GET(dt_node), \
682 .is_streaming = false, \
683 .channels = _CONCAT(__channel_array_, name), \
684 .count = ARRAY_SIZE(_CONCAT(__channel_array_, name)), \
685 .max = ARRAY_SIZE(_CONCAT(__channel_array_, name)), \
686 }; \
687 RTIO_IODEV_DEFINE(name, &__sensor_iodev_api, _CONCAT(&__sensor_read_config_, name))
688
708#define SENSOR_DT_STREAM_IODEV(name, dt_node, ...) \
709 static struct sensor_stream_trigger _CONCAT(__trigger_array_, name)[] = {__VA_ARGS__}; \
710 static struct sensor_read_config _CONCAT(__sensor_read_config_, name) = { \
711 .sensor = DEVICE_DT_GET(dt_node), \
712 .is_streaming = true, \
713 .triggers = _CONCAT(__trigger_array_, name), \
714 .count = ARRAY_SIZE(_CONCAT(__trigger_array_, name)), \
715 .max = ARRAY_SIZE(_CONCAT(__trigger_array_, name)), \
716 }; \
717 RTIO_IODEV_DEFINE(name, &__sensor_iodev_api, &_CONCAT(__sensor_read_config_, name))
718
719/* Used to submit an RTIO sqe to the sensor's iodev */
720typedef void (*sensor_submit_t)(const struct device *sensor, struct rtio_iodev_sqe *sqe);
721
722/* The default decoder API */
723extern const struct sensor_decoder_api __sensor_default_decoder;
724
725/* The default sensor iodev API */
726extern const struct rtio_iodev_api __sensor_iodev_api;
727
737
750__syscall int sensor_attr_set(const struct device *dev,
751 enum sensor_channel chan,
752 enum sensor_attribute attr,
753 const struct sensor_value *val);
754
755static inline int z_impl_sensor_attr_set(const struct device *dev,
756 enum sensor_channel chan,
757 enum sensor_attribute attr,
758 const struct sensor_value *val)
759{
760 const struct sensor_driver_api *api =
761 (const struct sensor_driver_api *)dev->api;
762
763 if (api->attr_set == NULL) {
764 return -ENOSYS;
765 }
766
767 return api->attr_set(dev, chan, attr, val);
768}
769
782__syscall int sensor_attr_get(const struct device *dev,
783 enum sensor_channel chan,
784 enum sensor_attribute attr,
785 struct sensor_value *val);
786
787static inline int z_impl_sensor_attr_get(const struct device *dev,
788 enum sensor_channel chan,
789 enum sensor_attribute attr,
790 struct sensor_value *val)
791{
792 const struct sensor_driver_api *api =
793 (const struct sensor_driver_api *)dev->api;
794
795 if (api->attr_get == NULL) {
796 return -ENOSYS;
797 }
798
799 return api->attr_get(dev, chan, attr, val);
800}
801
824static inline int sensor_trigger_set(const struct device *dev,
825 const struct sensor_trigger *trig,
827{
828 const struct sensor_driver_api *api =
829 (const struct sensor_driver_api *)dev->api;
830
831 if (api->trigger_set == NULL) {
832 return -ENOSYS;
833 }
834
835 return api->trigger_set(dev, trig, handler);
836}
837
856__syscall int sensor_sample_fetch(const struct device *dev);
857
858static inline int z_impl_sensor_sample_fetch(const struct device *dev)
859{
860 const struct sensor_driver_api *api =
861 (const struct sensor_driver_api *)dev->api;
862
863 return api->sample_fetch(dev, SENSOR_CHAN_ALL);
864}
865
887__syscall int sensor_sample_fetch_chan(const struct device *dev,
888 enum sensor_channel type);
889
890static inline int z_impl_sensor_sample_fetch_chan(const struct device *dev,
891 enum sensor_channel type)
892{
893 const struct sensor_driver_api *api =
894 (const struct sensor_driver_api *)dev->api;
895
896 return api->sample_fetch(dev, type);
897}
898
920__syscall int sensor_channel_get(const struct device *dev,
921 enum sensor_channel chan,
922 struct sensor_value *val);
923
924static inline int z_impl_sensor_channel_get(const struct device *dev,
925 enum sensor_channel chan,
926 struct sensor_value *val)
927{
928 const struct sensor_driver_api *api =
929 (const struct sensor_driver_api *)dev->api;
930
931 return api->channel_get(dev, chan, val);
932}
933
934#if defined(CONFIG_SENSOR_ASYNC_API) || defined(__DOXYGEN__)
935
936/*
937 * Generic data structure used for encoding the sample timestamp and number of channels sampled.
938 */
939struct __attribute__((__packed__)) sensor_data_generic_header {
942
943 /*
944 ** The number of channels present in the frame.
945 * This will be the true number of elements in channel_info and in the q31 values that
946 * follow the header.
947 */
949
952
953 /* This padding is needed to make sure that the 'channels' field is aligned */
954 int8_t _padding[sizeof(struct sensor_chan_spec) - 1];
955
958};
959
968#define SENSOR_CHANNEL_3_AXIS(chan) \
969 ((chan) == SENSOR_CHAN_ACCEL_XYZ || (chan) == SENSOR_CHAN_GYRO_XYZ || \
970 (chan) == SENSOR_CHAN_MAGN_XYZ || (chan) == SENSOR_CHAN_POS_DXYZ)
971
980#define SENSOR_CHANNEL_IS_ACCEL(chan) \
981 ((chan) == SENSOR_CHAN_ACCEL_XYZ || (chan) == SENSOR_CHAN_ACCEL_X || \
982 (chan) == SENSOR_CHAN_ACCEL_Y || (chan) == SENSOR_CHAN_ACCEL_Z)
983
992#define SENSOR_CHANNEL_IS_GYRO(chan) \
993 ((chan) == SENSOR_CHAN_GYRO_XYZ || (chan) == SENSOR_CHAN_GYRO_X || \
994 (chan) == SENSOR_CHAN_GYRO_Y || (chan) == SENSOR_CHAN_GYRO_Z)
995
1004__syscall int sensor_get_decoder(const struct device *dev,
1005 const struct sensor_decoder_api **decoder);
1006
1007static inline int z_impl_sensor_get_decoder(const struct device *dev,
1008 const struct sensor_decoder_api **decoder)
1009{
1010 const struct sensor_driver_api *api = (const struct sensor_driver_api *)dev->api;
1011
1012 __ASSERT_NO_MSG(api != NULL);
1013
1014 if (api->get_decoder == NULL) {
1015 *decoder = &__sensor_default_decoder;
1016 return 0;
1017 }
1018
1019 return api->get_decoder(dev, decoder);
1020}
1021
1040__syscall int sensor_reconfigure_read_iodev(const struct rtio_iodev *iodev,
1041 const struct device *sensor,
1042 const struct sensor_chan_spec *channels,
1043 size_t num_channels);
1044
1045static inline int z_impl_sensor_reconfigure_read_iodev(const struct rtio_iodev *iodev,
1046 const struct device *sensor,
1047 const struct sensor_chan_spec *channels,
1048 size_t num_channels)
1049{
1050 struct sensor_read_config *cfg = (struct sensor_read_config *)iodev->data;
1051
1052 if (cfg->max < num_channels || cfg->is_streaming) {
1053 return -ENOMEM;
1054 }
1055
1056 cfg->sensor = sensor;
1057 memcpy(cfg->channels, channels, num_channels * sizeof(struct sensor_chan_spec));
1058 cfg->count = num_channels;
1059 return 0;
1060}
1061
1062static inline int sensor_stream(const struct rtio_iodev *iodev, struct rtio *ctx, void *userdata,
1063 struct rtio_sqe **handle)
1064{
1065 if (IS_ENABLED(CONFIG_USERSPACE)) {
1066 struct rtio_sqe sqe;
1067
1069 rtio_sqe_copy_in_get_handles(ctx, &sqe, handle, 1);
1070 } else {
1071 struct rtio_sqe *sqe = rtio_sqe_acquire(ctx);
1072
1073 if (sqe == NULL) {
1074 return -ENOMEM;
1075 }
1076 if (handle != NULL) {
1077 *handle = sqe;
1078 }
1080 }
1081 rtio_submit(ctx, 0);
1082 return 0;
1083}
1084
1099static inline int sensor_read(const struct rtio_iodev *iodev, struct rtio *ctx, uint8_t *buf,
1100 size_t buf_len)
1101{
1102 if (IS_ENABLED(CONFIG_USERSPACE)) {
1103 struct rtio_sqe sqe;
1104
1106 rtio_sqe_copy_in(ctx, &sqe, 1);
1107 } else {
1108 struct rtio_sqe *sqe = rtio_sqe_acquire(ctx);
1109
1110 if (sqe == NULL) {
1111 return -ENOMEM;
1112 }
1114 }
1115 rtio_submit(ctx, 0);
1116
1117 struct rtio_cqe *cqe = rtio_cqe_consume_block(ctx);
1118 int res = cqe->result;
1119
1120 __ASSERT(cqe->userdata == buf,
1121 "consumed non-matching completion for sensor read into buffer %p\n", buf);
1122
1123 rtio_cqe_release(ctx, cqe);
1124
1125 return res;
1126}
1127
1141static inline int sensor_read_async_mempool(const struct rtio_iodev *iodev, struct rtio *ctx,
1142 void *userdata)
1143{
1144 if (IS_ENABLED(CONFIG_USERSPACE)) {
1145 struct rtio_sqe sqe;
1146
1148 rtio_sqe_copy_in(ctx, &sqe, 1);
1149 } else {
1150 struct rtio_sqe *sqe = rtio_sqe_acquire(ctx);
1151
1152 if (sqe == NULL) {
1153 return -ENOMEM;
1154 }
1156 }
1157 rtio_submit(ctx, 0);
1158 return 0;
1159}
1160
1173 void *userdata);
1174
1187
1188#endif /* defined(CONFIG_SENSOR_ASYNC_API) || defined(__DOXYGEN__) */
1189
1193#define SENSOR_G 9806650LL
1194
1198#define SENSOR_PI 3141592LL
1199
1208static inline int32_t sensor_ms2_to_g(const struct sensor_value *ms2)
1209{
1210 int64_t micro_ms2 = ms2->val1 * 1000000LL + ms2->val2;
1211
1212 if (micro_ms2 > 0) {
1213 return (micro_ms2 + SENSOR_G / 2) / SENSOR_G;
1214 } else {
1215 return (micro_ms2 - SENSOR_G / 2) / SENSOR_G;
1216 }
1217}
1218
1225static inline void sensor_g_to_ms2(int32_t g, struct sensor_value *ms2)
1226{
1227 ms2->val1 = ((int64_t)g * SENSOR_G) / 1000000LL;
1228 ms2->val2 = ((int64_t)g * SENSOR_G) % 1000000LL;
1229}
1230
1239static inline int32_t sensor_ms2_to_mg(const struct sensor_value *ms2)
1240{
1241 int64_t nano_ms2 = (ms2->val1 * 1000000LL + ms2->val2) * 1000LL;
1242
1243 if (nano_ms2 > 0) {
1244 return (nano_ms2 + SENSOR_G / 2) / SENSOR_G;
1245 } else {
1246 return (nano_ms2 - SENSOR_G / 2) / SENSOR_G;
1247 }
1248}
1249
1258static inline int32_t sensor_ms2_to_ug(const struct sensor_value *ms2)
1259{
1260 int64_t micro_ms2 = (ms2->val1 * INT64_C(1000000)) + ms2->val2;
1261
1262 return (micro_ms2 * 1000000LL) / SENSOR_G;
1263}
1264
1271static inline void sensor_ug_to_ms2(int32_t ug, struct sensor_value *ms2)
1272{
1273 ms2->val1 = ((int64_t)ug * SENSOR_G / 1000000LL) / 1000000LL;
1274 ms2->val2 = ((int64_t)ug * SENSOR_G / 1000000LL) % 1000000LL;
1275}
1276
1284static inline int32_t sensor_rad_to_degrees(const struct sensor_value *rad)
1285{
1286 int64_t micro_rad_s = rad->val1 * 1000000LL + rad->val2;
1287
1288 if (micro_rad_s > 0) {
1289 return (micro_rad_s * 180LL + SENSOR_PI / 2) / SENSOR_PI;
1290 } else {
1291 return (micro_rad_s * 180LL - SENSOR_PI / 2) / SENSOR_PI;
1292 }
1293}
1294
1301static inline void sensor_degrees_to_rad(int32_t d, struct sensor_value *rad)
1302{
1303 rad->val1 = ((int64_t)d * SENSOR_PI / 180LL) / 1000000LL;
1304 rad->val2 = ((int64_t)d * SENSOR_PI / 180LL) % 1000000LL;
1305}
1306
1318static inline int32_t sensor_rad_to_10udegrees(const struct sensor_value *rad)
1319{
1320 int64_t micro_rad_s = rad->val1 * 1000000LL + rad->val2;
1321
1322 return (micro_rad_s * 180LL * 100000LL) / SENSOR_PI;
1323}
1324
1331static inline void sensor_10udegrees_to_rad(int32_t d, struct sensor_value *rad)
1332{
1333 rad->val1 = ((int64_t)d * SENSOR_PI / 180LL / 100000LL) / 1000000LL;
1334 rad->val2 = ((int64_t)d * SENSOR_PI / 180LL / 100000LL) % 1000000LL;
1335}
1336
1343static inline double sensor_value_to_double(const struct sensor_value *val)
1344{
1345 return (double)val->val1 + (double)val->val2 / 1000000;
1346}
1347
1354static inline float sensor_value_to_float(const struct sensor_value *val)
1355{
1356 return (float)val->val1 + (float)val->val2 / 1000000;
1357}
1358
1366static inline int sensor_value_from_double(struct sensor_value *val, double inp)
1367{
1368 if (inp < (double)INT32_MIN || inp > (double)INT32_MAX) {
1369 return -ERANGE;
1370 }
1371
1372 int32_t val1 = (int32_t)inp;
1373 int32_t val2 = (int32_t)((inp - (double)val1) * 1000000.0);
1374
1375 val->val1 = val1;
1376 val->val2 = val2;
1377
1378 return 0;
1379}
1380
1388static inline int sensor_value_from_float(struct sensor_value *val, float inp)
1389{
1390 if (inp < (float)INT32_MIN || inp >= (float)INT32_MAX) {
1391 return -ERANGE;
1392 }
1393
1394 int32_t val1 = (int32_t)inp;
1395 int32_t val2 = (int32_t)((inp - (float)val1) * 1000000.0f);
1396
1397 val->val1 = val1;
1398 val->val2 = val2;
1399
1400 return 0;
1401}
1402
1403#ifdef CONFIG_SENSOR_INFO
1404
1405struct sensor_info {
1406 const struct device *dev;
1407 const char *vendor;
1408 const char *model;
1409 const char *friendly_name;
1410};
1411
1412#define SENSOR_INFO_INITIALIZER(_dev, _vendor, _model, _friendly_name) \
1413 { \
1414 .dev = _dev, \
1415 .vendor = _vendor, \
1416 .model = _model, \
1417 .friendly_name = _friendly_name, \
1418 }
1419
1420#define SENSOR_INFO_DEFINE(name, ...) \
1421 static const STRUCT_SECTION_ITERABLE(sensor_info, name) = \
1422 SENSOR_INFO_INITIALIZER(__VA_ARGS__)
1423
1424#define SENSOR_INFO_DT_NAME(node_id) \
1425 _CONCAT(__sensor_info, DEVICE_DT_NAME_GET(node_id))
1426
1427#define SENSOR_INFO_DT_DEFINE(node_id) \
1428 SENSOR_INFO_DEFINE(SENSOR_INFO_DT_NAME(node_id), \
1429 DEVICE_DT_GET(node_id), \
1430 DT_NODE_VENDOR_OR(node_id, NULL), \
1431 DT_NODE_MODEL_OR(node_id, NULL), \
1432 DT_PROP_OR(node_id, friendly_name, NULL)) \
1433
1434#else
1435
1436#define SENSOR_INFO_DEFINE(name, ...)
1437#define SENSOR_INFO_DT_DEFINE(node_id)
1438
1439#endif /* CONFIG_SENSOR_INFO */
1440
1468#define SENSOR_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
1469 data_ptr, cfg_ptr, level, prio, \
1470 api_ptr, ...) \
1471 DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
1472 data_ptr, cfg_ptr, level, prio, \
1473 api_ptr, __VA_ARGS__); \
1474 \
1475 SENSOR_INFO_DT_DEFINE(node_id);
1476
1486#define SENSOR_DEVICE_DT_INST_DEFINE(inst, ...) \
1487 SENSOR_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1488
1495static inline int64_t sensor_value_to_deci(const struct sensor_value *val)
1496{
1497 return ((int64_t)val->val1 * 10) + val->val2 / 100000;
1498}
1499
1506static inline int64_t sensor_value_to_centi(const struct sensor_value *val)
1507{
1508 return ((int64_t)val->val1 * 100) + val->val2 / 10000;
1509}
1510
1517static inline int64_t sensor_value_to_milli(const struct sensor_value *val)
1518{
1519 return ((int64_t)val->val1 * 1000) + val->val2 / 1000;
1520}
1521
1528static inline int64_t sensor_value_to_micro(const struct sensor_value *val)
1529{
1530 return ((int64_t)val->val1 * 1000000) + val->val2;
1531}
1532
1540static inline int sensor_value_from_milli(struct sensor_value *val, int64_t milli)
1541{
1542 if (milli < ((int64_t)INT32_MIN - 1) * 1000LL ||
1543 milli > ((int64_t)INT32_MAX + 1) * 1000LL) {
1544 return -ERANGE;
1545 }
1546
1547 val->val1 = (int32_t)(milli / 1000);
1548 val->val2 = (int32_t)(milli % 1000) * 1000;
1549
1550 return 0;
1551}
1552
1560static inline int sensor_value_from_micro(struct sensor_value *val, int64_t micro)
1561{
1562 if (micro < ((int64_t)INT32_MIN - 1) * 1000000LL ||
1563 micro > ((int64_t)INT32_MAX + 1) * 1000000LL) {
1564 return -ERANGE;
1565 }
1566
1567 val->val1 = (int32_t)(micro / 1000000LL);
1568 val->val2 = (int32_t)(micro % 1000000LL);
1569
1570 return 0;
1571}
1572
1576
1582#define SENSOR_DECODER_NAME() UTIL_CAT(DT_DRV_COMPAT, __decoder_api)
1583
1591#define SENSOR_DECODER_DT_GET(node_id) \
1592 &UTIL_CAT(DT_STRING_TOKEN_BY_IDX(node_id, compatible, 0), __decoder_api)
1593
1609#define SENSOR_DECODER_API_DT_DEFINE() \
1610 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), (), (static)) \
1611 const STRUCT_SECTION_ITERABLE(sensor_decoder_api, SENSOR_DECODER_NAME())
1612
1613#define Z_MAYBE_SENSOR_DECODER_DECLARE_INTERNAL_IDX(node_id, prop, idx) \
1614 extern const struct sensor_decoder_api UTIL_CAT( \
1615 DT_STRING_TOKEN_BY_IDX(node_id, prop, idx), __decoder_api);
1616
1617#define Z_MAYBE_SENSOR_DECODER_DECLARE_INTERNAL(node_id) \
1618 COND_CODE_1(DT_NODE_HAS_PROP(node_id, compatible), \
1619 (DT_FOREACH_PROP_ELEM(node_id, compatible, \
1620 Z_MAYBE_SENSOR_DECODER_DECLARE_INTERNAL_IDX)), \
1621 ())
1622
1623DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_SENSOR_DECODER_DECLARE_INTERNAL)
1624
1625#ifdef __cplusplus
1626}
1627#endif
1628
1629#include <zephyr/syscalls/sensor.h>
1630
1631#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_H_ */
irp nz macro MOVR cc d
Definition asm-macro-32-bit-gnu.h:11
System error numbers.
#define DT_FOREACH_STATUS_OKAY_NODE(fn)
Invokes fn for every status okay node in the tree.
Definition devicetree.h:3048
#define RTIO_PRIO_NORM
Normal priority.
Definition rtio.h:71
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 rtio.h:624
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:1725
int rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes, struct rtio_sqe **handle, size_t sqe_count)
Copy an array of SQEs into the queue and get resulting handles back.
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 rtio.h:603
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition rtio.h:1108
static void rtio_sqe_prep_read_multishot(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Definition rtio.h:632
static void rtio_cqe_release(struct rtio *r, struct rtio_cqe *cqe)
Release consumed completion queue event.
Definition rtio.h:1282
static struct rtio_cqe * rtio_cqe_consume_block(struct rtio *r)
Wait for and consume a single completion queue event.
Definition rtio.h:1258
int rtio_submit(struct rtio *r, uint32_t wait_count)
Submit I/O requests to the underlying executor.
#define SENSOR_G
The value of gravitational constant in micro m/s^2.
Definition sensor.h:1193
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.
Definition sensor.h:421
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:609
static int sensor_stream(const struct rtio_iodev *iodev, struct rtio *ctx, void *userdata, struct rtio_sqe **handle)
Definition sensor.h:1062
static int32_t sensor_rad_to_degrees(const struct sensor_value *rad)
Helper function for converting radians to degrees.
Definition sensor.h:1284
sensor_trigger_type
Sensor trigger types.
Definition sensor.h:239
sensor_attribute
Sensor attribute types.
Definition sensor.h:323
int sensor_get_decoder(const struct device *dev, const struct sensor_decoder_api **decoder)
Get the sensor's decoder API.
int(* sensor_get_decoder_t)(const struct device *dev, const struct sensor_decoder_api **api)
Get the decoder associate with the given device.
Definition sensor.h:623
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:1271
static double sensor_value_to_double(const struct sensor_value *val)
Helper function for converting struct sensor_value to double.
Definition sensor.h:1343
static float sensor_value_to_float(const struct sensor_value *val)
Helper function for converting struct sensor_value to float.
Definition sensor.h:1354
int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel, size_t *base_size, size_t *frame_size)
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.
Definition sensor.h:410
static void sensor_degrees_to_rad(int32_t d, struct sensor_value *rad)
Helper function for converting degrees to radians.
Definition sensor.h:1301
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:1258
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.
Definition sensor.h:449
static int sensor_value_from_float(struct sensor_value *val, float inp)
Helper function for converting float to struct sensor_value.
Definition sensor.h:1388
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:1225
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:1517
#define SENSOR_PI
The value of constant PI in micros.
Definition sensor.h:1198
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_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:824
sensor_stream_data_opt
Options for what to do with the associated data when a trigger is consumed.
Definition sensor.h:629
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:1540
void(* sensor_trigger_handler_t)(const struct device *dev, const struct sensor_trigger *trigger)
Callback API upon firing of a trigger.
Definition sensor.h:401
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:1528
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:1239
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:1172
sensor_channel
Sensor channels.
Definition sensor.h:65
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:1331
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:1208
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:1495
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:1560
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_sample_fetch_t)(const struct device *dev, enum sensor_channel chan)
Callback API for fetching data from a sensor.
Definition sensor.h:441
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:1099
void(* sensor_submit_t)(const struct device *sensor, struct rtio_iodev_sqe *sqe)
Definition sensor.h:720
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.
Definition sensor.h:432
static int32_t sensor_rad_to_10udegrees(const struct sensor_value *rad)
Helper function for converting radians to 10 micro degrees.
Definition sensor.h:1318
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:1506
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:480
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:1366
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:1141
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.
@ SENSOR_TRIG_OVERFLOW
Trigger fires when data overflows.
Definition sensor.h:291
@ SENSOR_TRIG_DELTA
Trigger fires when the selected channel varies significantly.
Definition sensor.h:255
@ SENSOR_TRIG_NEAR_FAR
Trigger fires when a near/far event is detected.
Definition sensor.h:257
@ SENSOR_TRIG_FREEFALL
Trigger fires when a free fall is detected.
Definition sensor.h:273
@ SENSOR_TRIG_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:302
@ SENSOR_TRIG_FIFO_FULL
Trigger fires when the FIFO becomes full.
Definition sensor.h:285
@ SENSOR_TRIG_MOTION
Trigger fires when motion is detected.
Definition sensor.h:276
@ SENSOR_TRIG_STATIONARY
Trigger fires when no motion has been detected for a while.
Definition sensor.h:279
@ SENSOR_TRIG_COMMON_COUNT
Number of all common sensor triggers.
Definition sensor.h:296
@ SENSOR_TRIG_THRESHOLD
Trigger fires when channel reading transitions configured thresholds.
Definition sensor.h:264
@ SENSOR_TRIG_MAX
Maximum value describing a sensor trigger type.
Definition sensor.h:307
@ SENSOR_TRIG_DOUBLE_TAP
Trigger fires when a double tap is detected.
Definition sensor.h:270
@ SENSOR_TRIG_TILT
Trigger fires when a tilt is detected.
Definition sensor.h:288
@ SENSOR_TRIG_TIMER
Timer-based trigger, useful when the sensor does not have an interrupt line.
Definition sensor.h:244
@ SENSOR_TRIG_FIFO_WATERMARK
Trigger fires when the FIFO watermark has been reached.
Definition sensor.h:282
@ SENSOR_TRIG_TAP
Trigger fires when a single tap is detected.
Definition sensor.h:267
@ SENSOR_TRIG_DATA_READY
Trigger fires whenever new data is ready.
Definition sensor.h:246
@ SENSOR_ATTR_HYSTERESIS
Definition sensor.h:341
@ SENSOR_ATTR_FEATURE_MASK
Enable/disable sensor features.
Definition sensor.h:361
@ SENSOR_ATTR_CALIB_TARGET
Calibration target.
Definition sensor.h:355
@ SENSOR_ATTR_OFFSET
The sensor value returned will be altered by the amount indicated by offset: final_value = sensor_val...
Definition sensor.h:350
@ SENSOR_ATTR_BATCH_DURATION
Hardware batch duration in ticks.
Definition sensor.h:372
@ SENSOR_ATTR_OVERSAMPLING
Oversampling factor.
Definition sensor.h:343
@ SENSOR_ATTR_FF_DUR
Free-fall duration represented in milliseconds.
Definition sensor.h:369
@ SENSOR_ATTR_UPPER_THRESH
Upper threshold for trigger.
Definition sensor.h:332
@ SENSOR_ATTR_CONFIGURATION
Configure the operating modes of a sensor.
Definition sensor.h:357
@ SENSOR_ATTR_RESOLUTION
Definition sensor.h:376
@ SENSOR_ATTR_CALIBRATION
Set a calibration value needed by a sensor.
Definition sensor.h:359
@ SENSOR_ATTR_COMMON_COUNT
Number of all common sensor attributes.
Definition sensor.h:380
@ SENSOR_ATTR_ALERT
Alert threshold or alert enable/disable.
Definition sensor.h:363
@ SENSOR_ATTR_SLOPE_TH
Threshold for any-motion (slope) trigger.
Definition sensor.h:334
@ SENSOR_ATTR_GAIN
Definition sensor.h:374
@ SENSOR_ATTR_SAMPLING_FREQUENCY
Sensor sampling frequency, i.e.
Definition sensor.h:328
@ SENSOR_ATTR_FULL_SCALE
Sensor range, in SI units.
Definition sensor.h:345
@ SENSOR_ATTR_LOWER_THRESH
Lower threshold for trigger.
Definition sensor.h:330
@ SENSOR_ATTR_SLOPE_DUR
Duration for which the slope values needs to be outside the threshold for the trigger to fire.
Definition sensor.h:339
@ SENSOR_ATTR_MAX
Maximum value describing a sensor attribute type.
Definition sensor.h:391
@ SENSOR_ATTR_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:386
@ SENSOR_STREAM_DATA_INCLUDE
Include whatever data is associated with the trigger.
Definition sensor.h:631
@ SENSOR_STREAM_DATA_NOP
Do nothing with the associated trigger data, it may be consumed later.
Definition sensor.h:633
@ SENSOR_STREAM_DATA_DROP
Flush/clear whatever data is associated with the trigger.
Definition sensor.h:635
@ SENSOR_CHAN_GAUGE_STATE_OF_HEALTH
State of health measurement in %.
Definition sensor.h:193
@ SENSOR_CHAN_PM_1_0
1.0 micro-meters Particulate Matter, in ug/m^3
Definition sensor.h:119
@ SENSOR_CHAN_DIE_TEMP
Device die temperature in degrees Celsius.
Definition sensor.h:91
@ SENSOR_CHAN_PRESS
Pressure in kilopascal.
Definition sensor.h:95
@ SENSOR_CHAN_GAUGE_TIME_TO_FULL
Time to full in minutes.
Definition sensor.h:197
@ SENSOR_CHAN_ACCEL_XYZ
Acceleration on the X, Y and Z axes.
Definition sensor.h:73
@ SENSOR_CHAN_MAGN_X
Magnetic field on the X axis, in Gauss.
Definition sensor.h:83
@ SENSOR_CHAN_O2
O2 level, in parts per million (ppm).
Definition sensor.h:130
@ SENSOR_CHAN_CURRENT
Current, in amps.
Definition sensor.h:145
@ SENSOR_CHAN_GYRO_XYZ
Angular velocity around the X, Y and Z axes.
Definition sensor.h:81
@ SENSOR_CHAN_VSHUNT
Current Shunt Voltage in milli-volts.
Definition sensor.h:142
@ SENSOR_CHAN_GREEN
Illuminance in green spectrum, in lux.
Definition sensor.h:112
@ SENSOR_CHAN_GRAVITY_VECTOR
Gravity Vector (X/Y/Z components in m/s^2).
Definition sensor.h:209
@ SENSOR_CHAN_MAGN_Z
Magnetic field on the Z axis, in Gauss.
Definition sensor.h:87
@ SENSOR_CHAN_MAGN_Y
Magnetic field on the Y axis, in Gauss.
Definition sensor.h:85
@ SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE
Desired voltage of cell in V (nominal voltage).
Definition sensor.h:203
@ SENSOR_CHAN_POWER
Power in watts.
Definition sensor.h:147
@ SENSOR_CHAN_PM_2_5
2.5 micro-meters Particulate Matter, in ug/m^3
Definition sensor.h:121
@ SENSOR_CHAN_RESISTANCE
Resistance , in Ohm.
Definition sensor.h:150
@ SENSOR_CHAN_GAME_ROTATION_VECTOR
Game Rotation Vector (unit quaternion components X/Y/Z/W).
Definition sensor.h:207
@ SENSOR_CHAN_AMBIENT_LIGHT
Ambient illuminance in visible spectrum, in lux.
Definition sensor.h:104
@ SENSOR_CHAN_GAUGE_AVG_CURRENT
Average current, in amps (negative=discharging).
Definition sensor.h:173
@ SENSOR_CHAN_ENCODER_COUNT
Raw quadrature decoder count, in counts.
Definition sensor.h:214
@ SENSOR_CHAN_GYRO_Y
Angular velocity around the Y axis, in radians/s.
Definition sensor.h:77
@ SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT
Desired charging current in mA.
Definition sensor.h:205
@ SENSOR_CHAN_FREQUENCY
Frequency, in Hz.
Definition sensor.h:168
@ SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY
Full Charge Capacity in mAh.
Definition sensor.h:183
@ SENSOR_CHAN_ROTATION
Angular rotation, in degrees.
Definition sensor.h:153
@ SENSOR_CHAN_AMBIENT_TEMP
Ambient temperature in degrees Celsius.
Definition sensor.h:93
@ SENSOR_CHAN_MAGN_XYZ
Magnetic field on the X, Y and Z axes.
Definition sensor.h:89
@ SENSOR_CHAN_GAUGE_STDBY_CURRENT
Standby current, in amps (negative=discharging).
Definition sensor.h:175
@ SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT
Max load current, in amps (negative=discharging).
Definition sensor.h:177
@ SENSOR_CHAN_ACCEL_Y
Acceleration on the Y axis, in m/s^2.
Definition sensor.h:69
@ SENSOR_CHAN_RPM
Revolutions per minute, in RPM.
Definition sensor.h:165
@ SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY
Full Available Capacity in mAh.
Definition sensor.h:189
@ SENSOR_CHAN_VOLTAGE
Voltage, in volts.
Definition sensor.h:139
@ SENSOR_CHAN_FLOW_RATE
Flow rate in litres per minute.
Definition sensor.h:136
@ SENSOR_CHAN_BLUE
Illuminance in blue spectrum, in lux.
Definition sensor.h:114
@ SENSOR_CHAN_LIGHT
Illuminance in visible spectrum, in lux.
Definition sensor.h:106
@ SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE
Design voltage of cell in V (max voltage).
Definition sensor.h:201
@ SENSOR_CHAN_ACCEL_Z
Acceleration on the Z axis, in m/s^2.
Definition sensor.h:71
@ SENSOR_CHAN_CO2
CO2 level, in parts per million (ppm).
Definition sensor.h:128
@ SENSOR_CHAN_GAUGE_STATE_OF_CHARGE
State of charge measurement in %.
Definition sensor.h:181
@ SENSOR_CHAN_POS_DXYZ
Position change on the X, Y and Z axis, in points.
Definition sensor.h:162
@ SENSOR_CHAN_GBIAS_XYZ
Gyroscope bias (X/Y/Z components in radians/s).
Definition sensor.h:211
@ SENSOR_CHAN_GAUGE_CYCLE_COUNT
Cycle count (total number of charge/discharge cycles).
Definition sensor.h:199
@ SENSOR_CHAN_GAUGE_TEMP
Gauge temperature.
Definition sensor.h:179
@ SENSOR_CHAN_POS_DY
Position change on the Y axis, in points.
Definition sensor.h:158
@ SENSOR_CHAN_GYRO_Z
Angular velocity around the Z axis, in radians/s.
Definition sensor.h:79
@ SENSOR_CHAN_POS_DX
Position change on the X axis, in points.
Definition sensor.h:156
@ SENSOR_CHAN_GAUGE_AVG_POWER
Average power in mW.
Definition sensor.h:191
@ SENSOR_CHAN_GAUGE_TIME_TO_EMPTY
Time to empty in minutes.
Definition sensor.h:195
@ SENSOR_CHAN_PM_10
10 micro-meters Particulate Matter, in ug/m^3
Definition sensor.h:123
@ SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY
Remaining Charge Capacity in mAh.
Definition sensor.h:185
@ SENSOR_CHAN_ALL
All channels.
Definition sensor.h:217
@ SENSOR_CHAN_GAUGE_VOLTAGE
Voltage, in volts.
Definition sensor.h:171
@ SENSOR_CHAN_PROX
Proximity.
Definition sensor.h:100
@ SENSOR_CHAN_COMMON_COUNT
Number of all common sensor channels.
Definition sensor.h:222
@ SENSOR_CHAN_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:228
@ SENSOR_CHAN_GYRO_X
Angular velocity around the X axis, in radians/s.
Definition sensor.h:75
@ SENSOR_CHAN_GAS_RES
Gas sensor resistance in ohms.
Definition sensor.h:134
@ SENSOR_CHAN_HUMIDITY
Humidity, in percent.
Definition sensor.h:102
@ SENSOR_CHAN_DISTANCE
Distance.
Definition sensor.h:125
@ SENSOR_CHAN_IR
Illuminance in infra-red spectrum, in lux.
Definition sensor.h:108
@ SENSOR_CHAN_MAX
Maximum value describing a sensor channel type.
Definition sensor.h:233
@ SENSOR_CHAN_POS_DZ
Position change on the Z axis, in points.
Definition sensor.h:160
@ SENSOR_CHAN_RED
Illuminance in red spectrum, in lux.
Definition sensor.h:110
@ SENSOR_CHAN_ALTITUDE
Altitude, in meters.
Definition sensor.h:116
@ SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY
Nominal Available Capacity in mAh.
Definition sensor.h:187
@ SENSOR_CHAN_ACCEL_X
Acceleration on the X axis, in m/s^2.
Definition sensor.h:67
@ SENSOR_CHAN_VOC
VOC level, in parts per billion (ppb).
Definition sensor.h:132
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:148
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define ENOMEM
Not enough core.
Definition errno.h:50
#define ERANGE
Result too large.
Definition errno.h:72
#define NULL
Definition iar_missing_defs.h:20
#define BUILD_ASSERT(EXPR, MSG...)
Definition llvm.h:51
Size of off_t must be equal or less than size of size_t
Definition retained_mem.h:29
Real-Time IO device API for moving bytes with low effort.
#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:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
A completion queue event.
Definition rtio.h:386
void * userdata
Associated userdata with operation.
Definition rtio.h:390
int32_t result
Result from operation.
Definition rtio.h:389
API that an RTIO IO device should implement.
Definition rtio.h:525
Compute the mempool block index for a given pointer.
Definition rtio.h:515
struct rtio_sqe sqe
Definition rtio.h:516
An IO device with a function table for submitting requests.
Definition rtio.h:540
void * data
Definition rtio.h:545
A submission queue event.
Definition rtio.h:296
void * userdata
User provided data which is returned upon operation completion.
Definition rtio.h:314
uint32_t buf_len
Length of buffer.
Definition rtio.h:320
const struct rtio_iodev * iodev
Device to operation on.
Definition rtio.h:305
const uint8_t * buf
Buffer to write from.
Definition rtio.h:321
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:419
Sensor Channel Specification.
Definition sensor.h:461
uint16_t chan_idx
A sensor channel index.
Definition sensor.h:463
uint16_t chan_type
A sensor channel type.
Definition sensor.h:462
Definition sensor.h:939
uint64_t timestamp_ns
The timestamp at which the data was collected from the sensor.
Definition sensor.h:941
int8_t shift
Shift value for all samples in the frame.
Definition sensor.h:951
uint32_t num_channels
Definition sensor.h:948
struct sensor_chan_spec channels[0]
Channels present in the frame.
Definition sensor.h:957
Used for iterating over the data frames via the sensor_decoder_api.
Definition sensor.h:583
const struct sensor_decoder_api * decoder
Definition sensor.h:584
struct sensor_chan_spec channel
Definition sensor.h:586
const uint8_t * buffer
Definition sensor.h:585
uint32_t fit
Definition sensor.h:587
Decodes a single raw data buffer.
Definition sensor.h:493
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:519
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:504
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:546
bool(* has_trigger)(const uint8_t *buffer, enum sensor_trigger_type trigger)
Check if the given trigger type is present.
Definition sensor.h:556
Definition sensor.h:728
sensor_get_decoder_t get_decoder
Definition sensor.h:734
sensor_attr_set_t attr_set
Definition sensor.h:729
sensor_attr_get_t attr_get
Definition sensor.h:730
sensor_trigger_set_t trigger_set
Definition sensor.h:731
sensor_sample_fetch_t sample_fetch
Definition sensor.h:732
sensor_channel_get_t channel_get
Definition sensor.h:733
sensor_submit_t submit
Definition sensor.h:735
Definition sensor.h:652
struct sensor_chan_spec *const channels
Definition sensor.h:656
size_t count
Definition sensor.h:659
struct sensor_stream_trigger *const triggers
Definition sensor.h:657
const bool is_streaming
Definition sensor.h:654
const struct device * sensor
Definition sensor.h:653
const size_t max
Definition sensor.h:660
Definition sensor.h:638
enum sensor_stream_data_opt opt
Definition sensor.h:640
enum sensor_trigger_type trigger
Definition sensor.h:639
Sensor trigger spec.
Definition sensor.h:313
enum sensor_trigger_type type
Trigger type.
Definition sensor.h:315
enum sensor_channel chan
Channel the trigger is set on.
Definition sensor.h:317
Representation of a sensor readout value.
Definition sensor.h:55
int32_t val2
Fractional part of the value (in one-millionth parts).
Definition sensor.h:59
int32_t val1
Integer part of the value.
Definition sensor.h:57
#define INT64_C(x)
Definition xcc.h:119