Zephyr API Documentation  3.7.0-rc3
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ADC driver APIs

ADC driver APIs. More...

Modules

 Emulated ADC
 Emulated ADC backend API.
 

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_driver_api
 ADC driver API. 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_INST_GET_BY_NAME(inst, name)    ADC_DT_SPEC_GET_BY_NAME(DT_DRV_INST(inst), name)
 Get ADC io-channel information from a DT_DRV_COMPAT devicetree instance by name.
 
#define ADC_DT_SPEC_GET_BY_IDX(node_id, idx)
 Get ADC io-channel information from devicetree.
 
#define ADC_DT_SPEC_INST_GET_BY_IDX(inst, idx)    ADC_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)
 Get ADC io-channel information from a DT_DRV_COMPAT devicetree instance.
 
#define ADC_DT_SPEC_GET(node_id)   ADC_DT_SPEC_GET_BY_IDX(node_id, 0)
 Equivalent to ADC_DT_SPEC_GET_BY_IDX(node_id, 0).
 
#define ADC_DT_SPEC_INST_GET(inst)   ADC_DT_SPEC_GET(DT_DRV_INST(inst))
 Equivalent to ADC_DT_SPEC_INST_GET_BY_IDX(inst, 0).
 

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_api_channel_setup) (const struct device *dev, const struct adc_channel_cfg *channel_cfg)
 Type definition of ADC API function for configuring a channel.
 
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 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_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...
 

Functions

int adc_gain_invert (enum adc_gain gain, int32_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 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_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_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.
 

Detailed Description

ADC driver APIs.

Since
1.0
Version
1.0.0

Macro Definition Documentation

◆ ADC_CHANNEL_CFG_DT

#define ADC_CHANNEL_CFG_DT (   node_id)

#include <zephyr/drivers/adc.h>

Value:
{ \
.gain = DT_STRING_TOKEN(node_id, zephyr_gain), \
.reference = DT_STRING_TOKEN(node_id, zephyr_reference), \
.acquisition_time = DT_PROP(node_id, zephyr_acquisition_time), \
.channel_id = DT_REG_ADDR(node_id), \
IF_ENABLED(UTIL_OR(DT_PROP(node_id, zephyr_differential), \
UTIL_AND(CONFIG_ADC_CONFIGURABLE_INPUTS, \
DT_NODE_HAS_PROP(node_id, zephyr_input_negative))), \
(.differential = true,)) \
IF_ENABLED(CONFIG_ADC_CONFIGURABLE_INPUTS, \
(.input_positive = DT_PROP_OR(node_id, zephyr_input_positive, 0), \
.input_negative = DT_PROP_OR(node_id, zephyr_input_negative, 0),)) \
IF_ENABLED(CONFIG_ADC_CONFIGURABLE_EXCITATION_CURRENT_SOURCE_PIN, \
(.current_source_pin_set = DT_NODE_HAS_PROP(node_id, zephyr_current_source_pin), \
.current_source_pin = DT_PROP_OR(node_id, zephyr_current_source_pin, {0}),)) \
IF_ENABLED(CONFIG_ADC_CONFIGURABLE_VBIAS_PIN, \
(.vbias_pins = DT_PROP_OR(node_id, zephyr_vbias_pins, 0),)) \
}
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition: devicetree.h:3479
#define DT_STRING_TOKEN(node_id, prop)
Get a string property's value as a token.
Definition: devicetree.h:959
#define DT_PROP_OR(node_id, prop, default_value)
Like DT_PROP(), but with a fallback to default_value.
Definition: devicetree.h:825
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition: devicetree.h:663
#define DT_REG_ADDR(node_id)
Get a node's (only) register block address.
Definition: devicetree.h:2276
#define UTIL_AND(a, b)
Like a && b, but does evaluation and short-circuiting at C preprocessor time.
Definition: util_macro.h:391
#define UTIL_OR(a, b)
Like a || b, but does evaluation and short-circuiting at C preprocessor time.
Definition: util_macro.h:378

Get ADC channel configuration from a given devicetree node.

This returns a static initializer for a struct adc_channel_cfg filled with data from a given devicetree node.

Example devicetree fragment:

&adc {
#address-cells = <1>;
#size-cells = <0>;
channel@0 {
reg = <0>;
zephyr,gain = "ADC_GAIN_1_6";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 20)>;
zephyr,input-positive = <NRF_SAADC_AIN6>;
zephyr,input-negative = <NRF_SAADC_AIN7>;
};
channel@1 {
reg = <1>;
zephyr,gain = "ADC_GAIN_1_6";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN0>;
};
};

