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

Interface for controlling ADC onboard MCU. More...

Go to the source code of this file.

Data Structures

struct  ri_adc_pin_config_t
 
struct  ri_adc_pins_config_t
 
struct  ri_adc_channel_config_t
 
struct  ri_adc_config_t
 
struct  ri_adc_get_data_t
 

Enumerations

enum  ri_adc_channel_t {
  RI_ADC_GND , RI_ADC_AIN0 , RI_ADC_AIN1 , RI_ADC_AIN2 ,
  RI_ADC_AIN3 , RI_ADC_AIN4 , RI_ADC_AIN5 , RI_ADC_AIN6 ,
  RI_ADC_AIN7 , RI_ADC_AINVDD , RI_ADC_CH_NUM
}
 Enable implementation selected by application. More...
 
enum  ri_adc_vref_t { RI_ADC_VREF_INTERNAL , RI_ADC_VREF_EXTERNAL }
 
enum  ri_adc_mode_t { RI_ADC_MODE_SINGLE }
 
enum  ri_adc_oversample_t {
  RI_ADC_OVERSAMPLE_DISABLED , RI_ADC_OVERSAMPLE_2X , RI_ADC_OVERSAMPLE_4X , RI_ADC_OVERSAMPLE_8X ,
  RI_ADC_OVERSAMPLE_16X , RI_ADC_OVERSAMPLE_32X , RI_ADC_OVERSAMPLE_64X , RI_ADC_OVERSAMPLE_128X ,
  RI_ADC_OVERSAMPLE_256X
}
 
enum  ri_adc_resolution_t { RI_ADC_RESOLUTION_8BIT , RI_ADC_RESOLUTION_10BIT , RI_ADC_RESOLUTION_12BIT , RI_ADC_RESOLUTION_14BIT }
 
enum  ri_adc_gain_t {
  RI_ADC_GAIN1_6 , RI_ADC_GAIN1_5 , RI_ADC_GAIN1_4 , RI_ADC_GAIN1_3 ,
  RI_ADC_GAIN1_2 , RI_ADC_GAIN1 , RI_ADC_GAIN2 , RI_ADC_GAIN4
}
 

Functions

bool ri_adc_is_init (void)
 Check if ADC is initialized. More...
 
rd_status_t ri_adc_init (ri_adc_config_t *p_config)
 Initialization of ADC. More...
 
rd_status_t ri_adc_uninit (bool config_default)
 Uninitialize ADC. More...
 
rd_status_t ri_adc_configure (uint8_t channel_num, ri_adc_pins_config_t *p_pins, ri_adc_channel_config_t *p_config)
 Configure ADC channel. More...
 
rd_status_t ri_adc_stop (uint8_t channel_num)
 Stop use ADC channel. More...
 
rd_status_t ri_adc_get_raw_data (uint8_t channel_num, int16_t *p_data)
 Get raw ADC data. More...
 
rd_status_t ri_adc_get_data_absolute (uint8_t channel_num, ri_adc_get_data_t *p_config, float *p_data)
 Get ADC data in volts. More...
 
rd_status_t ri_adc_get_data_ratio (uint8_t channel_num, ri_adc_get_data_t *p_config, float *p_data)
 Get ADC data in volts. More...
 
bool ri_adc_mcu_is_valid_ch (const uint8_t ch)
 Return true if given channel index can be used by underlying implementation. More...
 

Detailed Description

Interface for controlling ADC onboard MCU.

Author
Oleg Protasevich
Date
2019-06-03

Definition in file ruuvi_interface_adc_mcu.h.

Enumeration Type Documentation

◆ ri_adc_channel_t

Enable implementation selected by application.

Enumerator
RI_ADC_GND 

GND of device.

RI_ADC_AIN0 

Channel 0 of ADC.

RI_ADC_AIN1 

Channel 1 of ADC.

RI_ADC_AIN2 

Channel 2 of ADC.

RI_ADC_AIN3 

Channel 3 of ADC.

RI_ADC_AIN4 

Channel 4 of ADC.

RI_ADC_AIN5 

Channel 5 of ADC.

RI_ADC_AIN6 

Channel 6 of ADC.

RI_ADC_AIN7 

Channel 7 of ADC.

RI_ADC_AINVDD 

Analog supply voltage.

RI_ADC_CH_NUM 

Number of ADC inputs.

Definition at line 27 of file ruuvi_interface_adc_mcu.h.

◆ ri_adc_gain_t

Enumerator
RI_ADC_GAIN1_6 
RI_ADC_GAIN1_5 
RI_ADC_GAIN1_4 
RI_ADC_GAIN1_3 
RI_ADC_GAIN1_2 
RI_ADC_GAIN1 
RI_ADC_GAIN2 
RI_ADC_GAIN4 

