1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/qn908x: migrate ADC periph to ztimer

This commit is contained in:
Alexandre Abadie 2021-12-02 13:59:42 +01:00
parent 2e0c02b25d
commit 7c34d69b84
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
3 changed files with 15 additions and 3 deletions

View File

@ -14,4 +14,9 @@ ifneq (,$(filter periph_uart periph_i2c periph_spi,$(USEMODULE)))
USEMODULE += periph_flexcomm
endif
ifneq (,$(filter periph_adc,$(USEMODULE)))
USEMODULE += ztimer
USEMODULE += ztimer_usec
endif
include $(RIOTCPU)/cortexm_common/Makefile.dep

View File

@ -17,3 +17,10 @@ config MODULE_PERIPH_GPIO_MUX
depends on TEST_KCONFIG
help
Common Pin MUX functions for qn908x CPUs.
config MODULE_PERIPH_ADC
bool "ADC peripheral driver"
depends on HAS_PERIPH_ADC
select MODULE_ZTIMER
select MODULE_ZTIMER_USEC
select MODULE_ZTIMER_PERIPH_TIMER

View File

@ -41,7 +41,7 @@
#include "bitarithm.h"
#include "cpu.h"
#include "mutex.h"
#include "xtimer.h"
#include "ztimer.h"
#include "gpio_mux.h"
#include "periph/adc.h"
@ -142,7 +142,7 @@ int adc_init(adc_t line)
/* Need to wait 100 us before the ADC can be used for sampling. We could
* in theory avoid this wait since it is only needed before adc_sample()
* is called but it is short enough that it is safer to include it. */
xtimer_usleep(100u);
ztimer_sleep(ZTIMER_USEC, 100u);
/* Enable the ADC clock so we can use the ADC. */
CLOCK_EnableClock(kCLOCK_Adc);
@ -278,7 +278,7 @@ int32_t adc_sample(adc_t line, adc_res_t res) {
ADC_CFG_SCAN_INTV(4); /* Switching ADC source every 32 clock cycles. */
/* Need to wait for one ADC cycle before it can be started. */
xtimer_usleep(adc_clock_cycle_us[QN908X_ADC_CLOCK]);
ztimer_sleep(ZTIMER_USEC, adc_clock_cycle_us[QN908X_ADC_CLOCK]);
/* Configure the destination of the ADC value read from the interrupt. */
volatile int32_t adc_data = 0;