From 2c722ec0ee8fc53e18f1b6df0b602df1aecfd59b Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Thu, 3 Jun 2021 13:50:48 -0400 Subject: [PATCH] Migrate sdmmc to macro tables. --- embassy-stm32/gen.py | 88 ---------------------------------- embassy-stm32/src/sdmmc/mod.rs | 2 +- embassy-stm32/src/sdmmc/v2.rs | 59 ++++++++++++++++++----- 3 files changed, 49 insertions(+), 100 deletions(-) diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 7c128c1a..ddd4a3b8 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py @@ -48,48 +48,6 @@ with open(output_file, 'w') as f: custom_singletons = False - # if block_mod == 'usart': - # f.write(f'impl_usart!({name});') - # for pin, funcs in af.items(): - # if pin in pins: - # if (func := funcs.get(f'{name}_RX')) != None: - # f.write(f'impl_usart_pin!({name}, RxPin, {pin}, {func});') - # if (func := funcs.get(f'{name}_TX')) != None: - # f.write(f'impl_usart_pin!({name}, TxPin, {pin}, {func});') - # if (func := funcs.get(f'{name}_CTS')) != None: - # f.write(f'impl_usart_pin!({name}, CtsPin, {pin}, {func});') - # if (func := funcs.get(f'{name}_RTS')) != None: - # f.write(f'impl_usart_pin!({name}, RtsPin, {pin}, {func});') - # if (func := funcs.get(f'{name}_CK')) != None: - # f.write(f'impl_usart_pin!({name}, CkPin, {pin}, {func});') - - # if block_mod == 'rng': - # for irq in chip['interrupts']: - # if re.search('RNG', irq): - # f.write(f'impl_rng!({name}, {irq});') - - # if block_mod == 'spi': - # if 'clock' in peri: - # clock = peri['clock'] - # f.write(f'impl_spi!({name}, {clock});') - # for pin, funcs in af.items(): - # if pin in pins: - # if (func := funcs.get(f'{name}_SCK')) != None: - # f.write(f'impl_spi_pin!({name}, SckPin, {pin}, {func});') - # if (func := funcs.get(f'{name}_MOSI')) != None: - # f.write(f'impl_spi_pin!({name}, MosiPin, {pin}, {func});') - # if (func := funcs.get(f'{name}_MISO')) != None: - # f.write(f'impl_spi_pin!({name}, MisoPin, {pin}, {func});') - - # if block_mod == 'i2c': - # f.write(f'impl_i2c!({name});') - # for pin, funcs in af.items(): - # if pin in pins: - # if func := funcs.get(f'{name}_SCL'): - # f.write(f'impl_i2c_pin!({name}, SclPin, {pin}, {func});') - # if func := funcs.get(f'{name}_SDA'): - # f.write(f'impl_i2c_pin!({name}, SdaPin, {pin}, {func});') - if block_mod == 'gpio': custom_singletons = True port = name[4:] @@ -111,53 +69,7 @@ with open(output_file, 'w') as f: f.write(f'impl_dma_channel!({channel}, {dma_num}, {ch_num});') - if peri['block'] == 'sdmmc_v2/SDMMC': - f.write(f'impl_sdmmc!({name});') - for pin, funcs in af.items(): - if pin in pins: - if (func := funcs.get(f'{name}_CK')) != None: - f.write(f'impl_sdmmc_pin!({name}, CkPin, {pin}, {func});') - if (func := funcs.get(f'{name}_CMD')) != None: - f.write(f'impl_sdmmc_pin!({name}, CmdPin, {pin}, {func});') - if (func := funcs.get(f'{name}_D0')) != None: - f.write(f'impl_sdmmc_pin!({name}, D0Pin, {pin}, {func});') - if (func := funcs.get(f'{name}_D1')) != None: - f.write(f'impl_sdmmc_pin!({name}, D1Pin, {pin}, {func});') - if (func := funcs.get(f'{name}_D2')) != None: - f.write(f'impl_sdmmc_pin!({name}, D2Pin, {pin}, {func});') - if (func := funcs.get(f'{name}_D3')) != None: - f.write(f'impl_sdmmc_pin!({name}, D3Pin, {pin}, {func});') - if (func := funcs.get(f'{name}_D4')) != None: - f.write(f'impl_sdmmc_pin!({name}, D4Pin, {pin}, {func});') - if (func := funcs.get(f'{name}_D5')) != None: - f.write(f'impl_sdmmc_pin!({name}, D5Pin, {pin}, {func});') - if (func := funcs.get(f'{name}_D6')) != None: - f.write(f'impl_sdmmc_pin!({name}, D6Pin, {pin}, {func});') - 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_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});') - # if 'dac_out1' in peri: - # pin = peri['dac_out1'] - # f.write(f'impl_dac_pin!({name}, 1, {pin});') - # if 'dac_out2' in peri: - # pin = peri['dac_out2'] - # f.write(f'impl_dac_pin!({name}, 2, {pin});') - # if not custom_singletons: singletons.append(name) f.write(f"embassy_extras::peripherals!({','.join(singletons)});") - - # ========= exti interrupts - # f.write(f"impl_exti_irq!({','.join(exti_interrupts)});") diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 087cb4c4..9244c22a 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -1,6 +1,6 @@ #![macro_use] -#[cfg_attr(sdmmc_v1, path = "v1.rs")] +//#[cfg_attr(sdmmc_v1, path = "v1.rs")] #[cfg_attr(sdmmc_v2, path = "v2.rs")] mod _version; diff --git a/embassy-stm32/src/sdmmc/v2.rs b/embassy-stm32/src/sdmmc/v2.rs index e432ca9a..6d21091a 100644 --- a/embassy-stm32/src/sdmmc/v2.rs +++ b/embassy-stm32/src/sdmmc/v2.rs @@ -15,6 +15,7 @@ use crate::interrupt::Interrupt; use crate::pac; use crate::pac::gpio::Gpio; use crate::pac::sdmmc::Sdmmc as RegBlock; +use crate::peripherals; use crate::time::Hertz; /// The signalling scheme used on the SDMMC bus @@ -1469,12 +1470,12 @@ where } } -macro_rules! impl_sdmmc { - ($inst:ident) => { - impl crate::sdmmc::sealed::Instance for peripherals::$inst { +crate::pac::peripherals!( + (sdmmc, $inst:ident) => { + impl sealed::Instance for peripherals::$inst { type Interrupt = crate::interrupt::$inst; - fn inner() -> crate::sdmmc::SdmmcInner { + fn inner() -> SdmmcInner { const INNER: crate::sdmmc::SdmmcInner = crate::sdmmc::SdmmcInner(crate::pac::$inst); INNER } @@ -1485,20 +1486,56 @@ macro_rules! impl_sdmmc { } } - impl crate::sdmmc::Instance for peripherals::$inst {} + impl Instance for peripherals::$inst {} }; -} +); -macro_rules! impl_sdmmc_pin { - ($inst:ident, $func:ident, $pin:ident, $num:expr) => { - impl crate::sdmmc::sealed::$func for peripherals::$pin { - const AF_NUM: u8 = $num; +macro_rules! impl_pin { + ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { + impl crate::sdmmc::sealed::$signal for peripherals::$pin { + const AF_NUM: u8 = $af; } - impl crate::sdmmc::$func for peripherals::$pin {} + impl crate::sdmmc::$signal for peripherals::$pin {} }; } +crate::pac::peripheral_pins!( + ($inst:ident, sdmmc, SDMMC, $pin:ident, CK, $af:expr) => { + impl_pin!($inst, $pin, CkPin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, CMD, $af:expr) => { + impl_pin!($inst, $pin, CmdPin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D0, $af:expr) => { + impl_pin!($inst, $pin, D0Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D1, $af:expr) => { + impl_pin!($inst, $pin, D1Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D2, $af:expr) => { + impl_pin!($inst, $pin, D2Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D3, $af:expr) => { + impl_pin!($inst, $pin, D3Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D4, $af:expr) => { + impl_pin!($inst, $pin, D4Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D5, $af:expr) => { + impl_pin!($inst, $pin, D5Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D6, $af:expr) => { + impl_pin!($inst, $pin, D6Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D6, $af:expr) => { + impl_pin!($inst, $pin, D7Pin, $af); + }; + ($inst:ident, sdmmc, SDMMC, $pin:ident, D8, $af:expr) => { + impl_pin!($inst, $pin, D8Pin, $af); + }; +); + #[cfg(feature = "sdmmc-rs")] mod sdmmc_rs { use super::*;