2.1. adc
— Analog to digital convertion¶
Source code: src/drivers/adc.h, src/drivers/adc.c
Test code: tst/drivers/adc/main.c
- Version
- 7.0.0
Defines
-
ADC_REFERENCE_VCC
¶ Use VCC as reference for convertions.
Functions
-
int
adc_module_init
(void)¶ Initialize the ADC driver module. This function must be called before calling any other function in this module.
The module will only be initialized once even if this function is called multiple times.
- Return
- zero(0) or negative error code.
-
int
adc_init
(struct adc_driver_t *self_p, struct adc_device_t *dev_p, struct pin_device_t *pin_dev_p, int reference, long sampling_rate)¶ Initialize given driver object from given configuration.
- Return
- zero(0) or negative error code.
- Parameters
self_p
-Driver object to be initialized.
dev_p
-ADC device to use.
pin_dev_p
-Pin device to use.
reference
-Voltage reference. Only
ADC_REFERENCE_VCC
is supported.sampling_rate
-Sampling rate in Hz. The lowest allowed value is one and the highest value depends on the architechture. The sampling rate is not used in single sample convertions, ie. calls to
adc_async_convert()
andadc_convert()
with length one; or calls toadc_convert_isr()
.
-
int
adc_async_convert
(struct adc_driver_t *self_p, uint16_t *samples_p, size_t length)¶ Start an asynchronous convertion of analog signal to digital samples. Call
adc_async_wait()
to wait for the convertion to complete.- Return
- zero(0) or negative error code.
- Parameters
self_p
-Driver object.
samples_p
-Converted samples.
length
-Length of samples array.
-
int
adc_async_wait
(struct adc_driver_t *self_p)¶ Wait for an asynchronous convertion to complete.
- Return
- zero(0) or negative error code.
- Parameters
self_p
-Driver object.
-
int
adc_convert
(struct adc_driver_t *self_p, uint16_t *samples_p, size_t length)¶ Start a synchronous convertion of analog signal to digital samples. This is equivalent to
adc_async_convert()
+adc_async_wait()
, but in a single function call.- Return
- zero(0) or negative error code.
- Parameters
self_p
-Driver object.
samples_p
-Converted samples.
length
-Length of samples array.
-
int
adc_convert_isr
(struct adc_driver_t *self_p, uint16_t *sample_p)¶ Start a synchronous convertion of analog signal to digital samples from isr or with the system lock taken. This function will poll the ADC hardware until the sample has been coverted.
- Return
- zero(0) or negative error code.
- Parameters
self_p
-Driver object.
sample_p
-Converted sample.
Variables
-
struct adc_device_t
adc_device
[ADC_DEVICE_MAX]¶