Example usage:

static const struct adc_channel_cfg ch0_cfg_dt =
static const struct adc_channel_cfg ch1_cfg_dt =
// Initializes 'ch0_cfg_dt' to:
// {
// .channel_id = 0,
// .gain = ADC_GAIN_1_6,
// .reference = ADC_REF_INTERNAL,
// .acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 20),
// .differential = true,
// .input_positive = NRF_SAADC_AIN6,
// .input-negative = NRF_SAADC_AIN7,
// }
// and 'ch1_cfg_dt' to:
// {
// .channel_id = 1,
// .gain = ADC_GAIN_1_6,
// .reference = ADC_REF_INTERNAL,
// .acquisition_time = ADC_ACQ_TIME_DEFAULT,
// .input_positive = NRF_SAADC_AIN0,
// }
#define ADC_CHANNEL_CFG_DT(node_id)
Get ADC channel configuration from a given devicetree node.
Definition: adc.h:239
#define DT_CHILD(node_id, child)
Get a node identifier for a child node.
Definition: devicetree.h:423
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition: devicetree.h:200
Structure for specifying the configuration of an ADC channel.
Definition: adc.h:90
Parameters
node_idDevicetree node identifier.
Returns
Static initializer for an adc_channel_cfg structure.

◆ ADC_DT_SPEC_GET

#define ADC_DT_SPEC_GET (   node_id)    ADC_DT_SPEC_GET_BY_IDX(node_id, 0)

#include <zephyr/drivers/adc.h>

Equivalent to ADC_DT_SPEC_GET_BY_IDX(node_id, 0).

See also
ADC_DT_SPEC_GET_BY_IDX()
Parameters
node_idDevicetree node identifier.
Returns
Static initializer for an adc_dt_spec structure.

◆ ADC_DT_SPEC_GET_BY_IDX

#define ADC_DT_SPEC_GET_BY_IDX (   node_id,
  idx 
)

#include <zephyr/drivers/adc.h>

Value:
ADC_DT_SPEC_STRUCT(DT_IO_CHANNELS_CTLR_BY_IDX(node_id, idx), \
#define DT_IO_CHANNELS_INPUT_BY_IDX(node_id, idx)
Get an io-channels specifier input cell at an index.
Definition: io-channels.h:161
#define DT_IO_CHANNELS_CTLR_BY_IDX(node_id, idx)
Get the node identifier for the node referenced by an io-channels property at an index.
Definition: io-channels.h:50

Get ADC io-channel information from devicetree.

This returns a static initializer for an adc_dt_spec structure given a devicetree node and a channel index. The node must have the "io-channels" property defined.

Example devicetree fragment:

/ {
zephyr,user {
io-channels = <&adc0 1>, <&adc0 3>;
};
};
&adc0 {
#address-cells = <1>;
#size-cells = <0>;
channel@3 {
reg = <3>;
zephyr,gain = "ADC_GAIN_1_5";
zephyr,reference = "ADC_REF_VDD_1_4";
zephyr,vref-mv = <750>;
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,resolution = <12>;
zephyr,oversampling = <4>;
};
};

Example usage:

static const struct adc_dt_spec adc_chan0 =
ADC_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), 0);
static const struct adc_dt_spec adc_chan1 =
ADC_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), 1);
// Initializes 'adc_chan0' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(adc0)),
// .channel_id = 1,
// }
// and 'adc_chan1' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(adc0)),
// .channel_id = 3,
// .channel_cfg_dt_node_exists = true,
// .channel_cfg = {
// .channel_id = 3,
// .gain = ADC_GAIN_1_5,
// .reference = ADC_REF_VDD_1_4,
// .acquisition_time = ADC_ACQ_TIME_DEFAULT,
// },
// .vref_mv = 750,
// .resolution = 12,
// .oversampling = 4,
// }
#define ADC_DT_SPEC_GET_BY_IDX(node_id, idx)
Get ADC io-channel information from devicetree.
Definition: adc.h:490
#define DT_PATH(...)
Get a node identifier for a devicetree path.
Definition: devicetree.h:144
Container for ADC channel information specified in devicetree.
Definition: adc.h:264
See also
ADC_DT_SPEC_GET()
Parameters
node_idDevicetree node identifier.
idxChannel index.
Returns
Static initializer for an adc_dt_spec structure.

◆ ADC_DT_SPEC_GET_BY_NAME

#define ADC_DT_SPEC_GET_BY_NAME (   node_id,
  name 
)

#include <zephyr/drivers/adc.h>

