From 650f867b1cb364a514d9e5145b0244bb7223c387 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Fri, 23 Jul 2021 11:16:17 -0400 Subject: [PATCH] Add a single-column variant to gpio_rcc! macro table which includes just the set of registers that need to be considered. Then match against those registers with a single `modify(...)` --- embassy-stm32/src/gpio.rs | 8 ++++++-- stm32-metapac-gen/src/lib.rs | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 09f241faa..5145bd689 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -452,9 +452,13 @@ crate::pac::pins!( pub(crate) unsafe fn init() { crate::pac::gpio_rcc! { - ($name:ident, $clock:ident, $en_reg:ident, $rst_reg:ident, $en_fn:ident, $rst_fn:ident) => { + ($en_reg:ident) => { crate::pac::RCC.$en_reg().modify(|reg| { - reg.$en_fn(true); + crate::pac::gpio_rcc! { + ($name:ident, $clock:ident, $en_reg, $rst_reg:ident, $en_fn:ident, $rst_fn:ident) => { + reg.$en_fn(true); + }; + } }); }; } diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 1c7ac38ee..203d943de 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -288,6 +288,7 @@ pub fn gen(options: Options) { let mut dma_channel_counts: HashMap = HashMap::new(); let mut dbgmcu_table: Vec> = Vec::new(); let mut gpio_rcc_table: Vec> = Vec::new(); + let mut gpio_regs: HashSet = HashSet::new(); let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; let gpio_stride = 0x400; @@ -492,6 +493,7 @@ pub fn gen(options: Options) { peripheral_rcc_table.push(row); } else { gpio_rcc_table.push(row); + gpio_regs.insert( enable_reg.to_ascii_lowercase() ); } } (None, Some(_)) => { @@ -508,6 +510,10 @@ pub fn gen(options: Options) { dev.peripherals.push(ir_peri); } + for reg in gpio_regs { + gpio_rcc_table.push( vec!( reg ) ); + } + for (id, channel_info) in &core.dma_channels { let mut row = Vec::new(); let dma_peri = core.peripherals.get(&channel_info.dma).unwrap();