From 3868a7fa100f72137063bc2aed4f07284422ebd6 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Thu, 27 Apr 2023 17:52:03 +0200 Subject: [PATCH] cpu/stm32: implement periph_timer_query_freqs --- cpu/stm32/Kconfig | 1 + cpu/stm32/Makefile.features | 1 + cpu/stm32/periph/timer.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/cpu/stm32/Kconfig b/cpu/stm32/Kconfig index e714eca3c378..f6a0c4bba788 100644 --- a/cpu/stm32/Kconfig +++ b/cpu/stm32/Kconfig @@ -12,6 +12,7 @@ config CPU_STM32 select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ select HAS_PERIPH_TIMER_PERIODIC + select HAS_PERIPH_TIMER_QUERY_FREQS select HAS_PERIPH_RTT_OVERFLOW select HAS_PERIPH_UART_MODECFG select HAS_PERIPH_UART_NONBLOCKING diff --git a/cpu/stm32/Makefile.features b/cpu/stm32/Makefile.features index db958253163d..aa93e3cef57f 100644 --- a/cpu/stm32/Makefile.features +++ b/cpu/stm32/Makefile.features @@ -8,6 +8,7 @@ FEATURES_PROVIDED += cpu_stm32$(CPU_FAM) FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_timer_periodic +FEATURES_PROVIDED += periph_timer_query_freqs FEATURES_PROVIDED += periph_rtt_overflow FEATURES_PROVIDED += periph_uart_modecfg FEATURES_PROVIDED += periph_uart_nonblocking diff --git a/cpu/stm32/periph/timer.c b/cpu/stm32/periph/timer.c index 3ea8fb85e77a..edf80488c43d 100644 --- a/cpu/stm32/periph/timer.c +++ b/cpu/stm32/periph/timer.c @@ -161,6 +161,23 @@ int timer_set_absolute(tim_t tim, int channel, unsigned int value) return 0; } +uword_t timer_query_freqs_numof(tim_t dev) +{ + (void)dev; + /* Prescaler values from 0 to UINT16_MAX are supported */ + return UINT16_MAX + 1; +} + +uint32_t timer_query_freqs(tim_t dev, uword_t index) +{ + + if (index > UINT16_MAX) { + return 0; + } + + return periph_timer_clk(timer_config[dev].bus) / (index + 1); +} + int timer_set(tim_t tim, int channel, unsigned int timeout) { unsigned value = (dev(tim)->CNT + timeout) & timer_config[tim].max;