Value:
ADC_DT_SPEC_STRUCT(DT_IO_CHANNELS_CTLR_BY_NAME(node_id, name), \
#define DT_IO_CHANNELS_CTLR_BY_NAME(node_id, name)
Get the node identifier for the node referenced by an io-channels property by name.
Definition: io-channels.h:79
#define DT_IO_CHANNELS_INPUT_BY_NAME(node_id, name)
Get an io-channels specifier input cell by name.
Definition: io-channels.h:203

Get ADC io-channel information from devicetree by name.

This returns a static initializer for an adc_dt_spec structure given a devicetree node and a channel name. The node must have the "io-channels" property defined.

Example devicetree fragment:

/ {
zephyr,user {
io-channels = <&adc0 1>, <&adc0 3>;
io-channel-names = "A0", "A1";
};
};
&adc0 {
#address-cells = <1>;
#size-cells = <0>;
channel@3 {
reg = <3>;
zephyr,gain = "ADC_GAIN_1_5";
zephyr,reference = "ADC_REF_VDD_1_4";
zephyr,vref-mv = <750>;
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,resolution = <12>;
zephyr,oversampling = <4>;
};
};

Example usage:

static const struct adc_dt_spec adc_chan0 =
ADC_DT_SPEC_GET_BY_NAME(DT_PATH(zephyr_user), a0);
static const struct adc_dt_spec adc_chan1 =
ADC_DT_SPEC_GET_BY_NAME(DT_PATH(zephyr_user), a1);
// Initializes 'adc_chan0' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(adc0)),
// .channel_id = 1,
// }
// and 'adc_chan1' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(adc0)),
// .channel_id = 3,
// .channel_cfg_dt_node_exists = true,
// .channel_cfg = {
// .channel_id = 3,
// .gain = ADC_GAIN_1_5,
// .reference = ADC_REF_VDD_1_4,
// .acquisition_time = ADC_ACQ_TIME_DEFAULT,
// },
// .vref_mv = 750,
// .resolution = 12,
// .oversampling = 4,
// }
#define ADC_DT_SPEC_GET_BY_NAME(node_id, name)
Get ADC io-channel information from devicetree by name.
Definition: adc.h:404
Parameters
node_idDevicetree node identifier.
nameChannel name.
Returns
Static initializer for an adc_dt_spec structure.

◆ ADC_DT_SPEC_INST_GET

#define ADC_DT_SPEC_INST_GET (   inst)    ADC_DT_SPEC_GET(DT_DRV_INST(inst))

#include <zephyr/drivers/adc.h>

Equivalent to ADC_DT_SPEC_INST_GET_BY_IDX(inst, 0).

See also
ADC_DT_SPEC_GET()
Parameters
instDT_DRV_COMPAT instance number
Returns
Static initializer for an adc_dt_spec structure.

◆ ADC_DT_SPEC_INST_GET_BY_IDX

#define ADC_DT_SPEC_INST_GET_BY_IDX (   inst,
  idx 
)     ADC_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)

#include <zephyr/drivers/adc.h>

Get ADC io-channel information from a DT_DRV_COMPAT devicetree instance.

See also
ADC_DT_SPEC_GET_BY_IDX()
Parameters
instDT_DRV_COMPAT instance number
idxChannel index.
Returns
Static initializer for an adc_dt_spec structure.

◆ ADC_DT_SPEC_INST_GET_BY_NAME

#define ADC_DT_SPEC_INST_GET_BY_NAME (   inst,
  name 
)     ADC_DT_SPEC_GET_BY_NAME(DT_DRV_INST(inst), name)

#include <zephyr/drivers/adc.h>

Get ADC io-channel information from a DT_DRV_COMPAT devicetree instance by name.

See also
ADC_DT_SPEC_GET_BY_NAME()
Parameters
instDT_DRV_COMPAT instance number
nameChannel name.
Returns
Static initializer for an adc_dt_spec structure.

Typedef Documentation

◆ adc_api_channel_setup

typedef int(* adc_api_channel_setup) (const struct device *dev, const struct adc_channel_cfg *channel_cfg)

#include <zephyr/drivers/adc.h>

Type definition of ADC API function for configuring a channel.

See adc_channel_setup() for argument descriptions.

◆ adc_api_read

typedef int(* adc_api_read) (const struct device *dev, const struct adc_sequence *sequence)

#include <zephyr/drivers/adc.h>

Type definition of ADC API function for setting a read request.

See adc_read() for argument descriptions.

◆ adc_api_read_async

