Firmware SDK
twr_adc

Driver for ADC (analog to digital converter) More...

Enumerations

enum  twr_adc_channel_t {
  TWR_ADC_CHANNEL_A0 = 0,
  TWR_ADC_CHANNEL_A1 = 1,
  TWR_ADC_CHANNEL_A2 = 2,
  TWR_ADC_CHANNEL_A3 = 3,
  TWR_ADC_CHANNEL_A4 = 4,
  TWR_ADC_CHANNEL_A5 = 5,
  TWR_ADC_CHANNEL_A6 = 6
}
 ADC channel. More...
 
enum  twr_adc_oversampling_t {
  TWR_ADC_OVERSAMPLING_NONE = 0,
  TWR_ADC_OVERSAMPLING_2 = 1,
  TWR_ADC_OVERSAMPLING_4 = 2,
  TWR_ADC_OVERSAMPLING_8 = 3,
  TWR_ADC_OVERSAMPLING_16 = 4,
  TWR_ADC_OVERSAMPLING_32 = 5,
  TWR_ADC_OVERSAMPLING_64 = 6,
  TWR_ADC_OVERSAMPLING_128 = 7,
  TWR_ADC_OVERSAMPLING_256 = 8
}
 ADC oversampling. More...
 
enum  twr_adc_resolution_t {
  TWR_ADC_RESOLUTION_12_BIT = 0,
  TWR_ADC_RESOLUTION_10_BIT = ADC_CFGR1_RES_0,
  TWR_ADC_RESOLUTION_8_BIT = ADC_CFGR1_RES_1,
  TWR_ADC_RESOLUTION_6_BIT = ADC_CFGR1_RES_1 | ADC_CFGR1_RES_0
}
 ADC resolution. More...
 
enum  twr_adc_event_t { TWR_ADC_EVENT_DONE }
 ADC event. More...
 

Functions

void twr_adc_init ()
 Initialize ADC converter.
 
bool twr_adc_is_ready ()
 Check if ADC is ready for reading. More...
 
bool twr_adc_get_value (twr_adc_channel_t channel, uint16_t *result)
 Reads the ADC channel value. More...
 
bool twr_adc_set_event_handler (twr_adc_channel_t channel, void(*event_handler)(twr_adc_channel_t, twr_adc_event_t, void *), void *event_param)
 Set callback function. More...
 
bool twr_adc_async_measure (twr_adc_channel_t channel)
 Begins reading the ADC channel voltage in asynchronous mode. More...
 
bool twr_adc_async_get_value (twr_adc_channel_t channel, uint16_t *result)
 Get asynchronous measurement result. More...
 
bool twr_adc_async_get_voltage (twr_adc_channel_t channel, float *result)
 Get asynchronous measurement result in volts. More...
 
bool twr_adc_get_vdda_voltage (float *vdda_voltage)
 Get voltage on VDDA pin. More...
 
bool twr_adc_calibration (void)
 Calibration. More...
 
void twr_adc_resolution_set (twr_adc_channel_t channel, twr_adc_resolution_t resolution)
 Set ADC resolution for specific channel. More...
 
void twr_adc_oversampling_set (twr_adc_channel_t channel, twr_adc_oversampling_t oversampling)
 Set ADC oversampling for specific channel. More...
 

Detailed Description

Driver for ADC (analog to digital converter)

Enumeration Type Documentation

◆ twr_adc_channel_t

ADC channel.

Enumerator
TWR_ADC_CHANNEL_A0 

ADC channel A0.

TWR_ADC_CHANNEL_A1 

ADC channel A1.

TWR_ADC_CHANNEL_A2 

ADC channel A2.

TWR_ADC_CHANNEL_A3 

ADC channel A3.

TWR_ADC_CHANNEL_A4 

ADC channel A4.

TWR_ADC_CHANNEL_A5 

ADC channel A5.

TWR_ADC_CHANNEL_A6 

ADC channel A6.

Definition at line 13 of file twr_adc.h.

◆ twr_adc_event_t

ADC event.

Enumerator
TWR_ADC_EVENT_DONE 

ADC event.

Definition at line 91 of file twr_adc.h.

◆ twr_adc_oversampling_t

ADC oversampling.

Enumerator
TWR_ADC_OVERSAMPLING_NONE 

ADC no oversampling.

TWR_ADC_OVERSAMPLING_2 

ADC 2x oversampling.

TWR_ADC_OVERSAMPLING_4 

ADC 4x oversampling.

TWR_ADC_OVERSAMPLING_8 

ADC 8x oversampling.

