cpu/stm32/adc: migrate to ztimer

This commit is contained in:
Alexandre Abadie 2021-12-02 12:26:13 +01:00
parent 0c7d2a0f55
commit 924c2fd6da
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
4 changed files with 19 additions and 7 deletions

View File

@ -43,7 +43,7 @@ ifneq (,$(filter periph_rtc_mem,$(USEMODULE)))
endif endif
ifneq (,$(filter periph_adc,$(FEATURES_USED))) ifneq (,$(filter periph_adc,$(FEATURES_USED)))
ifneq (,$(filter $(CPU_FAM),wl)) ifneq (,$(filter f3 l4 wl, $(CPU_FAM)))
USEMODULE += ztimer USEMODULE += ztimer
USEMODULE += ztimer_msec USEMODULE += ztimer_msec
endif endif

View File

@ -31,6 +31,6 @@ config MODULE_PERIPH_CAN
config MODULE_PERIPH_ADC config MODULE_PERIPH_ADC
bool "ADC peripheral driver" bool "ADC peripheral driver"
depends on HAS_PERIPH_ADC depends on HAS_PERIPH_ADC
select MODULE_ZTIMER if HAS_CPU_STM32WL select MODULE_ZTIMER if HAS_CPU_STM32F3 || HAS_CPU_STM32L4 || HAS_CPU_STM32WL
select MODULE_ZTIMER_MSEC if HAS_CPU_STM32WL select MODULE_ZTIMER_MSEC if HAS_CPU_STM32F3 || HAS_CPU_STM32L4 || HAS_CPU_STM32WL
select MODULE_PERIPH_COMMON select MODULE_PERIPH_COMMON

View File

@ -23,7 +23,7 @@
#include "mutex.h" #include "mutex.h"
#include "periph/adc.h" #include "periph/adc.h"
#include "periph_conf.h" #include "periph_conf.h"
#include "xtimer.h" #include "ztimer.h"
#define SMP_MIN (0x2) /*< Sampling time for slow channels #define SMP_MIN (0x2) /*< Sampling time for slow channels
(0x2 = 4.5 ADC clock cycles) */ (0x2 = 4.5 ADC clock cycles) */
@ -134,7 +134,13 @@ int adc_init(adc_t line)
if (!(dev(line)->CR & ADC_CR_ADEN)) { if (!(dev(line)->CR & ADC_CR_ADEN)) {
/* Enable ADC internal voltage regulator and wait for startup period */ /* Enable ADC internal voltage regulator and wait for startup period */
dev(line)->CR |= ADC_CR_ADVREGEN; dev(line)->CR |= ADC_CR_ADVREGEN;
xtimer_usleep(ADC_T_ADCVREG_STUP_US); #if IS_USED(MODULE_ZTIMER_USEC)
ztimer_sleep(ZTIMER_USEC, ADC_T_ADCVREG_STUP_US);
#else
/* to avoid using ZTIMER_USEC unless already included round up the
internal voltage regulator start up to 1ms */
ztimer_sleep(ZTIMER_MSEC, 1);
#endif
if (dev(line)->DIFSEL & (1 << adc_config[line].chan)) { if (dev(line)->DIFSEL & (1 << adc_config[line].chan)) {
/* Configure calibration for differential inputs */ /* Configure calibration for differential inputs */

View File

@ -25,7 +25,7 @@
#include "mutex.h" #include "mutex.h"
#include "periph/adc.h" #include "periph/adc.h"
#include "periph_conf.h" #include "periph_conf.h"
#include "xtimer.h" #include "ztimer.h"
/** /**
* @brief map CPU specific register/value names * @brief map CPU specific register/value names
@ -138,7 +138,13 @@ int adc_init(adc_t line)
/* enable ADC internal voltage regulator and wait for startup period */ /* enable ADC internal voltage regulator and wait for startup period */
dev(line)->ADC_CR_REG |= (ADC_CR_ADVREGEN); dev(line)->ADC_CR_REG |= (ADC_CR_ADVREGEN);
xtimer_usleep(ADC_T_ADCVREG_STUP_US); #if IS_USED(MODULE_ZTIMER_USEC)
ztimer_sleep(ZTIMER_USEC, ADC_T_ADCVREG_STUP_US);
#else
/* to avoid using ZTIMER_USEC unless already included round up the
internal voltage regulator start up to 1ms */
ztimer_sleep(ZTIMER_MSEC, 1);
#endif
/* configure calibration for single ended input */ /* configure calibration for single ended input */
dev(line)->ADC_CR_REG &= ~(ADC_CR_ADCALDIF); dev(line)->ADC_CR_REG &= ~(ADC_CR_ADCALDIF);