typedef int(* adc_api_read_async) (const struct device *dev, const struct adc_sequence *sequence, struct k_poll_signal *async)

#include <zephyr/drivers/adc.h>

Type definition of ADC API function for setting an asynchronous read request.

See adc_read_async() for argument descriptions.

◆ adc_sequence_callback

typedef enum adc_action(* adc_sequence_callback) (const struct device *dev, const struct adc_sequence *sequence, uint16_t sampling_index)

#include <zephyr/drivers/adc.h>

Type definition of the optional callback function to be called after a requested sampling is done.

Parameters
devPointer to the device structure for the driver instance.
sequencePointer to the sequence structure that triggered the sampling. This parameter points to a copy of the structure that was supplied to the call that started the sampling sequence, thus it cannot be used with the CONTAINER_OF() macro to retrieve some other data associated with the sequence. Instead, the adc_sequence_options::user_data field should be used for such purpose.
sampling_indexIndex (0-65535) of the sampling done.
Returns
Action to be performed by the driver. See adc_action.

Enumeration Type Documentation

◆ adc_action

enum adc_action

#include <zephyr/drivers/adc.h>

Action to be performed after a sampling is done.

Enumerator
ADC_ACTION_CONTINUE 

The sequence should be continued normally.

ADC_ACTION_REPEAT 

The sampling should be repeated.

New samples or sample should be read from the ADC and written in the same place as the recent ones.

ADC_ACTION_FINISH 

The sequence should be finished immediately.

◆ adc_gain

enum adc_gain

#include <zephyr/drivers/adc.h>

ADC channel gain factors.

Enumerator
ADC_GAIN_1_6 

x 1/6.

ADC_GAIN_1_5 

x 1/5.

ADC_GAIN_1_4 

x 1/4.

ADC_GAIN_1_3 

x 1/3.

ADC_GAIN_2_5 

x 2/5.

ADC_GAIN_1_2 

x 1/2.

ADC_GAIN_2_3 

x 2/3.

ADC_GAIN_4_5 

x 4/5.

ADC_GAIN_1 

x 1.

ADC_GAIN_2 

x 2.

ADC_GAIN_3 

x 3.

ADC_GAIN_4 

x 4.

ADC_GAIN_6 

x 6.

ADC_GAIN_8 

x 8.

ADC_GAIN_12 

x 12.

ADC_GAIN_16 

x 16.

ADC_GAIN_24 

x 24.

ADC_GAIN_32 

x 32.

ADC_GAIN_64 

x 64.

ADC_GAIN_128 

x 128.

◆ adc_reference

#include <zephyr/drivers/adc.h>

ADC references.

Enumerator
ADC_REF_VDD_1 

VDD.

ADC_REF_VDD_1_2 

VDD/2.

ADC_REF_VDD_1_3 

VDD/3.

ADC_REF_VDD_1_4 

VDD/4.

ADC_REF_INTERNAL 

Internal.

ADC_REF_EXTERNAL0 

External, input 0.

ADC_REF_EXTERNAL1 

External, input 1.

Function Documentation

◆ adc_channel_setup()

int adc_channel_setup ( const struct device dev,
const struct adc_channel_cfg channel_cfg 
)

#include <zephyr/drivers/adc.h>

Configure an ADC channel.

It is required to call this function and configure each channel before it is selected for a read request.

Parameters
devPointer to the device structure for the driver instance.
channel_cfgChannel configuration.
Return values
0On success.
-EINVALIf a parameter with an invalid value has been provided.

◆ adc_channel_setup_dt()

static int adc_channel_setup_dt ( const struct adc_dt_spec spec)
inlinestatic

#include <zephyr/drivers/adc.h>

Configure an ADC channel from a struct adc_dt_spec.

Parameters
specADC specification from Devicetree.
Returns
A value from adc_channel_setup() or -ENOTSUP if information from Devicetree is not valid.
See also
adc_channel_setup()

◆ adc_gain_invert()

int adc_gain_invert ( enum adc_gain  gain,
int32_t value 
)

#include <zephyr/drivers/adc.h>

Invert the application of gain to a measurement value.

For example, if the gain passed in is ADC_GAIN_1_6 and the referenced value is 10, the value after the function returns is 60.

Parameters
gainthe gain used to amplify the input signal.
valuea pointer to a value that initially has the effect of the applied gain but has that effect removed when this function successfully returns. If the gain cannot be reversed the value remains unchanged.
Return values
0if the gain was successfully reversed
-EINVALif the gain could not be interpreted

◆ adc_is_ready_dt()

static bool adc_is_ready_dt ( const struct adc_dt_spec spec)
inlinestatic

