From c00a85f9a9e1506c23650b27d8db5a1c5b046aa5 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Thu, 3 Jun 2021 11:31:03 -0400 Subject: [PATCH] Refactor SPI signal pin macro. --- embassy-stm32/src/spi/mod.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index a888622d..730169ec 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -84,34 +84,28 @@ crate::pac::peripherals!( }; ); -crate::pac::peripheral_pins!( - ($inst:ident, spi, SPI, $pin:ident, SCK, $af:expr) => { - impl SckPin for peripherals::$pin {} +macro_rules! impl_pin { + ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { + impl $signal for peripherals::$pin {} - impl sealed::SckPin 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 MosiPin for peripherals::$pin {} - - impl sealed::MosiPin for peripherals::$pin { - fn af_num(&self) -> u8 { - $af - } - } + impl_pin!($inst, $pin, MosiPin, $af); }; ($inst:ident, spi, SPI, $pin:ident, MISO, $af:expr) => { - impl MisoPin for peripherals::$pin {} - - impl sealed::MisoPin for peripherals::$pin { - fn af_num(&self) -> u8 { - $af - } - } + impl_pin!($inst, $pin, MisoPin, $af); }; );