TWR_ADC_OVERSAMPLING_16 

ADC 16x oversampling.

TWR_ADC_OVERSAMPLING_32 

ADC 32x oversampling.

TWR_ADC_OVERSAMPLING_64 

ADC 64x oversampling.

TWR_ADC_OVERSAMPLING_128 

ADC 128x oversampling.

TWR_ADC_OVERSAMPLING_256 

ADC 256x oversampling.

Definition at line 40 of file twr_adc.h.

◆ twr_adc_resolution_t

ADC resolution.

Enumerator
TWR_ADC_RESOLUTION_12_BIT 

ADC 12 bit resolution.

TWR_ADC_RESOLUTION_10_BIT 

ADC 10 bit resolution.

TWR_ADC_RESOLUTION_8_BIT 

ADC 8 bit resolution.

TWR_ADC_RESOLUTION_6_BIT 

ADC 6 bit resolution.

Definition at line 73 of file twr_adc.h.

Function Documentation

◆ twr_adc_async_get_value()

bool twr_adc_async_get_value ( twr_adc_channel_t  channel,
uint16_t *  result 
)

Get asynchronous measurement result.

Parameters
[in]channelADC channel
[out]resultPointer to variable where result will be stored
Returns
true On success
false On failure

Definition at line 274 of file twr_adc.c.

◆ twr_adc_async_get_voltage()

bool twr_adc_async_get_voltage ( twr_adc_channel_t  channel,
float *  result 
)

Get asynchronous measurement result in volts.

Parameters
[in]channelADC channel
[out]resultPointer to variable where result in volts will be stored
Returns
true On success
false On failure

Definition at line 280 of file twr_adc.c.

Referenced by twr_module_battery_is_present().

Here is the caller graph for this function:

◆ twr_adc_async_measure()

bool twr_adc_async_measure ( twr_adc_channel_t  channel)

Begins reading the ADC channel voltage in asynchronous mode.

Parameters
[in]channelADC channel
Returns
true On success
false On failure

Definition at line 234 of file twr_adc.c.

Referenced by twr_adc_calibration(), and twr_module_battery_is_present().

Here is the caller graph for this function:

◆ twr_adc_calibration()

bool twr_adc_calibration ( void  )

Calibration.

Returns
true On success
false On failure

Definition at line 344 of file twr_adc.c.

Referenced by twr_adc_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_adc_get_value()

bool twr_adc_get_value ( twr_adc_channel_t  channel,
uint16_t *  result 
)

Reads the ADC channel value.

Parameters
[in]channelADC channel
[out]resultPointer to destination where ADC conversion will be stored
Returns
true On success
false On failure

Definition at line 178 of file twr_adc.c.

Referenced by twr_analog_sensor_measure().

Here is the caller graph for this function:

◆ twr_adc_get_vdda_voltage()

bool twr_adc_get_vdda_voltage ( float *  vdda_voltage)

Get voltage on VDDA pin.

Parameters
[out]vdda_voltagePointer to destination where VDDA will be stored
Returns
true On valid VDDA
false On valid VDDA

Definition at line 286 of file twr_adc.c.

Here is the call graph for this function:

◆ twr_adc_is_ready()

bool twr_adc_is_ready ( )

Check if ADC is ready for reading.

Returns
true If ready
false If not ready

Definition at line 173 of file twr_adc.c.

◆ twr_adc_oversampling_set()

void twr_adc_oversampling_set ( twr_adc_channel_t  channel,
twr_adc_oversampling_t  oversampling 
)

Set ADC oversampling for specific channel.

Parameters
[in]channelADC channel
[in]oversamplingOversampling can be 2, 4, 8, 16, 32, 64, 128 or 256

Definition at line 101 of file twr_adc.c.

Referenced by twr_module_battery_is_present().

Here is the caller graph for this function:

◆ twr_adc_resolution_set()

void twr_adc_resolution_set ( twr_adc_channel_t  channel,
twr_adc_resolution_t  resolution 
)

Set ADC resolution for specific channel.

Parameters
[in]channelADC channel
[in]resolutionResolution can be 6, 8, 10 or 12 bit

Definition at line 106 of file twr_adc.c.

◆ twr_adc_set_event_handler()

bool twr_adc_set_event_handler ( twr_adc_channel_t  channel,
void(*)(twr_adc_channel_t, twr_adc_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]channelADC channel
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)
Returns
true On success
false On failure

Definition at line 218 of file twr_adc.c.

Referenced by twr_analog_sensor_init(), and twr_module_battery_is_present().

Here is the caller graph for this function: