diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index bfb79194..2736cd69 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:] @@ -102,62 +60,11 @@ with open(output_file, 'w') as f: if block_mod == 'dma': custom_singletons = True - num_dmas += 1 - dma_num = int(name[3:])-1 # substract 1 because we want DMA1=0, DMA2=1 - for ch_num in range(8): channel = f'{name}_CH{ch_num}' singletons.append(channel) - 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/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); }; +); diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index e1a603d4..46c485b3 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs @@ -3,6 +3,7 @@ #[cfg_attr(dac_v2, path = "v2.rs")] mod _version; use crate::gpio::NoPin; +use crate::peripherals; pub use _version::*; pub(crate) mod sealed { @@ -23,8 +24,8 @@ pub trait DacPin: sealed::DacPin + 'static {} impl DacPin for NoPin {} impl sealed::DacPin for NoPin {} -macro_rules! impl_dac { - ($inst:ident) => { +crate::pac::peripherals!( + (dac, $inst:ident) => { impl crate::dac::sealed::Instance for peripherals::$inst { fn regs() -> &'static crate::pac::dac::Dac { &crate::pac::$inst @@ -33,16 +34,21 @@ macro_rules! impl_dac { impl crate::dac::Instance for peripherals::$inst {} }; -} +); -macro_rules! impl_dac_pin { - ($inst:ident, $channel:expr, $pin:ident ) => { - impl crate::dac::DacPin for peripherals::$pin {} +crate::pac::peripheral_pins!( + ($inst:ident, dac, DAC, $pin:ident, OUT1) => { + impl DacPin for peripherals::$pin {} - impl crate::dac::sealed::DacPin for peripherals::$pin { - //fn af_num(&self) -> u8 { - //$af - //} + impl sealed::DacPin for peripherals::$pin { + } + + }; + + ($inst:ident, dac, DAC, $pin:ident, OUT2) => { + impl DacPin for peripherals::$pin {} + + impl sealed::DacPin for peripherals::$pin { } }; -} +); diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index aef31ce7..773cdc8b 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -8,6 +8,7 @@ mod _version; pub use _version::*; use crate::pac; +use crate::peripherals; pub(crate) mod sealed { use super::*; @@ -31,8 +32,8 @@ pub trait Channel: sealed::Channel + Sized {} macro_rules! impl_dma_channel { ($type:ident, $dma_num:expr, $ch_num:expr) => { - impl crate::dma::Channel for peripherals::$type {} - impl crate::dma::sealed::Channel for peripherals::$type { + impl Channel for peripherals::$type {} + impl sealed::Channel for peripherals::$type { #[inline] fn num(&self) -> u8 { $dma_num * 8 + $ch_num @@ -40,3 +41,27 @@ macro_rules! impl_dma_channel { } }; } + +crate::pac::peripherals!( + (dma,DMA1) => { + impl_dma_channel!(DMA1_CH0, 0, 0); + impl_dma_channel!(DMA1_CH1, 0, 1); + impl_dma_channel!(DMA1_CH2, 0, 2); + impl_dma_channel!(DMA1_CH3, 0, 3); + impl_dma_channel!(DMA1_CH4, 0, 4); + impl_dma_channel!(DMA1_CH5, 0, 5); + impl_dma_channel!(DMA1_CH6, 0, 6); + impl_dma_channel!(DMA1_CH7, 0, 7); + }; + + (dma,DMA2) => { + impl_dma_channel!(DMA2_CH0, 1, 0); + impl_dma_channel!(DMA2_CH1, 1, 1); + impl_dma_channel!(DMA2_CH2, 1, 2); + impl_dma_channel!(DMA2_CH3, 1, 3); + impl_dma_channel!(DMA2_CH4, 1, 4); + impl_dma_channel!(DMA2_CH5, 1, 5); + impl_dma_channel!(DMA2_CH6, 1, 6); + impl_dma_channel!(DMA2_CH7, 1, 7); + }; +); diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 61c28aa7..90d4afd5 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -212,25 +212,63 @@ impl_exti!(EXTI13, 13); impl_exti!(EXTI14, 14); impl_exti!(EXTI15, 15); -pub(crate) unsafe fn init() {} +macro_rules! foreach_exti_irq { + ($action:ident) => { + crate::pac::interrupts!( + (EXTI0) => { $action!(EXTI0); }; + (EXTI1) => { $action!(EXTI1); }; + (EXTI2) => { $action!(EXTI2); }; + (EXTI3) => { $action!(EXTI3); }; + (EXTI4) => { $action!(EXTI4); }; + (EXTI5) => { $action!(EXTI5); }; + (EXTI6) => { $action!(EXTI6); }; + (EXTI7) => { $action!(EXTI7); }; + (EXTI8) => { $action!(EXTI8); }; + (EXTI9) => { $action!(EXTI9); }; + (EXTI10) => { $action!(EXTI10); }; + (EXTI11) => { $action!(EXTI11); }; + (EXTI12) => { $action!(EXTI12); }; + (EXTI13) => { $action!(EXTI13); }; + (EXTI14) => { $action!(EXTI14); }; + (EXTI15) => { $action!(EXTI15); }; -macro_rules! impl_exti_irq { - ($($e:ident),+) => { - /// safety: must be called only once - pub(crate) unsafe fn init_exti() { - use embassy::interrupt::Interrupt; - use embassy::interrupt::InterruptExt; - - $( - crate::interrupt::$e::steal().enable(); - )+ - } - - $( - #[crate::interrupt] - unsafe fn $e() { - crate::exti::on_irq() - } - )+ + // plus the weird ones + (EXTI0_1) => { $action!( EXTI0_1 ); }; + (EXTI15_10) => { $action!(EXTI15_10); }; + (EXTI15_4) => { $action!(EXTI15_4); }; + (EXTI1_0) => { $action!(EXTI1_0); }; + (EXTI2_3) => { $action!(EXTI2_3); }; + (EXTI2_TSC) => { $action!(EXTI2_TSC); }; + (EXTI3_2) => { $action!(EXTI3_2); }; + (EXTI4_15) => { $action!(EXTI4_15); }; + (EXTI9_5) => { $action!(EXTI9_5); }; + ); }; } + +macro_rules! enable_irq { + ($e:ident) => { + crate::interrupt::$e::steal().enable(); + }; +} + +/// safety: must be called only once +pub(crate) unsafe fn init() { + use embassy::interrupt::Interrupt; + use embassy::interrupt::InterruptExt; + + foreach_exti_irq!(enable_irq); +} + +use crate::interrupt; + +macro_rules! impl_irq { + ($e:ident) => { + #[interrupt] + unsafe fn $e() { + on_irq() + } + }; +} + +foreach_exti_irq!(impl_irq); diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 7b0dd816..0f9414c5 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -3,6 +3,7 @@ #[cfg_attr(i2c_v1, path = "v1.rs")] #[cfg_attr(i2c_v2, path = "v2.rs")] mod _version; +use crate::peripherals; pub use _version::*; pub enum Error { @@ -37,26 +38,37 @@ pub trait SclPin: sealed::SclPin + 'static {} pub trait SdaPin: sealed::SdaPin + 'static {} -macro_rules! impl_i2c { - ($inst:ident) => { - impl crate::i2c::sealed::Instance for peripherals::$inst { +crate::pac::peripherals!( + (i2c, $inst:ident) => { + impl sealed::Instance for peripherals::$inst { fn regs() -> &'static crate::pac::i2c::I2c { &crate::pac::$inst } } - impl crate::i2c::Instance for peripherals::$inst {} + impl Instance for peripherals::$inst {} + }; -} +); -macro_rules! impl_i2c_pin { - ($inst:ident, $pin_func:ident, $pin:ident, $af:expr) => { - impl crate::i2c::$pin_func for peripherals::$pin {} +macro_rules! impl_pin { + ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { + impl $signal for peripherals::$pin {} - impl crate::i2c::sealed::$pin_func for peripherals::$pin { + impl sealed::$signal for peripherals::$pin { fn af_num(&self) -> u8 { $af } } }; } + +crate::pac::peripheral_pins!( + ($inst:ident, i2c, I2C, $pin:ident, SDA, $af:expr) => { + impl_pin!($inst, $pin, SdaPin, $af); + }; + + ($inst:ident, i2c, I2C, $pin:ident, SCL, $af:expr) => { + impl_pin!($inst, $pin, SclPin, $af); + }; +); diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index c51f93eb..c205bc49 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(); rcc::init(config.rcc); } diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 694ad4a1..704f1a97 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -9,6 +9,7 @@ use futures::future::poll_fn; use rand_core::{CryptoRng, RngCore}; use crate::pac; +use crate::peripherals; pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new(); @@ -134,16 +135,20 @@ pub(crate) mod sealed { pub trait Instance: sealed::Instance {} -macro_rules! impl_rng { - ($inst:ident, $irq:ident) => { - impl crate::rng::sealed::Instance for peripherals::RNG { +crate::pac::peripherals!( + (rng, $inst:ident) => { + impl Instance for peripherals::$inst {} + + impl sealed::Instance for peripherals::$inst { fn regs() -> crate::pac::rng::Rng { crate::pac::RNG } } + }; +); - impl crate::rng::Instance for peripherals::RNG {} - +macro_rules! irq { + ($irq:ident) => { mod rng_irq { use crate::interrupt; @@ -158,3 +163,25 @@ macro_rules! impl_rng { } }; } + +crate::pac::interrupts!( + (RNG) => { + irq!(RNG); + }; + + (RNG_LPUART1) => { + irq!(RNG_LPUART1); + }; + + (AES_RNG_LPUART1) => { + irq!(AES_RNG_LPUART1); + }; + + (AES_RNG) => { + irq!(AES_RNG); + }; + + (HASH_RNG) => { + irq!(HASH_RNG); + }; +); 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..2c7f8ac0 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,13 +1470,13 @@ 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 { - const INNER: crate::sdmmc::SdmmcInner = crate::sdmmc::SdmmcInner(crate::pac::$inst); + fn inner() -> SdmmcInner { + const INNER: SdmmcInner = 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 sealed::$signal for peripherals::$pin { + const AF_NUM: u8 = $af; } - impl crate::sdmmc::$func for peripherals::$pin {} + impl $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::*; diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index d8bd66d9..730169ec 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -4,6 +4,7 @@ #[cfg_attr(spi_v2, path = "v2.rs")] #[cfg_attr(spi_v3, path = "v3.rs")] mod _version; +use crate::peripherals; pub use _version::*; use crate::gpio::Pin; @@ -71,26 +72,40 @@ pub trait MosiPin: sealed::MosiPin + 'static {} pub trait MisoPin: sealed::MisoPin + 'static {} -macro_rules! impl_spi { - ($inst:ident, $clk:ident) => { - impl crate::spi::sealed::Instance for peripherals::$inst { +crate::pac::peripherals!( + (spi, $inst:ident) => { + impl sealed::Instance for peripherals::$inst { fn regs() -> &'static crate::pac::spi::Spi { &crate::pac::$inst } } - impl crate::spi::Instance for peripherals::$inst {} + impl Instance for peripherals::$inst {} }; -} +); -macro_rules! impl_spi_pin { - ($inst:ident, $pin_func:ident, $pin:ident, $af:expr) => { - impl crate::spi::$pin_func for peripherals::$pin {} +macro_rules! impl_pin { + ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { + impl $signal for peripherals::$pin {} - impl crate::spi::sealed::$pin_func for peripherals::$pin { + impl sealed::$signal for peripherals::$pin { fn af_num(&self) -> u8 { $af } } }; } + +crate::pac::peripheral_pins!( + ($inst:ident, spi, SPI, $pin:ident, SCK, $af:expr) => { + impl_pin!($inst, $pin, SckPin, $af); + }; + + ($inst:ident, spi, SPI, $pin:ident, MOSI, $af:expr) => { + impl_pin!($inst, $pin, MosiPin, $af); + }; + + ($inst:ident, spi, SPI, $pin:ident, MISO, $af:expr) => { + impl_pin!($inst, $pin, MisoPin, $af); + }; +); diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 77b217c3..adf48c32 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -3,6 +3,7 @@ #[cfg_attr(usart_v1, path = "v1.rs")] #[cfg_attr(usart_v2, path = "v2.rs")] mod _version; +use crate::peripherals; pub use _version::*; use crate::gpio::Pin; @@ -51,24 +52,48 @@ pub trait CtsPin: sealed::CtsPin {} pub trait RtsPin: sealed::RtsPin {} pub trait CkPin: sealed::CkPin {} -macro_rules! impl_usart { - ($inst:ident) => { - impl crate::usart::sealed::Instance for peripherals::$inst { +crate::pac::peripherals!( + (usart, $inst:ident) => { + impl sealed::Instance for peripherals::$inst { fn regs(&self) -> crate::pac::usart::Usart { crate::pac::$inst } } - impl crate::usart::Instance for peripherals::$inst {} - }; -} -macro_rules! impl_usart_pin { - ($inst:ident, $func:ident, $pin:ident, $af:expr) => { - impl crate::usart::sealed::$func for peripherals::$pin { + impl Instance for peripherals::$inst {} + }; +); + +macro_rules! impl_pin { + ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { + impl sealed::$signal for peripherals::$pin { fn af_num(&self) -> u8 { $af } } - impl crate::usart::$func for peripherals::$pin {} + + impl $signal for peripherals::$pin {} }; } + +crate::pac::peripheral_pins!( + ($inst:ident, usart, USART, $pin:ident, TX, $af:expr) => { + impl_pin!($inst, $pin, TxPin, $af); + }; + + ($inst:ident, usart, USART, $pin:ident, RX, $af:expr) => { + impl_pin!($inst, $pin, RxPin, $af); + }; + + ($inst:ident, usart, USART, $pin:ident, CTS, $af:expr) => { + impl_pin!($inst, $pin, CtsPin, $af); + }; + + ($inst:ident, usart, USART, $pin:ident, RTS, $af:expr) => { + impl_pin!($inst, $pin, RtsPin, $af); + }; + + ($inst:ident, usart, USART, $pin:ident, CK, $af:expr) => { + impl_pin!($inst, $pin, CkPin, $af); + }; +); diff --git a/stm32-data b/stm32-data index dfc67fe2..33dfa674 160000 --- a/stm32-data +++ b/stm32-data @@ -1 +1 @@ -Subproject commit dfc67fe255e1e70101e9f1e3fb8b4fd8bb37362f +Subproject commit 33dfa674865b1b5f0bfb86f3217055a6a057a6fb diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs index 49ca7620..ef95f331 100644 --- a/stm32-metapac/build.rs +++ b/stm32-metapac/build.rs @@ -40,12 +40,24 @@ pub struct Peripheral { pub block: Option, #[serde(default)] pub clock: Option, + #[serde(default)] + pub pins: Vec, +} + +#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] +pub struct Pin { + pub pin: String, + pub signal: String, + pub af: Option, } struct BlockInfo { - module: String, // usart_v1/USART -> usart - version: String, // usart_v1/USART -> v1 - block: String, // usart_v1/USART -> USART + /// usart_v1/USART -> usart + module: String, + /// usart_v1/USART -> v1 + version: String, + /// usart_v1/USART -> USART + block: String, } impl BlockInfo { @@ -123,6 +135,8 @@ fn main() { let mut cfgs: HashSet = HashSet::new(); let mut pin_table: Vec> = Vec::new(); let mut interrupt_table: Vec> = Vec::new(); + let mut peripherals_table: Vec> = Vec::new(); + let mut peripheral_pins_table: Vec> = Vec::new(); let dma_base = chip .peripherals @@ -149,8 +163,25 @@ fn main() { if let Some(block) = &p.block { let bi = BlockInfo::parse(block); + for pin in &p.pins { + let mut row = Vec::new(); + row.push(name.clone()); + row.push(bi.module.clone()); + row.push(bi.block.clone()); + row.push(pin.pin.clone()); + row.push(pin.signal.clone()); + if let Some(ref af) = pin.af { + row.push(af.clone()); + } + 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); if let Some(old_version) = peripheral_versions.insert(bi.module.clone(), bi.version.clone()) @@ -226,7 +257,9 @@ fn main() { make_table(&mut extra, "pins", &pin_table); make_table(&mut extra, "interrupts", &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); for (module, version) in peripheral_versions { println!("loading {} {}", module, version);