Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
adc.h File Reference

Main header file for ADC (Analog-to-Digital Converter) driver API. More...

#include <zephyr/device.h>
#include <zephyr/dt-bindings/adc/adc.h>
#include <zephyr/kernel.h>
#include <zephyr/rtio/rtio.h>
#include <zephyr/dsp/types.h>
#include <zephyr/syscalls/adc.h>

Go to the source code of this file.

Data Structures

struct  adc_channel_cfg
 Structure for specifying the configuration of an ADC channel. More...
struct  adc_dt_spec
 Container for ADC channel information specified in devicetree. More...
struct  adc_sequence_options
 Structure defining additional options for an ADC sampling sequence. More...
struct  adc_sequence
 Structure defining an ADC sampling sequence. More...
struct  adc_data_header
struct  adc_data
 Data for the adc channel. More...
struct  adc_data::adc_sample_data
struct  adc_stream_trigger
struct  adc_chan_spec
 ADC Channel Specification. More...
struct  adc_read_config
struct  adc_decoder_api
 Decodes a single raw data buffer. More...
struct  adc_driver_api
 @driver_ops{ADC} More...
struct  adc_data_generic_header
 Generic header for encoded ADC streaming frames. More...

Macros

#define ADC_CHANNEL_CFG_DT(node_id)
 Get ADC channel configuration from a given devicetree node.
#define ADC_DT_SPEC_GET_BY_NAME(node_id, name)
 Get ADC io-channel information from devicetree by name.
#define ADC_DT_SPEC_GET_BY_NAME_OR(node_id, name, default_value)
 Like ADC_DT_SPEC_GET_BY_NAME(), with a fallback to a default value.
#define ADC_DT_SPEC_INST_GET_BY_NAME(inst, name)
 Get ADC io-channel information from a DT_DRV_COMPAT devicetree instance by name.
#define ADC_DT_SPEC_INST_GET_BY_NAME_OR(inst, name, default_value)
 Like ADC_DT_SPEC_INST_GET_BY_NAME(), with a fallback to a default value.
#define ADC_DT_SPEC_GET_BY_IDX(node_id, idx)
 Get ADC io-channel information from devicetree.
#define ADC_DT_SPEC_GET_BY_IDX_OR(node_id, idx, default_value)
 Like ADC_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.
#define ADC_DT_SPEC_INST_GET_BY_IDX(inst, idx)
 Get ADC io-channel information from a DT_DRV_COMPAT devicetree instance.
#define ADC_DT_SPEC_INST_GET_BY_IDX_OR(inst, idx, default_value)
 Like ADC_DT_SPEC_INST_GET_BY_IDX(), with a fallback to a default value.
#define ADC_DT_SPEC_GET(node_id)
 Equivalent to ADC_DT_SPEC_GET_BY_IDX(node_id, 0).
#define ADC_DT_SPEC_GET_OR(node_id, default_value)
 Equivalent to ADC_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value).
#define ADC_DT_SPEC_INST_GET(inst)
 Equivalent to ADC_DT_SPEC_INST_GET_BY_IDX(inst, 0).
#define ADC_DT_SPEC_INST_GET_OR(inst, default_value)
 Equivalent to ADC_DT_SPEC_INST_GET_BY_IDX_OR(inst, 0, default).
#define ADC_DECODER_NAME()
 Get the decoder name for the current driver.
#define ADC_DECODER_DT_GET(node_id)
 Statically get the decoder for a given node.
#define ADC_DECODER_API_DT_DEFINE()
 Define a decoder API.
#define ADC_DT_STREAM_IODEV(name, dt_node, adc_dt_spec, ...)
 Define an RTIO IO device for ADC streaming.

Typedefs

typedef 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.
typedef 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.
typedef int(* adc_api_channel_setup) (const struct device *dev, const struct adc_channel_cfg *channel_cfg)
 @def_driverbackendgroup{ADC,adc_interface}
