Zephyr API Documentation 4.4.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
adc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_DRIVERS_ADC_H_
15#define ZEPHYR_INCLUDE_DRIVERS_ADC_H_
16
17#include <zephyr/device.h>
19#include <zephyr/kernel.h>
20#include <zephyr/rtio/rtio.h>
21#include <zephyr/dsp/types.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
40
65
82int adc_gain_invert(enum adc_gain gain, int32_t *value);
83
100int adc_gain_invert_64(enum adc_gain gain, int64_t *value);
101
112
119
122
133
157
160
161#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS
167 uint8_t input_positive;
168
174 uint8_t input_negative;
175#endif /* CONFIG_ADC_CONFIGURABLE_INPUTS */
176
177#ifdef CONFIG_ADC_CONFIGURABLE_EXCITATION_CURRENT_SOURCE_PIN
178 uint8_t current_source_pin_set : 1;
185 uint8_t current_source_pin[2];
186#endif /* CONFIG_ADC_CONFIGURABLE_EXCITATION_CURRENT_SOURCE_PIN */
187
188#ifdef CONFIG_ADC_CONFIGURABLE_VBIAS_PIN
197 uint32_t vbias_pins;
198#endif /* CONFIG_ADC_CONFIGURABLE_VBIAS_PIN */
199};
200
265#define ADC_CHANNEL_CFG_DT(node_id) { \
266 .gain = DT_STRING_TOKEN(node_id, zephyr_gain), \
267 .reference = DT_STRING_TOKEN(node_id, zephyr_reference), \
268 .acquisition_time = DT_PROP(node_id, zephyr_acquisition_time), \
269 .channel_id = DT_REG_ADDR(node_id), \
270COND_CODE_1(UTIL_OR(DT_PROP(node_id, zephyr_differential), \
271 UTIL_AND(CONFIG_ADC_CONFIGURABLE_INPUTS, \
272 DT_NODE_HAS_PROP(node_id, zephyr_input_negative))), \
273 (.differential = true,), \
274 (.differential = false,)) \
275IF_ENABLED(CONFIG_ADC_CONFIGURABLE_INPUTS, \
276 (.input_positive = DT_PROP_OR(node_id, zephyr_input_positive, 0), \
277 .input_negative = DT_PROP_OR(node_id, zephyr_input_negative, 0),)) \
278IF_ENABLED(CONFIG_ADC_CONFIGURABLE_EXCITATION_CURRENT_SOURCE_PIN, \
279 (.current_source_pin_set = DT_NODE_HAS_PROP(node_id, zephyr_current_source_pin), \
280 .current_source_pin = DT_PROP_OR(node_id, zephyr_current_source_pin, {0}),)) \
281IF_ENABLED(CONFIG_ADC_CONFIGURABLE_VBIAS_PIN, \
282 (.vbias_pins = DT_PROP_OR(node_id, zephyr_vbias_pins, 0),)) \
283}
284
341
343
344#define ADC_DT_SPEC_STRUCT(ctlr, input) { \
345 .dev = DEVICE_DT_GET(ctlr), \
346 .channel_id = input, \
347 ADC_CHANNEL_CFG_FROM_DT_NODE(\
348 ADC_CHANNEL_DT_NODE(ctlr, input)) \
349 }
350
351#define ADC_CHANNEL_DT_NODE(ctlr, input) \
352 DT_CHILD_BY_UNIT_ADDR_INT(ctlr, input)
353
354#define ADC_CHANNEL_CFG_FROM_DT_NODE(node_id) \
355 IF_ENABLED(DT_NODE_EXISTS(node_id), \
356 (.channel_cfg_dt_node_exists = true, \
357 .channel_cfg = ADC_CHANNEL_CFG_DT(node_id), \
358 .vref_mv = DT_PROP_OR(node_id, zephyr_vref_mv, 0), \
359 .resolution = DT_PROP_OR(node_id, zephyr_resolution, 0), \
360 .oversampling = DT_PROP_OR(node_id, zephyr_oversampling, 0),))
361
363
432#define ADC_DT_SPEC_GET_BY_NAME(node_id, name) \
433 ADC_DT_SPEC_STRUCT(DT_IO_CHANNELS_CTLR_BY_NAME(node_id, name), \
434 DT_IO_CHANNELS_INPUT_BY_NAME(node_id, name))
435
448#define ADC_DT_SPEC_GET_BY_NAME_OR(node_id, name, default_value) \
449 COND_CODE_1(DT_PROP_HAS_NAME(node_id, io_channels, name), \
450 (ADC_DT_SPEC_GET_BY_NAME(node_id, name)), (default_value))
451
462#define ADC_DT_SPEC_INST_GET_BY_NAME(inst, name) \
463 ADC_DT_SPEC_GET_BY_NAME(DT_DRV_INST(inst), name)
464
477#define ADC_DT_SPEC_INST_GET_BY_NAME_OR(inst, name, default_value) \
478 ADC_DT_SPEC_GET_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
479
549#define ADC_DT_SPEC_GET_BY_IDX(node_id, idx) \
550 ADC_DT_SPEC_STRUCT(DT_IO_CHANNELS_CTLR_BY_IDX(node_id, idx), \
551 DT_IO_CHANNELS_INPUT_BY_IDX(node_id, idx))
552
565#define ADC_DT_SPEC_GET_BY_IDX_OR(node_id, idx, default_value) \
566 COND_CODE_1(DT_PROP_HAS_IDX(node_id, io_channels, idx), \
567 (ADC_DT_SPEC_GET_BY_IDX(node_id, idx)), (default_value))
568
579#define ADC_DT_SPEC_INST_GET_BY_IDX(inst, idx) \
580 ADC_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)
581
594#define ADC_DT_SPEC_INST_GET_BY_IDX_OR(inst, idx, default_value) \
595 ADC_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), idx, default_value)
596
605#define ADC_DT_SPEC_GET(node_id) ADC_DT_SPEC_GET_BY_IDX(node_id, 0)
606
618#define ADC_DT_SPEC_GET_OR(node_id, default_value) \
619 ADC_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value)
620
630#define ADC_DT_SPEC_INST_GET(inst) ADC_DT_SPEC_GET(DT_DRV_INST(inst))
631
643#define ADC_DT_SPEC_INST_GET_OR(inst, default_value) \
644 ADC_DT_SPEC_GET_OR(DT_DRV_INST(inst), default_value)
645
646/* Forward declaration of the adc_sequence structure. */
647struct adc_sequence;
648
665
685typedef enum adc_action (*adc_sequence_callback)(const struct device *dev,
686 const struct adc_sequence *sequence,
687 uint16_t sampling_index);
688
722
732
741
753 void *buffer;
754
762
763#if defined(CONFIG_ADC_SEQUENCE_PRIORITY) || defined(__DOXYGEN__)
775#endif
776
785
793
803};
804
818
832
862
874
879
891
892/*
893 * Internal data structure used to store information about the IODevice for async reading and
894 * streaming adc data.
895 */
907
922 int (*get_frame_count)(const uint8_t *buffer, uint32_t channel,
923 uint16_t *frame_count);
924
938 int (*get_size_info)(struct adc_dt_spec adc_spec, uint32_t channel, size_t *base_size,
939 size_t *frame_size);
940
956 int (*decode)(const uint8_t *buffer, uint32_t channel, uint32_t *fit,
957 uint16_t max_count, void *data_out);
958
966 bool (*has_trigger)(const uint8_t *buffer, enum adc_trigger_type trigger);
967};
968
973typedef int (*adc_api_channel_setup)(const struct device *dev,
974 const struct adc_channel_cfg *channel_cfg);
975
980typedef int (*adc_api_read)(const struct device *dev,
981 const struct adc_sequence *sequence);
982
986typedef void (*adc_api_submit)(const struct device *dev,
987 struct rtio_iodev_sqe *sqe);
988
994typedef int (*adc_api_get_decoder)(const struct device *dev,
995 const struct adc_decoder_api **api);
996
997
1003typedef int (*adc_api_read_async)(const struct device *dev,
1004 const struct adc_sequence *sequence,
1005 struct k_poll_signal *async);
1006
1012__subsystem struct adc_driver_api {
1015#ifdef CONFIG_ADC_ASYNC
1016 adc_api_read_async read_async;
1017#endif
1018#ifdef CONFIG_ADC_STREAM
1019 adc_api_submit submit;
1020 adc_api_get_decoder get_decoder;
1021#endif
1023};
1024
1037__syscall int adc_channel_setup(const struct device *dev,
1038 const struct adc_channel_cfg *channel_cfg);
1039
1040static inline int z_impl_adc_channel_setup(const struct device *dev,
1041 const struct adc_channel_cfg *channel_cfg)
1042{
1043 return DEVICE_API_GET(adc, dev)->channel_setup(dev, channel_cfg);
1044}
1045
1055static inline int adc_channel_setup_dt(const struct adc_dt_spec *spec)
1056{
1057 if (!spec->channel_cfg_dt_node_exists) {
1058 return -ENOTSUP;
1059 }
1060
1061 return adc_channel_setup(spec->dev, &spec->channel_cfg);
1062}
1063
1085__syscall int adc_read(const struct device *dev,
1086 const struct adc_sequence *sequence);
1087
1088static inline int z_impl_adc_read(const struct device *dev,
1089 const struct adc_sequence *sequence)
1090{
1091 return DEVICE_API_GET(adc, dev)->read(dev, sequence);
1092}
1093
1103static inline int adc_read_dt(const struct adc_dt_spec *spec,
1104 const struct adc_sequence *sequence)
1105{
1106 return adc_read(spec->dev, sequence);
1107}
1108
1129__syscall int adc_read_async(const struct device *dev,
1130 const struct adc_sequence *sequence,
1131 struct k_poll_signal *async);
1132
1133#ifdef CONFIG_ADC_ASYNC
1134static inline int z_impl_adc_read_async(const struct device *dev,
1135 const struct adc_sequence *sequence,
1136 struct k_poll_signal *async)
1137{
1138 return DEVICE_API_GET(adc, dev)->read_async(dev, sequence, async);
1139}
1140#endif /* CONFIG_ADC_ASYNC */
1141
1161static inline int adc_read_async_dt(const struct adc_dt_spec *spec,
1162 const struct adc_sequence *sequence,
1163 struct k_poll_signal *async)
1164{
1165 return adc_read_async(spec->dev, sequence, async);
1166}
1167
1180__syscall int adc_get_decoder(const struct device *dev,
1181 const struct adc_decoder_api **api);
1182
1189struct __attribute__((__packed__)) adc_data_generic_header {
1192
1195
1198
1199 /* This padding is needed to make sure that the 'channels' field is aligned */
1200 int16_t _padding;
1201
1204};
1205
1230static inline int adc_stream(struct rtio_iodev *iodev, struct rtio *ctx, void *userdata,
1231 struct rtio_sqe **handle)
1232{
1233 if (IS_ENABLED(CONFIG_USERSPACE)) {
1234 struct rtio_sqe sqe;
1235
1237 rtio_sqe_copy_in_get_handles(ctx, &sqe, handle, 1);
1238 } else {
1239 struct rtio_sqe *sqe = rtio_sqe_acquire(ctx);
1240
1241 if (sqe == NULL) {
1242 return -ENOMEM;
1243 }
1244 if (handle != NULL) {
1245 *handle = sqe;
1246 }
1248 }
1249 rtio_submit(ctx, 0);
1250 return 0;
1251}
1252
1253#ifdef CONFIG_ADC_STREAM
1254static inline int z_impl_adc_get_decoder(const struct device *dev,
1255 const struct adc_decoder_api **decoder)
1256{
1257 const struct adc_driver_api *api = DEVICE_API_GET(adc, dev);
1258
1259 __ASSERT_NO_MSG(api != NULL);
1260
1261 if (api->get_decoder == NULL) {
1262 *decoder = NULL;
1263 return -1;
1264 }
1265
1266 return api->get_decoder(dev, decoder);
1267}
1268#endif /* CONFIG_ADC_STREAM */
1269
1279static inline uint16_t adc_ref_internal(const struct device *dev)
1280{
1281 return DEVICE_API_GET(adc, dev)->ref_internal;
1282}
1283
1307typedef int (*adc_raw_to_x_fn)(int32_t ref_mv, enum adc_gain gain, uint8_t resolution,
1308 int32_t *valp);
1309
1315static inline int adc_raw_to_millivolts(int32_t ref_mv, enum adc_gain gain, uint8_t resolution,
1316 int32_t *valp)
1317{
1318 int64_t adc_mv = (int64_t)*valp * (int64_t)ref_mv;
1319 int ret = adc_gain_invert_64(gain, &adc_mv);
1320
1321 if (ret == 0) {
1322 adc_mv = adc_mv >> resolution;
1323 if (adc_mv > INT32_MAX || adc_mv < INT32_MIN) {
1324 __ASSERT_MSG_INFO("conversion result is out of range");
1325 }
1326
1327 *valp = (int32_t)adc_mv;
1328 }
1329
1330 return ret;
1331}
1332
1338static inline int adc_raw_to_microvolts(int32_t ref_mv, enum adc_gain gain, uint8_t resolution,
1339 int32_t *valp)
1340{
1341 int64_t adc_uv = (int64_t)*valp * ref_mv * 1000;
1342 int ret = adc_gain_invert_64(gain, &adc_uv);
1343
1344 if (ret == 0) {
1345 *valp = (int32_t)(adc_uv >> resolution);
1346 }
1347
1348 return ret;
1349}
1350
1367static inline int adc_raw_to_x_dt_chan(adc_raw_to_x_fn conv_func,
1368 const struct adc_dt_spec *spec,
1369 const struct adc_channel_cfg *channel_cfg,
1370 int32_t *valp)
1371{
1372 int32_t vref_mv;
1373 uint8_t resolution;
1374
1375 if (!spec->channel_cfg_dt_node_exists) {
1376 return -ENOTSUP;
1377 }
1378
1379 if (channel_cfg->reference == ADC_REF_INTERNAL) {
1380 vref_mv = (int32_t)adc_ref_internal(spec->dev);
1381 } else {
1382 vref_mv = spec->vref_mv;
1383 }
1384
1385 resolution = spec->resolution;
1386
1387 /*
1388 * For differential channels, one bit less needs to be specified
1389 * for resolution to achieve correct conversion.
1390 */
1391 if (channel_cfg->differential) {
1392 resolution -= 1U;
1393 }
1394
1395 return conv_func(vref_mv, channel_cfg->gain, resolution, valp);
1396}
1397
1398
1412static inline int adc_raw_to_millivolts_dt(const struct adc_dt_spec *spec, int32_t *valp)
1413{
1414 return adc_raw_to_x_dt_chan(adc_raw_to_millivolts, spec, &spec->channel_cfg, valp);
1415}
1416
1430static inline int adc_raw_to_microvolts_dt(const struct adc_dt_spec *spec, int32_t *valp)
1431{
1432 return adc_raw_to_x_dt_chan(adc_raw_to_microvolts, spec, &spec->channel_cfg, valp);
1433}
1434
1453static inline int adc_sequence_init_dt(const struct adc_dt_spec *spec,
1454 struct adc_sequence *seq)
1455{
1456 if (!spec->channel_cfg_dt_node_exists) {
1457 return -ENOTSUP;
1458 }
1459
1460 seq->channels = BIT(spec->channel_id);
1461 seq->resolution = spec->resolution;
1462 seq->oversampling = spec->oversampling;
1463
1464 return 0;
1465}
1466
1474static inline bool adc_is_ready_dt(const struct adc_dt_spec *spec)
1475{
1476 return device_is_ready(spec->dev);
1477}
1478
1482
1488#define ADC_DECODER_NAME() UTIL_CAT(DT_DRV_COMPAT, __adc_decoder_api)
1489
1497#define ADC_DECODER_DT_GET(node_id) \
1498 &UTIL_CAT(DT_STRING_TOKEN_BY_IDX(node_id, compatible, 0), __adc_decoder_api)
1499
1515#define ADC_DECODER_API_DT_DEFINE() \
1516 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), (), (static)) \
1517 const STRUCT_SECTION_ITERABLE(adc_decoder_api, ADC_DECODER_NAME())
1518
1519#define Z_MAYBE_ADC_DECODER_DECLARE_INTERNAL_IDX(node_id, prop, idx) \
1520 extern const struct adc_decoder_api UTIL_CAT( \
1521 DT_STRING_TOKEN_BY_IDX(node_id, prop, idx), __adc_decoder_api);
1522
1523#define Z_MAYBE_ADC_DECODER_DECLARE_INTERNAL(node_id) \
1524 COND_CODE_1(DT_NODE_HAS_PROP(node_id, compatible), \
1525 (DT_FOREACH_PROP_ELEM(node_id, compatible, \
1526 Z_MAYBE_ADC_DECODER_DECLARE_INTERNAL_IDX)), \
1527 ())
1528
1529DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_ADC_DECODER_DECLARE_INTERNAL)
1530
1531/* The default adc iodev API */
1532extern const struct rtio_iodev_api __adc_iodev_api;
1533
1553#define ADC_DT_STREAM_IODEV(name, dt_node, adc_dt_spec, ...) \
1554 static struct adc_stream_trigger _CONCAT(__trigger_array_, name)[] = {__VA_ARGS__}; \
1555 static struct adc_read_config _CONCAT(__adc_read_config_, name) = { \
1556 .adc = DEVICE_DT_GET(dt_node), \
1557 .is_streaming = true, \
1558 .adc_spec = adc_dt_spec, \
1559 .triggers = _CONCAT(__trigger_array_, name), \
1560 .adc_spec_cnt = ARRAY_SIZE(adc_dt_spec), \
1561 .trigger_cnt = ARRAY_SIZE(_CONCAT(__trigger_array_, name)), \
1562 }; \
1563 RTIO_IODEV_DEFINE(name, &__adc_iodev_api, &_CONCAT(__adc_read_config_, name))
1564
1565#ifdef __cplusplus
1566}
1567#endif
1568
1569#include <zephyr/syscalls/adc.h>
1570
1571#endif /* ZEPHYR_INCLUDE_DRIVERS_ADC_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1375
int adc_read_async(const struct device *dev, const struct adc_sequence *sequence, struct k_poll_signal *async)
Set an asynchronous read request.
static int adc_raw_to_millivolts_dt(const struct adc_dt_spec *spec, int32_t *valp)
Convert a raw ADC value to millivolts using information stored in a struct adc_dt_spec.
Definition adc.h:1412
int(* adc_api_get_decoder)(const struct device *dev, const struct adc_decoder_api **api)
Get the decoder associate with the given device.
Definition adc.h:994
static int adc_raw_to_x_dt_chan(adc_raw_to_x_fn conv_func, const struct adc_dt_spec *spec, const struct adc_channel_cfg *channel_cfg, int32_t *valp)
Convert a raw ADC value to an arbitrary output unit.
Definition adc.h:1367
static int adc_stream(struct rtio_iodev *iodev, struct rtio *ctx, void *userdata, struct rtio_sqe **handle)
Start a continuous ADC streaming session.
Definition adc.h:1230
int adc_gain_invert_64(enum adc_gain gain, int64_t *value)
Invert the application of gain to a measurement value.
static int adc_read_dt(const struct adc_dt_spec *spec, const struct adc_sequence *sequence)
Set a read request from a struct adc_dt_spec.
Definition adc.h:1103
adc_gain
ADC channel gain factors.
Definition adc.h:42
static bool adc_is_ready_dt(const struct adc_dt_spec *spec)
Validate that the ADC device is ready.
Definition adc.h:1474
int(* adc_raw_to_x_fn)(int32_t ref_mv, enum adc_gain gain, uint8_t resolution, int32_t *valp)
Conversion from raw ADC units to a specific output unit.
Definition adc.h:1307
adc_stream_data_opt
Options for what to do with the associated data when a trigger is consumed.
Definition adc.h:866
static int adc_raw_to_microvolts(int32_t ref_mv, enum adc_gain gain, uint8_t resolution, int32_t *valp)
Convert a raw ADC value to microvolts.
Definition adc.h:1338
static int adc_raw_to_microvolts_dt(const struct adc_dt_spec *spec, int32_t *valp)
Convert a raw ADC value to microvolts using information stored in a struct adc_dt_spec.
Definition adc.h:1430
int(* adc_api_read)(const struct device *dev, const struct adc_sequence *sequence)
Type definition of ADC API function for setting a read request.
Definition adc.h:980
static int adc_sequence_init_dt(const struct adc_dt_spec *spec, struct adc_sequence *seq)
Initialize a struct adc_sequence from information stored in struct adc_dt_spec.
Definition adc.h:1453
int adc_gain_invert(enum adc_gain gain, int32_t *value)
Invert the application of gain to a measurement value.
void(* adc_api_submit)(const struct device *dev, struct rtio_iodev_sqe *sqe)
Type definition of ADC API function for submitting a stream request.
Definition adc.h:986
int adc_read(const struct device *dev, const struct adc_sequence *sequence)
Set a read request.
adc_trigger_type
ADC trigger types.
Definition adc.h:836
int adc_channel_setup(const struct device *dev, const struct adc_channel_cfg *channel_cfg)
Configure an ADC channel.
int(* adc_api_channel_setup)(const struct device *dev, const struct adc_channel_cfg *channel_cfg)
Type definition of ADC API function for configuring a channel.
Definition adc.h:973
adc_action
Action to be performed after a sampling is done.
Definition adc.h:652
enum adc_action(* adc_sequence_callback)(const struct device *dev, const struct adc_sequence *sequence, uint16_t sampling_index)
Type definition of the optional callback function to be called after a requested sampling is done.
Definition adc.h:685
adc_reference
ADC references.
Definition adc.h:103
int(* adc_api_read_async)(const struct device *dev, const struct adc_sequence *sequence, struct k_poll_signal *async)
Type definition of ADC API function for setting an asynchronous read request.
Definition adc.h:1003
static uint16_t adc_ref_internal(const struct device *dev)
Get the internal reference voltage.
Definition adc.h:1279
static int adc_read_async_dt(const struct adc_dt_spec *spec, const struct adc_sequence *sequence, struct k_poll_signal *async)
Set an asynchronous read request from a struct adc_dt_spec.
Definition adc.h:1161
static int adc_channel_setup_dt(const struct adc_dt_spec *spec)
Configure an ADC channel from a struct adc_dt_spec.
Definition adc.h:1055
static int adc_raw_to_millivolts(int32_t ref_mv, enum adc_gain gain, uint8_t resolution, int32_t *valp)
Convert a raw ADC value to millivolts.
Definition adc.h:1315
int adc_get_decoder(const struct device *dev, const struct adc_decoder_api **api)
Get decoder APIs for that device.
@ ADC_GAIN_64
x 64.
Definition adc.h:62
@ ADC_GAIN_3
x 3.
Definition adc.h:54
@ ADC_GAIN_4
x 4.
Definition adc.h:55
@ ADC_GAIN_1_5
x 1/5.
Definition adc.h:44
@ ADC_GAIN_128
x 128.
Definition adc.h:63
@ ADC_GAIN_1_2
x 1/2.
Definition adc.h:49
@ ADC_GAIN_2_7
x 2/7.
Definition adc.h:46
@ ADC_GAIN_12
x 12.
Definition adc.h:58
@ ADC_GAIN_2_5
x 2/5.
Definition adc.h:48
@ ADC_GAIN_16
x 16.
Definition adc.h:59
@ ADC_GAIN_24
x 24.
Definition adc.h:60
@ ADC_GAIN_1
x 1.
Definition adc.h:52
@ ADC_GAIN_6
x 6.
Definition adc.h:56
@ ADC_GAIN_1_6
x 1/6.
Definition adc.h:43
@ ADC_GAIN_32
x 32.
Definition adc.h:61
@ ADC_GAIN_2_3
x 2/3.
Definition adc.h:50
@ ADC_GAIN_4_5
x 4/5.
Definition adc.h:51
@ ADC_GAIN_8
x 8.
Definition adc.h:57
@ ADC_GAIN_1_3
x 1/3.
Definition adc.h:47
@ ADC_GAIN_1_4
x 1/4.
Definition adc.h:45
@ ADC_GAIN_2
x 2.
Definition adc.h:53
@ ADC_STREAM_DATA_NOP
Do nothing with the associated trigger data, it may be consumed later.
Definition adc.h:870
@ ADC_STREAM_DATA_DROP
Flush/clear whatever data is associated with the trigger.
Definition adc.h:872
@ ADC_STREAM_DATA_INCLUDE
Include whatever data is associated with the trigger.
Definition adc.h:868
@ ADC_TRIG_PRIV_START
This and higher values are adc specific.
Definition adc.h:855
@ ADC_TRIG_DATA_READY
Trigger fires whenever new data is ready.
Definition adc.h:838
@ ADC_TRIG_FIFO_WATERMARK
Trigger fires when the FIFO watermark has been reached.
Definition adc.h:841
@ ADC_TRIG_MAX
Maximum value describing a adc trigger type.
Definition adc.h:860
@ ADC_TRIG_FIFO_FULL
Trigger fires when the FIFO becomes full.
Definition adc.h:844
@ ADC_TRIG_COMMON_COUNT
Number of all common adc triggers.
Definition adc.h:849
@ ADC_ACTION_FINISH
The sequence should be finished immediately.
Definition adc.h:663
@ ADC_ACTION_REPEAT
The sampling should be repeated.
Definition adc.h:660
@ ADC_ACTION_CONTINUE
The sequence should be continued normally.
Definition adc.h:654
@ ADC_REF_INTERNAL
Internal.
Definition adc.h:108
@ ADC_REF_EXTERNAL1
External, input 1.
Definition adc.h:110
@ ADC_REF_VDD_1_2
VDD/2.
Definition adc.h:105
@ ADC_REF_VDD_1_3
VDD/3.
Definition adc.h:106
@ ADC_REF_VDD_1_4
VDD/4.
Definition adc.h:107
@ ADC_REF_VDD_1
VDD.
Definition adc.h:104
@ ADC_REF_EXTERNAL0
External, input 0.
Definition adc.h:109
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
#define DT_FOREACH_STATUS_OKAY_NODE(fn)
Invokes fn for every status okay node in the tree.
Definition devicetree.h:3185
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:55
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 struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition rtio.h:327
static void rtio_sqe_prep_read_multishot(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Definition sqe.h:460
int rtio_submit(struct rtio *r, uint32_t wait_count)
Submit I/O requests to the underlying executor.
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:154
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOMEM
Not enough core.
Definition errno.h:50
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
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
__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
__INT16_TYPE__ int16_t
Definition stdint.h:73
ADC Channel Specification.
Definition adc.h:887
uint8_t chan_resolution
A ADC channel resolution.
Definition adc.h:889
uint8_t chan_idx
A ADC channel index.
Definition adc.h:888
Structure for specifying the configuration of an ADC channel.
Definition adc.h:116
enum adc_gain gain
Gain selection.
Definition adc.h:118
uint8_t differential
Channel type: single-ended or differential.
Definition adc.h:159
uint16_t acquisition_time
Acquisition time.
Definition adc.h:132
enum adc_reference reference
Reference selection.
Definition adc.h:121
uint8_t channel_id
Channel identifier.
Definition adc.h:156
Definition adc.h:825
q31_t value
Definition adc.h:828
uint32_t timestamp_delta
Definition adc.h:826
Generic header for encoded ADC streaming frames.
Definition adc.h:1189
uint8_t num_channels
Number of channels present in this frame.
Definition adc.h:1194
int8_t shift
Shift value for Q-format decoding of all samples in the frame.
Definition adc.h:1197
uint64_t timestamp_ns
Timestamp (in nanoseconds) at which the data was collected.
Definition adc.h:1191
struct adc_chan_spec channels[0]
Channel specifications for the channels present in the frame.
Definition adc.h:1203
Definition adc.h:805
uint64_t base_timestamp_ns
The closest timestamp for when the first frame was generated as attained by :c:func:k_uptime_ticks.
Definition adc.h:810
uint16_t reading_count
The number of elements in the 'readings' array.
Definition adc.h:816
Data for the adc channel.
Definition adc.h:822
int8_t shift
Definition adc.h:824
struct adc_data::adc_sample_data readings[1]
struct adc_data_header header
Definition adc.h:823
Decodes a single raw data buffer.
Definition adc.h:912
bool(* has_trigger)(const uint8_t *buffer, enum adc_trigger_type trigger)
Check if the given trigger type is present.
Definition adc.h:966
int(* get_frame_count)(const uint8_t *buffer, uint32_t channel, uint16_t *frame_count)
Get the number of frames in the current buffer.
Definition adc.h:922
int(* get_size_info)(struct adc_dt_spec adc_spec, uint32_t channel, size_t *base_size, size_t *frame_size)
Get the size required to decode a given channel.
Definition adc.h:938
int(* decode)(const uint8_t *buffer, uint32_t channel, uint32_t *fit, uint16_t max_count, void *data_out)
Decode up to max_count samples from the buffer.
Definition adc.h:956
ADC driver API.
Definition adc.h:1012
adc_api_read read
Definition adc.h:1014
uint16_t ref_internal
Definition adc.h:1022
adc_api_channel_setup channel_setup
Definition adc.h:1013
Container for ADC channel information specified in devicetree.
Definition adc.h:295
struct adc_channel_cfg channel_cfg
Configuration of the associated ADC channel specified in devicetree.
Definition adc.h:317
uint8_t channel_id
ADC channel identifier used by this io-channel.
Definition adc.h:303
uint16_t vref_mv
Voltage of the reference selected for the channel or 0 if this value is not provided in devicetree.
Definition adc.h:325
const struct device * dev
Pointer to the device structure for the ADC driver instance used by this io-channel.
Definition adc.h:300
uint8_t oversampling
Oversampling setting to be used for that channel.
Definition adc.h:339
bool channel_cfg_dt_node_exists
Flag indicating whether configuration of the associated ADC channel is provided as a child node of th...
Definition adc.h:310
uint8_t resolution
ADC resolution to be used for that channel.
Definition adc.h:332
Definition adc.h:896
const struct adc_dt_spec * adc_spec
Definition adc.h:899
uint16_t fifo_mode
Definition adc.h:903
uint16_t fifo_watermark_lvl
Definition adc.h:902
const struct device * adc
Definition adc.h:897
size_t trigger_cnt
Definition adc.h:905
struct adc_sequence * sequence
Definition adc.h:901
size_t adc_spec_cnt
Definition adc.h:904
const struct adc_stream_trigger * triggers
Definition adc.h:900
const bool is_streaming
Definition adc.h:898
Structure defining additional options for an ADC sampling sequence.
Definition adc.h:692
void * user_data
Pointer to user data.
Definition adc.h:714
uint16_t extra_samplings
Number of extra samplings to perform (the total number of samplings is 1 + extra_samplings).
Definition adc.h:720
adc_sequence_callback callback
Callback function to be called after each sampling is done.
Definition adc.h:708
uint32_t interval_us
Interval between consecutive samplings (in microseconds), 0 means sample as fast as possible,...
Definition adc.h:702
Structure defining an ADC sampling sequence.
Definition adc.h:726
uint8_t oversampling
Oversampling setting.
Definition adc.h:792
const struct adc_sequence_options * options
Pointer to a structure defining additional options for the sequence.
Definition adc.h:731
uint32_t priority
Channel priority for arbitration.
Definition adc.h:774
uint32_t channels
Bit-mask indicating the channels to be included in each sampling of this sequence.
Definition adc.h:740
void * buffer
Pointer to a buffer where the samples are to be written.
Definition adc.h:753
bool calibrate
Perform calibration before the reading is taken if requested.
Definition adc.h:802
size_t buffer_size
Specifies the actual size of the buffer pointed by the "buffer" field (in bytes).
Definition adc.h:761
uint8_t resolution
ADC resolution.
Definition adc.h:784
Definition adc.h:875
enum adc_stream_data_opt opt
Definition adc.h:877
enum adc_trigger_type trigger
Definition adc.h:876
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Definition kernel.h:6566
API that an RTIO IO device should implement.
Definition iodev.h:33
IO device submission queue entry.
Definition sqe.h:394
struct rtio_sqe sqe
Definition sqe.h:395
An IO device with a function table for submitting requests.
Definition iodev.h:48
A submission queue event.
Definition sqe.h:304
void * userdata
User provided data which is returned upon operation completion.
Definition sqe.h:322
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:313
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:71