ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_task_adc.h File Reference

Go to the source code of this file.

Enumerations

enum  rt_adc_mode_t { RATIOMETRIC , ABSOLUTE }
 

Functions

rd_status_t rt_adc_init (void)
 Reserve ADC. More...
 
rd_status_t rt_adc_uninit (void)
 Uninitialize ADC to release it for other users. More...
 
bool rt_adc_is_init (void)
 Check if ADC is initialized. More...
 
rd_status_t rt_adc_configure_se (rd_sensor_configuration_t *const config, const uint8_t handle, const rt_adc_mode_t mode)
 Configure ADC before sampling. More...
 
rd_status_t rt_adc_sample (void)
 Take a new sample on ADC configured in single-shot/sleep mode. More...
 
rd_status_t rt_adc_voltage_get (rd_sensor_data_t *const data)
 Populate data with latest sample. More...
 
rd_status_t rt_adc_ratio_get (rd_sensor_data_t *const data)
 Populate data with latest ratiometric value. More...
 
rd_status_t rt_adc_vdd_prepare (rd_sensor_configuration_t *const vdd_adc_configuration)
 Prepare for sampling VDD. More...
 
rd_status_t rt_adc_vdd_sample (void)
 Sample VDD. More...
 
rd_status_t rt_adc_vdd_get (float *const vdd)
 Get VDD. More...
 
rd_status_t rt_adc_absolute_sample (rd_sensor_configuration_t *const configuration, const uint8_t handle, float *const sample)
 Get absolute Voltage Sample from selected ADC handle. More...
 
rd_status_t rt_adc_ratiometric_sample (rd_sensor_configuration_t *const configuration, const uint8_t handle, float *const sample)
 Get ratiometric VDD Sample from selected ADC handle. More...
 

Detailed Description

Author
Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
Date
2019-20-27

Read ADC. Important: The ADC peripheral is shared by many different functions onboard, so always uninitialize the ADC after use to let others use the peripheral. Likewise important: The ADC might be in use while you need it, so always check the return code from init and do no block if you can't get ADC lock.

ADC lock must be atomic, and it requires the ri_atomic implementation.

Typical usage:

rd_sensor_configuration_t vdd_adc_configuration =
{
.dsp_function = APPLICATION_ADC_DSP_FUNC,
.dsp_parameter = APPLICATION_ADC_DSP_PARAM,
.mode = APPLICATION_ADC_MODE,
.resolution = APPLICATION_ADC_RESOLUTION,
.samplerate = APPLICATION_ADC_SAMPLERATE,
.scale = APPLICATION_ADC_SCALE
};
float battery_value;
err_code = rt_adc_init();
err_code |= rt_adc_configure_se(&vdd_adc_configuration, RI_ADC_AINVDD, ABSOLUTE);
err_code |= rt_adc_sample();
err_code |= rt_adc_voltage_get(&battery_value);
err_code = rt_adc_uninit();
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_CHECK(error, mask)
Shorthand macro for calling the rd_error_check with current file & line.
#define RD_SUCCESS
Internal Error.
rd_status_t rt_adc_configure_se(rd_sensor_configuration_t *const config, const uint8_t handle, const rt_adc_mode_t mode)
Configure ADC before sampling.
rd_status_t rt_adc_init(void)
Reserve ADC.
rd_status_t rt_adc_uninit(void)
Uninitialize ADC to release it for other users.
rd_status_t rt_adc_sample(void)
Take a new sample on ADC configured in single-shot/sleep mode.
rd_status_t rt_adc_voltage_get(rd_sensor_data_t *const data)
Populate data with latest sample.
@ ABSOLUTE
ADC measures absolute voltage in volts.
@ RI_ADC_AINVDD
Analog supply voltage.
All sensors must implement configuration functions which accept this struct.
uint8_t dsp_function
DSP function, one of RD_SENSOR_DSP_*.

Definition in file ruuvi_task_adc.h.