24#include "px_stm32cube.h"
31typedef struct px_adc_per_s
51static void px_adc_init_per(ADC_TypeDef * adc_base_adr,
59 LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
70 LL_ADC_SetClock(adc_base_adr, LL_ADC_CLOCK_SYNC_PCLK_DIV1);
73 LL_ADC_SetClock(adc_base_adr, LL_ADC_CLOCK_SYNC_PCLK_DIV2);
76 LL_ADC_SetClock(adc_base_adr, LL_ADC_CLOCK_SYNC_PCLK_DIV4);
83 LL_ADC_EnableInternalRegulator(adc_base_adr);
91 LL_ADC_SetOverSamplingScope(adc_base_adr, LL_ADC_OVS_GRP_REGULAR_CONTINUED);
92 LL_ADC_ConfigOverSamplingRatioShift(adc_base_adr,
97 LL_ADC_StartCalibration(adc_base_adr);
98 while(LL_ADC_IsCalibrationOnGoing(adc_base_adr)) {;}
100 LL_ADC_ClearFlag_ADRDY(adc_base_adr);
101 LL_ADC_Enable(adc_base_adr);
102 while(LL_ADC_IsActiveFlag_ADRDY(adc_base_adr) == 0) {;}
106static void px_adc_init_per_data(
px_adc_nr_t adc_nr,
114#if PX_ADC_CFG_ADC1_EN
131#if PX_ADC_CFG_ADC1_EN
132 px_adc_init_per_data(PX_ADC_NR_1, &px_adc_per_1);
155#if PX_ADC_CFG_ADC1_EN
157 adc_per = &px_adc_per_1;
161 PX_LOG_E(
"Invalid peripheral specified");
184 ADC_TypeDef * adc_base_adr;
191 ||(handle->
adc_per->open_counter == 0 ) )
213 LL_ADC_Disable(adc_base_adr);
214 while(LL_ADC_IsDisableOngoing(adc_base_adr)) {;}
216 LL_ADC_DisableInternalRegulator(adc_base_adr);
217 while(LL_ADC_IsInternalRegulatorEnabled(adc_base_adr)) {;}
219 switch(handle->
adc_per->adc_nr)
221#if PX_ADC_CFG_ADC1_EN
223 LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_ADC1);
238 ADC_TypeDef * adc_base_adr;
246 ||(handle->
adc_per->open_counter == 0 ) )
260 LL_ADC_REG_StartConversion(adc_base_adr);
262 while(LL_ADC_REG_IsConversionOngoing(adc_base_adr)) {;}
264 data = LL_ADC_REG_ReadConversionData12(adc_base_adr);
#define NULL
NULL pointer.
#define PX_LOG_NAME(name)
Macro to declare a log name string once for each file to reduce code size.
#define PX_LOG_E(format,...)
Macro to display a formatted ERROR message.
#define PX_LOG_ASSERT(expression)
Macro that will test an expression, and block indefinitely if false.
struct px_adc_per_s * adc_per
ADC peripheral data.
#define PX_ADC_CFG_OVERSAMPLING_SHIFT
Specify ADC oversampling (see 'px_adc_cfg_oversampling_shift_t')
#define PX_ADC_CFG_CLK
Specify ADC clock source (see 'px_adc_cfg_clk_t')
void px_adc_init(void)
Initialise ADC driver.
px_adc_nr_t
Specify ADC peripheral.
px_adc_ch_t
Specify ADC channel.
#define PX_ADC_CFG_OVERSAMPLING
Specify ADC oversampling (see 'px_adc_cfg_oversampling_t')
bool px_adc_close(px_adc_handle_t *handle)
Close specified device.
bool px_adc_open(px_adc_handle_t *handle, px_adc_nr_t adc_nr)
Open ADC peripheral using predefined (default) parameters.
#define PX_ADC_CFG_SAMPLE_TIME
Specify ADC sampling time (see 'px_adc_cfg_sample_time_t')
uint16_t px_adc_sample(px_adc_handle_t *handle, px_adc_ch_t ch)
Perform a single measurement on the specified ADC channel.
#define PX_ADC_CH_TO_BITMASK(ch)
Convert ADC channel number into bit mask.
@ PX_ADC_CFG_OVERSAMPLING_NONE
No oversampling.
@ PX_ADC_CFG_RES_12_BITS
12-bit resolution
@ PX_ADC_CFG_CLK_PCLK_DIV2
Peripheral Clock / 2.
@ PX_ADC_CFG_CLK_PCLK
Peripheral Clock.
@ PX_ADC_CFG_CLK_PCLK_DIV4
Peripheral Clock / 4.
Internal data for each ADC handle.
ADC_TypeDef * adc_base_adr
ADC peripheral base register address.
uint8_t open_counter
Number of open handles referencing peripheral.
px_adc_nr_t adc_nr
ADC peripheral number.