diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 97773bb4..5ba05fa3 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py @@ -57,6 +57,7 @@ for chip in chips.values(): af = gpio_afs[chip['gpio_af']] peripheral_names = [] # USART1, PA5, EXTI8 + exti_interrupts = [] # EXTI IRQs, EXTI0, EXTI4_15 etc. peripheral_versions = {} # usart -> v1, syscfg -> f4 pins = set() # set of all present pins. PA4, PA5... @@ -177,6 +178,12 @@ for chip in chips.values(): if func := funcs.get(f'{name}_D7'): f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});') + + if block_mod == 'exti': + for irq in chip['interrupts']: + if re.match('EXTI', irq): + exti_interrupts.append(irq) + if not custom_singletons: peripheral_names.append(name) @@ -228,6 +235,15 @@ for chip in chips.values(): }} {''.join(irq_declares)} + + pub mod exti {{ + use embassy::interrupt::InterruptExt; + use crate::interrupt; + use super::*; + + impl_exti_irq!({','.join(exti_interrupts)}); + impl_exti_init!({','.join(exti_interrupts)}); + }} }} mod interrupt_vector {{ extern "C" {{ diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 0ae121ce..9f2401c8 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -21,41 +21,6 @@ const EXTI_COUNT: usize = 16; const NEW_AW: AtomicWaker = AtomicWaker::new(); static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [NEW_AW; EXTI_COUNT]; -#[interrupt] -unsafe fn EXTI0() { - on_irq() -} - -#[interrupt] -unsafe fn EXTI1() { - on_irq() -} - -#[interrupt] -unsafe fn EXTI2() { - on_irq() -} - -#[interrupt] -unsafe fn EXTI3() { - on_irq() -} - -#[interrupt] -unsafe fn EXTI4() { - on_irq() -} - -#[interrupt] -unsafe fn EXTI9_5() { - on_irq() -} - -#[interrupt] -unsafe fn EXTI15_10() { - on_irq() -} - pub unsafe fn on_irq() { let bits = EXTI.pr().read().0; @@ -249,14 +214,30 @@ impl_exti!(EXTI13, 13); impl_exti!(EXTI14, 14); impl_exti!(EXTI15, 15); -/// safety: must be called only once -pub(crate) unsafe fn init() { - interrupt::EXTI0::steal().enable(); - interrupt::EXTI1::steal().enable(); - interrupt::EXTI2::steal().enable(); - interrupt::EXTI3::steal().enable(); - interrupt::EXTI4::steal().enable(); - interrupt::EXTI9_5::steal().enable(); - interrupt::EXTI15_10::steal().enable(); - interrupt::EXTI15_10::steal().enable(); +macro_rules! impl_exti_irq { + ($e:ident) => { + #[interrupt] + unsafe fn $e() { + crate::exti::on_irq() + } + }; + + ($e:ident, $($es:ident),+) => { + impl_exti_irq! { $e } + impl_exti_irq! { $($es),+ } + }; +} + +macro_rules! impl_exti_init { + ($e:ident) => { + crate::interrupt::$e::steal().enable(); + }; + + ($e:ident, $($es:ident),+) => { + /// safety: must be called only once + pub(crate) unsafe fn init() { + impl_exti_init! { $e } + impl_exti_init! { $($es),+ } + } + }; } diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index edb90d77..0751ac0b 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -49,8 +49,8 @@ pub fn init(_config: Config) -> Peripherals { let p = Peripherals::take(); unsafe { - exti::init(); dma::init(); + interrupt::exti::init(); } p