Skip to content

Commit

Permalink
Merge pull request #20148 from maribu/periph_timer_query_freq-stm32
Browse files Browse the repository at this point in the history
cpu/stm32: implement periph_timer_query_freqs
  • Loading branch information
maribu authored Dec 7, 2023
2 parents 81b5cf2 + 3868a7f commit b0261f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpu/stm32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cpu/stm32/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cpu/stm32/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b0261f3

Please sign in to comment.