Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
 4.2.99

Emulated ADC backend API. More...

Typedefs

typedef int(* adc_emul_value_func) (const struct device *dev, unsigned int chan, void *data, uint32_t *result)
 Type definition of the function which is used to obtain ADC mV input values.

Functions

int adc_emul_const_value_set (const struct device *dev, unsigned int chan, uint32_t value)
 Set constant mV value input for emulated ADC chan.
int adc_emul_const_raw_value_set (const struct device *dev, unsigned int chan, uint32_t raw_value)
 Set constant raw value input for emulated ADC chan.
int adc_emul_value_func_set (const struct device *dev, unsigned int chan, adc_emul_value_func func, void *data)
 Set function used to obtain voltage for input of emulated ADC chan.
int adc_emul_raw_value_func_set (const struct device *dev, unsigned int chan, adc_emul_value_func func, void *data)
 Set function used to obtain voltage for raw input value of emulated ADC chan.
int adc_emul_ref_voltage_set (const struct device *dev, enum adc_reference ref, uint16_t value)
 Set reference voltage.

Detailed Description

Emulated ADC backend API.

Behaviour of emulated ADC is application-defined. As-such, each application may

  • define a Device Tree overlay file to indicate the number of ADC controllers as well as the number of channels for each controller
  • set default reference voltages in Device Tree or using adc_emul_ref_voltage_set
  • asynchronously call adc_emul_const_value_set in order to set constant mV value on emulated ADC input
  • asynchronously call adc_emul_value_func_set in order to assign function which will be used to obtain voltage on emulated ADC input

An example of an appropriate Device Tree overlay file is in tests/drivers/adc/adc_api/boards/native_sim.overlay

An example of using emulated ADC backend API is in the file tests/drivers/adc/adc_emul/src/main.c

Typedef Documentation

◆ adc_emul_value_func

typedef int(* adc_emul_value_func) (const struct device *dev, unsigned int chan, void *data, uint32_t *result)

#include <zephyr/drivers/adc/adc_emul.h>

Type definition of the function which is used to obtain ADC mV input values.

Parameters
devPointer to the device structure for the driver instance
chanADC channel to sample
dataUser data which was passed on adc_emul_value_func_set
resultThe result value which will be set as input for ADC chan
Returns
0 on success
other as error code which ends ADC context

Function Documentation

◆ adc_emul_const_raw_value_set()

int adc_emul_const_raw_value_set ( const struct device * dev,
unsigned int chan,
uint32_t raw_value )

#include <zephyr/drivers/adc/adc_emul.h>

Set constant raw value input for emulated ADC chan.

Parameters
devThe emulated ADC device
chanThe channel of ADC which input is assigned
raw_valueNew raw value to assign to chan input
Returns
0 on success
-EINVAL if an invalid argument is provided

◆ adc_emul_const_value_set()

int adc_emul_const_value_set ( const struct device * dev,
unsigned int chan,
uint32_t value )

#include <zephyr/drivers/adc/adc_emul.h>

Set constant mV value input for emulated ADC chan.

Parameters
devThe emulated ADC device
chanThe channel of ADC which input is assigned
valueNew voltage in mV to assign to chan input
Returns
0 on success
-EINVAL if an invalid argument is provided

◆ adc_emul_raw_value_func_set()

int adc_emul_raw_value_func_set ( const struct device * dev,
unsigned int chan,
adc_emul_value_func func,
void * data )

#include <zephyr/drivers/adc/adc_emul.h>

Set function used to obtain voltage for raw input value of emulated ADC chan.

Parameters
devThe emulated ADC device
chanThe channel of ADC to which func is assigned
funcNew function to assign to chan
dataPointer to data passed to func on call
Returns
0 on success
-EINVAL if an invalid argument is provided

◆ adc_emul_ref_voltage_set()

int adc_emul_ref_voltage_set ( const struct device * dev,
enum adc_reference ref,
uint16_t value )

#include <zephyr/drivers/adc/adc_emul.h>

Set reference voltage.

Parameters
devThe emulated ADC device
refReference config which is changed
valueNew reference voltage in mV
Returns
0 on success
-EINVAL if an invalid argument is provided

◆ adc_emul_value_func_set()

int adc_emul_value_func_set ( const struct device * dev,
unsigned int chan,
adc_emul_value_func func,
void * data )

#include <zephyr/drivers/adc/adc_emul.h>

Set function used to obtain voltage for input of emulated ADC chan.

Parameters
devThe emulated ADC device
chanThe channel of ADC to which func is assigned
funcNew function to assign to chan
dataPointer to data passed to func on call
Returns
0 on success
-EINVAL if an invalid argument is provided