From 75dc0fd542b3d9744cc2a0a4b661cb2951a9c2bd Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Thu, 3 Jun 2021 13:23:21 -0400 Subject: [PATCH] Migrate TIM[2-5] to macro tables. --- embassy-stm32/gen.py | 6 +++--- embassy-stm32/src/clock.rs | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 55612cb3..3cf93a2c 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py @@ -136,9 +136,9 @@ with open(output_file, 'w') as f: if (func := funcs.get(f'{name}_D7')) != None: f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});') - if block_name == 'TimGp16': - if re.match('TIM[2345]$', name): - f.write(f'impl_timer!({name});') + # if block_name == 'TimGp16': + # if re.match('TIM[2345]$', name): + # f.write(f'impl_timer!({name});') if block_mod == 'exti': for irq in chip['interrupts']: diff --git a/embassy-stm32/src/clock.rs b/embassy-stm32/src/clock.rs index aa83c5b4..694ca666 100644 --- a/embassy-stm32/src/clock.rs +++ b/embassy-stm32/src/clock.rs @@ -10,6 +10,7 @@ use embassy::time::{Clock as EmbassyClock, TICKS_PER_SECOND}; use crate::interrupt::{CriticalSection, Interrupt, Mutex}; use crate::pac::timer::TimGp16; +use crate::peripherals; use crate::time::Hertz; // Clock timekeeping works with something we call "periods", which are time intervals @@ -362,15 +363,22 @@ pub trait Instance: sealed::Instance + Sized + 'static {} macro_rules! impl_timer { ($inst:ident) => { - impl crate::clock::sealed::Instance for peripherals::$inst { + impl sealed::Instance for peripherals::$inst { type Interrupt = crate::interrupt::$inst; fn inner() -> crate::clock::TimerInner { - const INNER: crate::clock::TimerInner = crate::clock::TimerInner(crate::pac::$inst); + const INNER: TimerInner = TimerInner(crate::pac::$inst); INNER } } - impl crate::clock::Instance for peripherals::$inst {} + impl Instance for peripherals::$inst {} }; } + +crate::pac::peripherals!( + (timer, TIM2) => { impl_timer!(TIM2); }; + (timer, TIM3) => { impl_timer!(TIM3); }; + (timer, TIM4) => { impl_timer!(TIM4); }; + (timer, TIM5) => { impl_timer!(TIM5); }; +);