diff --git a/include/libopencm3/stm32/f3/adc.h b/include/libopencm3/stm32/f3/adc.h index f54b8d10..6a0bfe5b 100644 --- a/include/libopencm3/stm32/f3/adc.h +++ b/include/libopencm3/stm32/f3/adc.h @@ -334,11 +334,10 @@ /* ADCALDIF: Differential mode for calibration */ #define ADC_CR_ADCALDIF (1 << 30) -/* ADVREGEN: ADC voltage regulador enable */ -#define ADC_CR_ADVREGEN_INTERMEDIATE (0x0 << 28) +/** ADVREGEN: ADC voltage regulator enable */ #define ADC_CR_ADVREGEN_ENABLE (0x1 << 28) #define ADC_CR_ADVREGEN_DISABLE (0x2 << 28) -/* --- Bit 0x3 reserved --- */ +#define ADC_CR_ADVREGEN_MASK (0x3 << 28) /* JADSTP: ADC stop of injected conversion command */ #define ADC_CR_JADSTP (1 << 5) @@ -920,6 +919,8 @@ bool adc_awd(uint32_t adc); /*void adc_set_dma_terminate(uint32_t adc);*/ void adc_enable_temperature_sensor(void); void adc_disable_temperature_sensor(void); +void adc_enable_regulator(uint32_t adc); +void adc_disable_regulator(uint32_t adc); END_DECLS diff --git a/lib/stm32/f3/adc.c b/lib/stm32/f3/adc.c index f857f7ed..2b3a4c93 100644 --- a/lib/stm32/f3/adc.c +++ b/lib/stm32/f3/adc.c @@ -1197,5 +1197,30 @@ void adc_disable_temperature_sensor() /*---------------------------------------------------------------------------*/ +/** + * Enable the ADC Voltage regulator + * Before any use of the ADC, the ADC Voltage regulator must be enabled. + * You must wait up to 10uSecs afterwards before trying anything else. + * @param[in] adc ADC block register address base + * @sa adc_disable_regulator + */ +void adc_enable_regulator(uint32_t adc) +{ + ADC_CR(adc) &= ~ADC_CR_ADVREGEN_MASK; + ADC_CR(adc) |= ADC_CR_ADVREGEN_ENABLE; +} + +/** + * Disable the ADC Voltage regulator + * You can disable the adc vreg when not in use to save power + * @param[in] adc ADC block register address base + * @sa adc_enable_regulator + */ +void adc_disable_regulator(uint32_t adc) +{ + ADC_CR(adc) &= ~ADC_CR_ADVREGEN_MASK; + ADC_CR(adc) |= ADC_CR_ADVREGEN_DISABLE; +} + /**@}*/