From fe47f781be10264ce1d3b533c1bdbf6508f6b361 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Thu, 3 Jun 2021 13:35:27 -0400 Subject: [PATCH] Migrate exti_irq stuff to macro tables. --- embassy-stm32/gen.py | 10 +++++----- embassy-stm32/src/exti.rs | 22 ++++++++++++++++++++++ embassy-stm32/src/lib.rs | 2 +- stm32-metapac/build.rs | 24 +++++++++++++++--------- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 3cf93a2c..7c128c1a 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py @@ -140,10 +140,10 @@ with open(output_file, 'w') as f: # if re.match('TIM[2345]$', name): # f.write(f'impl_timer!({name});') - if block_mod == 'exti': - for irq in chip['interrupts']: - if re.match('EXTI', irq): - exti_interrupts.append(irq) + # if block_mod == 'exti': + # for irq in chip['interrupts']: + # if re.match('EXTI', irq): + # exti_interrupts.append(irq) # if block_mod == 'dac': # f.write(f'impl_dac!({name});') @@ -160,4 +160,4 @@ with open(output_file, 'w') as f: f.write(f"embassy_extras::peripherals!({','.join(singletons)});") # ========= exti interrupts - f.write(f"impl_exti_irq!({','.join(exti_interrupts)});") + # f.write(f"impl_exti_irq!({','.join(exti_interrupts)});") diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 61c28aa7..a8875fb5 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -214,6 +214,7 @@ impl_exti!(EXTI15, 15); pub(crate) unsafe fn init() {} +/* macro_rules! impl_exti_irq { ($($e:ident),+) => { /// safety: must be called only once @@ -234,3 +235,24 @@ macro_rules! impl_exti_irq { )+ }; } + */ + +/// safety: must be called only once +pub(crate) unsafe fn init_exti() { + use embassy::interrupt::Interrupt; + use embassy::interrupt::InterruptExt; + + crate::pac::exti_interrupts!( + ($e:ident) => { + crate::interrupt::$e::steal().enable(); + }; + ); +} + +crate::pac::exti_interrupts!( + ($e:ident) => { + unsafe fn $e() { + on_irq() + } + }; +); diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index c51f93eb..54d46c5b 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -83,7 +83,7 @@ pub fn init(config: Config) -> Peripherals { #[cfg(dma)] dma::init(); - generated::init_exti(); + exti::init_exti(); rcc::init(config.rcc); } diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs index d33693f3..b19906ea 100644 --- a/stm32-metapac/build.rs +++ b/stm32-metapac/build.rs @@ -91,7 +91,7 @@ macro_rules! {} {{ ", name, name ) - .unwrap(); + .unwrap(); for row in data { write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap(); @@ -102,7 +102,7 @@ macro_rules! {} {{ " }}; }}" ) - .unwrap(); + .unwrap(); } fn main() { @@ -176,16 +176,15 @@ fn main() { peripheral_pins_table.push(row); } - cfgs.insert(bi.module.clone()); cfgs.insert(format!("{}_{}", bi.module, bi.version)); let mut peripheral_row = Vec::new(); - peripheral_row.push( bi.module.clone() ); - peripheral_row.push( name.clone() ); - peripherals_table.push( peripheral_row ); + peripheral_row.push(bi.module.clone()); + peripheral_row.push(name.clone()); + peripherals_table.push(peripheral_row); if let Some(old_version) = - peripheral_versions.insert(bi.module.clone(), bi.version.clone()) + peripheral_versions.insert(bi.module.clone(), bi.version.clone()) { if old_version != bi.version { panic!( @@ -256,8 +255,15 @@ fn main() { .map(|(kind, version)| vec![kind.clone(), version.clone()]) .collect(); + let exti_interrupt_table = &interrupt_table + .iter() + .filter(|row| row[0].contains("EXTI")) + .map(|row| row.clone()) + .collect(); + make_table(&mut extra, "pins", &pin_table); make_table(&mut extra, "interrupts", &interrupt_table); + make_table(&mut extra, "exti_interrupts", &exti_interrupt_table); make_table(&mut extra, "peripherals", &peripherals_table); make_table(&mut extra, "peripheral_versions", &peripheral_version_table); make_table(&mut extra, "peripheral_pins", &peripheral_pins_table); @@ -282,7 +288,7 @@ fn main() { transform::NameKind::Enum => format!("{}::vals::{}", prefix, s), _ => s.to_string(), }) - .unwrap(); + .unwrap(); ir.merge(peri); } @@ -311,7 +317,7 @@ fn main() { "PROVIDE({} = DefaultHandler);\n", name.to_ascii_uppercase() ) - .unwrap(); + .unwrap(); } File::create(out.join("device.x"))