From 6534b63e01b1f7d16f62743f007a2e9c43f9ec56 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Mon, 12 Jul 2021 14:53:19 -0400 Subject: [PATCH] Simplify some macros around dmamux peripheral channels. --- embassy-stm32/src/dmamux/mod.rs | 51 ++++++++++++--------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/embassy-stm32/src/dmamux/mod.rs b/embassy-stm32/src/dmamux/mod.rs index 0f3fb9a8..f6625146 100644 --- a/embassy-stm32/src/dmamux/mod.rs +++ b/embassy-stm32/src/dmamux/mod.rs @@ -100,54 +100,41 @@ peripherals! { }; } +#[allow(unused)] +macro_rules! impl_peripheral_channel { + ($channel_peri:ident, $direction:ident, $peri:ident, $request:expr) => { + impl sealed::PeripheralChannel + for peripherals::$channel_peri + { + fn request(&self) -> u8 { + $request + } + } + + impl PeripheralChannel for peripherals::$channel_peri {} + }; +} + #[allow(unused)] macro_rules! impl_usart_dma_requests { ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { dma_requests! { - // TODO: DRY this up. (usart, $peri:ident, RX, $request:expr) => { - impl sealed::PeripheralChannel for peripherals::$channel_peri { - fn request(&self) -> u8 { - $request - } - } - - impl PeripheralChannel for peripherals::$channel_peri { } - + impl_peripheral_channel($channel_peri, P2M, $peri, $request); }; (usart, $peri:ident, TX, $request:expr) => { - impl sealed::PeripheralChannel for peripherals::$channel_peri { - fn request(&self) -> u8 { - $request - } - } - - impl PeripheralChannel for peripherals::$channel_peri { } - + impl_peripheral_channel($channel_peri, M2P, $peri, $request); }; (uart, $peri:ident, TX, $request:expr) => { - impl sealed::PeripheralChannel for peripherals::$channel_peri { - fn request(&self) -> u8 { - $request - } - } - - impl PeripheralChannel for peripherals::$channel_peri { } + impl_peripheral_channel($channel_peri, P2M, $peri, $request); }; (uart, $peri:ident, RX, $request:expr) => { - impl sealed::PeripheralChannel for peripherals::$channel_peri { - fn request(&self) -> u8 { - $request - } - } - - impl PeripheralChannel for peripherals::$channel_peri { } + impl_peripheral_channel($channel_peri, M2P, $peri, $request); }; } - }; }