typedef int(* adc_api_read) (const struct device *dev, const struct adc_sequence *sequence)
 Type definition of ADC API function for setting a read request.
typedef void(* adc_api_submit) (const struct device *dev, struct rtio_iodev_sqe *sqe)
 Type definition of ADC API function for submitting a stream request.
typedef int(* adc_api_get_decoder) (const struct device *dev, const struct adc_decoder_api **api)
 Get the decoder associate with the given device.
typedef 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.

Enumerations

enum  adc_gain {
  ADC_GAIN_1_6 , ADC_GAIN_1_5 , ADC_GAIN_1_4 , ADC_GAIN_2_7 ,
  ADC_GAIN_1_3 , ADC_GAIN_2_5 , ADC_GAIN_1_2 , ADC_GAIN_2_3 ,
  ADC_GAIN_4_5 , ADC_GAIN_1 , ADC_GAIN_2 , ADC_GAIN_3 ,
  ADC_GAIN_4 , ADC_GAIN_6 , ADC_GAIN_8 , ADC_GAIN_12 ,
  ADC_GAIN_16 , ADC_GAIN_24 , ADC_GAIN_32 , ADC_GAIN_64 ,
  ADC_GAIN_128
}
 ADC channel gain factors. More...
enum  adc_reference {
  ADC_REF_VDD_1 , ADC_REF_VDD_1_2 , ADC_REF_VDD_1_3 , ADC_REF_VDD_1_4 ,
  ADC_REF_INTERNAL , ADC_REF_EXTERNAL0 , ADC_REF_EXTERNAL1
}
 ADC references. More...
enum  adc_action { ADC_ACTION_CONTINUE = 0 , ADC_ACTION_REPEAT , ADC_ACTION_FINISH }
 Action to be performed after a sampling is done. More...
enum  adc_trigger_type {
  ADC_TRIG_DATA_READY , ADC_TRIG_FIFO_WATERMARK , ADC_TRIG_FIFO_FULL , ADC_TRIG_COMMON_COUNT ,
  ADC_TRIG_PRIV_START = ADC_TRIG_COMMON_COUNT , ADC_TRIG_MAX = INT16_MAX
}
 ADC trigger types. More...
enum  adc_stream_data_opt { ADC_STREAM_DATA_INCLUDE = 0 , ADC_STREAM_DATA_NOP = 1 , ADC_STREAM_DATA_DROP = 2 }
 Options for what to do with the associated data when a trigger is consumed. More...

Functions

int adc_gain_invert (enum adc_gain gain, int32_t *value)
 Invert the application of gain to a measurement value.
int adc_gain_invert_64 (enum adc_gain gain, int64_t *value)
 Invert the application of gain to a measurement value.
int adc_channel_setup (const struct device *dev, const struct adc_channel_cfg *channel_cfg)
 Configure an ADC channel.
static int adc_channel_setup_dt (const struct adc_dt_spec *spec)
 Configure an ADC channel from a struct adc_dt_spec.
int adc_read (const struct device *dev, const struct adc_sequence *sequence)
 Set a read request.
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.
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_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.
int adc_get_decoder (const struct device *dev, const struct adc_decoder_api **api)
 Get decoder APIs for that device.
static int adc_stream (struct rtio_iodev *iodev, struct rtio *ctx, void *userdata, struct rtio_sqe **handle)
 Start a continuous ADC streaming session.
static uint16_t adc_ref_internal (const struct device *dev)
 Get the internal reference voltage.
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.
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.
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.
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.
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.
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.
static bool adc_is_ready_dt (const struct adc_dt_spec *spec)
 Validate that the ADC device is ready.
 DT_FOREACH_STATUS_OKAY_NODE (Z_MAYBE_ADC_DECODER_DECLARE_INTERNAL) extern const struct rtio_iodev_api __adc_iodev_api

Detailed Description

Main header file for ADC (Analog-to-Digital Converter) driver API.