Definition at line 104 of file ruuvi_interface_adc_mcu.h.

◆ ri_adc_mode_t

Enumerator
RI_ADC_MODE_SINGLE 

Single ended mode.

Definition at line 50 of file ruuvi_interface_adc_mcu.h.

◆ ri_adc_oversample_t

Enumerator
RI_ADC_OVERSAMPLE_DISABLED 
RI_ADC_OVERSAMPLE_2X 
RI_ADC_OVERSAMPLE_4X 
RI_ADC_OVERSAMPLE_8X 
RI_ADC_OVERSAMPLE_16X 
RI_ADC_OVERSAMPLE_32X 
RI_ADC_OVERSAMPLE_64X 
RI_ADC_OVERSAMPLE_128X 
RI_ADC_OVERSAMPLE_256X 

Definition at line 59 of file ruuvi_interface_adc_mcu.h.

◆ ri_adc_resolution_t

Enumerator
RI_ADC_RESOLUTION_8BIT 
RI_ADC_RESOLUTION_10BIT 
RI_ADC_RESOLUTION_12BIT 
RI_ADC_RESOLUTION_14BIT 

Definition at line 73 of file ruuvi_interface_adc_mcu.h.

◆ ri_adc_vref_t

Enumerator
RI_ADC_VREF_INTERNAL 

Internal voltage reference.

RI_ADC_VREF_EXTERNAL 

External voltage reference.

Definition at line 43 of file ruuvi_interface_adc_mcu.h.

Function Documentation

◆ ri_adc_configure()

rd_status_t ri_adc_configure ( uint8_t  channel_num,
ri_adc_pins_config_t p_pins,
ri_adc_channel_config_t p_config 
)

Configure ADC channel.

Parameters
[in]channel_numADC channel.
[in]p_pinsADC pin config.
[in]p_configADC channel config.
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_STATEif ADC channel is locked.
RD_ERROR_INVALID_PARAMif input channel incorrect.
Returns
RD_ERROR_NULL if either parameter is NULL.

◆ ri_adc_get_data_absolute()

rd_status_t ri_adc_get_data_absolute ( uint8_t  channel_num,
ri_adc_get_data_t p_config,
float *  p_data 
)

Get ADC data in volts.

Parameters
[in]channel_numADC channel.
[in]p_configADC output config.
[out]p_dataADC data in volts.
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_PARAMif input incorrect.
Returns
RD_ERROR_NULL if either parameter is NULL.

◆ ri_adc_get_data_ratio()

rd_status_t ri_adc_get_data_ratio ( uint8_t  channel_num,
ri_adc_get_data_t p_config,
float *  p_data 
)

Get ADC data in volts.

Parameters
[in]channel_numADC channel.
[in]p_configADC output config.
[out]p_dataADC data as a ratio to VDD.
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_PARAMif input incorrect.
Returns
RD_ERROR_NULL if either parameter is NULL.

◆ ri_adc_get_raw_data()

rd_status_t ri_adc_get_raw_data ( uint8_t  channel_num,
int16_t *  p_data 
)

Get raw ADC data.

Parameters
[in]channel_numADC channel.
[in,out]p_dataraw ADC data.
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_STATEif ADC channel is locked.

◆ ri_adc_init()

rd_status_t ri_adc_init ( ri_adc_config_t p_config)

Initialization of ADC.

Parameters
[in]p_configConfiguration of ADC.
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_STATEif ADC is already initialized or smth goes wrong.

◆ ri_adc_is_init()

bool ri_adc_is_init ( void  )

Check if ADC is initialized.

Return values
trueif ADC is initialized.
falseif ADC is not initialized.

◆ ri_adc_mcu_is_valid_ch()

bool ri_adc_mcu_is_valid_ch ( const uint8_t  ch)

Return true if given channel index can be used by underlying implementation.

Parameters
[in]chChannel to check.
Return values
trueChannel can be used (but might be reserved).
falseChannel is out of bounds.

◆ ri_adc_stop()

rd_status_t ri_adc_stop ( uint8_t  channel_num)

Stop use ADC channel.

Parameters
[in]channel_numADC channel
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_STATEif ADC channel is locked.
RD_ERROR_INVALID_PARAMif input channel incorrect.

◆ ri_adc_uninit()

rd_status_t ri_adc_uninit ( bool  config_default)

Uninitialize ADC.

Parameters
[in]config_defaultReset config to default.
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_STATEif ADC lock can't be released. Reboot.