diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index e8645ccf..55612cb3 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py @@ -48,20 +48,20 @@ 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 == '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']: 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); + }; +);