From 72b36371b276d77da9d9654ff6338acc2c25015e Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 11 Jan 2017 10:38:11 +0000 Subject: ADCv1 enhancement. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10031 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.c | 92 ++++++++++++++++++++++++++++++ os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h | 8 +++ 2 files changed, 100 insertions(+) (limited to 'os/hal') diff --git a/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.c b/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.c index 55d0d2d44..2f67aa80a 100644 --- a/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.c +++ b/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.c @@ -335,6 +335,98 @@ void adc_lld_serve_interrupt(ADCDriver *adcp) { } } +/** + * @brief Enables the VREFEN bit. + * @details The VREFEN bit is required in order to sample the VREF channel. + * @note This is an STM32-only functionality. + * @note This function is meant to be called after @p adcStart(). + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +void adcSTM32EnableVREF(void) { + + ADC->CCR |= ADC_CCR_VREFEN; +} + +/** + * @brief Disables the VREFEN bit. + * @details The VREFEN bit is required in order to sample the VREF channel. + * @note This is an STM32-only functionality. + * @note This function is meant to be called after @p adcStart(). + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +void adcSTM32DisableVREF(void) { + + ADC->CCR &= ~ADC_CCR_VREFEN; +} + +/** + * @brief Enables the TSEN bit. + * @details The TSEN bit is required in order to sample the internal + * temperature sensor and internal reference voltage. + * @note This is an STM32-only functionality. + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +void adcSTM32EnableTS(void) { + + ADC->CCR |= ADC_CCR_TSEN; +} + +/** + * @brief Disables the TSEN bit. + * @details The TSEN bit is required in order to sample the internal + * temperature sensor and internal reference voltage. + * @note This is an STM32-only functionality. + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +void adcSTM32DisableTS(void) { + + ADC->CCR &= ~ADC_CCR_TSEN; +} + +#ifdef STM32F0XX +/** + * @brief Enables the VBATEN bit. + * @details The VBATEN bit is required in order to sample the VBAT channel. + * @note This is an STM32-only functionality. + * @note This function is meant to be called after @p adcStart(). + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +void adcSTM32EnableVBAT(void) { + + ADC->CCR |= ADC_CCR_VBATEN; +} + +/** + * @brief Disables the VBATEN bit. + * @details The VBATEN bit is required in order to sample the VBAT channel. + * @note This is an STM32-only functionality. + * @note This function is meant to be called after @p adcStart(). + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +void adcSTM32DisableVBAT(void) { + + ADC->CCR &= ~ADC_CCR_VBATEN; +} +#endif /* STM32F0XX */ + #endif /* HAL_USE_ADC */ /** @} */ diff --git a/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h b/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h index 6cb2e0a9a..93bba6cb9 100644 --- a/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h +++ b/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h @@ -430,6 +430,14 @@ extern "C" { void adc_lld_start_conversion(ADCDriver *adcp); void adc_lld_stop_conversion(ADCDriver *adcp); void adc_lld_serve_interrupt(ADCDriver *adcp); + void adcSTM32EnableVREF(void); + void adcSTM32DisableVREF(void); + void adcSTM32EnableTS(void); + void adcSTM32DisableTS(void); +#ifdef STM32F0XX + void adcSTM32EnableVBAT(void); + void adcSTM32DisableVBAT(void); +#endif /* STM32F0XX */ #ifdef __cplusplus } #endif -- cgit v1.2.3