#include <zephyr/drivers/adc.h>

Validate that the ADC device is ready.

Parameters
specADC specification from devicetree
Return values
trueif the ADC device is ready for use and false otherwise.

◆ adc_raw_to_millivolts()

static int adc_raw_to_millivolts ( int32_t  ref_mv,
enum adc_gain  gain,
uint8_t  resolution,
int32_t valp 
)
inlinestatic

#include <zephyr/drivers/adc.h>

Convert a raw ADC value to millivolts.

This function performs the necessary conversion to transform a raw ADC measurement to a voltage in millivolts.

Parameters
ref_mvthe reference voltage used for the measurement, in millivolts. This may be from adc_ref_internal() or a known external reference.
gainthe ADC gain configuration used to sample the input
resolutionthe number of bits in the absolute value of the sample. For differential sampling this needs to be one less than the resolution in struct adc_sequence.
valppointer to the raw measurement value on input, and the corresponding millivolt value on successful conversion. If conversion fails the stored value is left unchanged.
Return values
0on successful conversion
-EINVALif the gain is not reversible

◆ adc_raw_to_millivolts_dt()

static int adc_raw_to_millivolts_dt ( const struct adc_dt_spec spec,
int32_t valp 
)
inlinestatic

#include <zephyr/drivers/adc.h>

Convert a raw ADC value to millivolts using information stored in a struct adc_dt_spec.

Parameters
[in]specADC specification from Devicetree.
[in,out]valpPointer to the raw measurement value on input, and the corresponding millivolt value on successful conversion. If conversion fails the stored value is left unchanged.
Returns
A value from adc_raw_to_millivolts() or -ENOTSUP if information from Devicetree is not valid.
See also
adc_raw_to_millivolts()

◆ adc_read()

int adc_read ( const struct device dev,
const struct adc_sequence sequence 
)

#include <zephyr/drivers/adc.h>

Set a read request.

Parameters
devPointer to the device structure for the driver instance.
sequenceStructure specifying requested sequence of samplings.

If invoked from user mode, any sequence struct options for callback must be NULL.

Return values
0On success.
-EINVALIf a parameter with an invalid value has been provided.
-ENOMEMIf the provided buffer is to small to hold the results of all requested samplings.
-ENOTSUPIf the requested mode of operation is not supported.
-EBUSYIf another sampling was triggered while the previous one was still in progress. This may occur only when samplings are done with intervals, and it indicates that the selected interval was too small. All requested samples are written in the buffer, but at least some of them were taken with an extra delay compared to what was scheduled.

◆ adc_read_async()

int adc_read_async ( const struct device dev,
const struct adc_sequence sequence,
struct k_poll_signal async 
)

#include <zephyr/drivers/adc.h>

Set an asynchronous read request.

Note
This function is available only if CONFIG_ADC_ASYNC is selected.

If invoked from user mode, any sequence struct options for callback must be NULL.

Parameters
devPointer to the device structure for the driver instance.
sequenceStructure specifying requested sequence of samplings.
asyncPointer to a valid and ready to be signaled struct k_poll_signal. (Note: if NULL this function will not notify the end of the transaction, and whether it went successfully or not).
Returns
0 on success, negative error code otherwise. See adc_read() for a list of possible error codes.

◆ adc_read_dt()

static int adc_read_dt ( const struct adc_dt_spec spec,
const struct adc_sequence sequence 
)
inlinestatic

#include <zephyr/drivers/adc.h>

Set a read request from a struct adc_dt_spec.

Parameters
specADC specification from Devicetree.
sequenceStructure specifying requested sequence of samplings.
Returns
A value from adc_read().
See also
adc_read()

◆ adc_ref_internal()

static uint16_t adc_ref_internal ( const struct device dev)
inlinestatic

#include <zephyr/drivers/adc.h>

Get the internal reference voltage.

Returns the voltage corresponding to ADC_REF_INTERNAL, measured in millivolts.

Returns
a positive value is the reference voltage value. Returns zero if reference voltage information is not available.

◆ adc_sequence_init_dt()

static int adc_sequence_init_dt ( const struct adc_dt_spec spec,
struct adc_sequence seq 
)
inlinestatic

#include <zephyr/drivers/adc.h>

Initialize a struct adc_sequence from information stored in struct adc_dt_spec.

Note that this function only initializes the following fields:

Other fields should be initialized by the caller.

Parameters
[in]specADC specification from Devicetree.
[out]seqSequence to initialize.
Return values
0On success
-ENOTSUPIf spec does not have valid channel configuration