From 9fa5a2920feefb29451c2e2fbdfb4d2c07bc208c Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 19 May 2021 10:42:10 +0200 Subject: [PATCH] Move regs trait implementation into generated pac This allows handling devices that don't have DMA2 --- embassy-stm32/gen.py | 2 +- embassy-stm32/src/dma/mod.rs | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 5ba05fa3..845b297c 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py @@ -151,7 +151,7 @@ for chip in chips.values(): for ch_num in range(8): channel = f'{name}_CH{ch_num}' peripheral_names.append(channel) - f.write(f'impl_dma_channel!({channel}, {dma_num}, {ch_num});') + f.write(f'impl_dma_channel!({name}, {channel}, {dma_num}, {ch_num});') if peri['block'] == 'sdmmc_v2/SDMMC': f.write(f'impl_sdmmc!({name});') diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 974b95f2..54eed9d4 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -20,26 +20,24 @@ pub(crate) mod sealed { fn ch_num(&self) -> u8 { self.num() % 8 } - - fn regs(&self) -> pac::dma::Dma { - match self.dma_num() { - 0 => pac::DMA1, - _ => pac::DMA2, - } - } + fn regs(&self) -> pac::dma::Dma; } } pub trait Channel: sealed::Channel + Sized {} macro_rules! impl_dma_channel { - ($type:ident, $dma_num:expr, $ch_num:expr) => { + ($name:ident, $type:ident, $dma_num:expr, $ch_num:expr) => { impl crate::dma::Channel for peripherals::$type {} impl crate::dma::sealed::Channel for peripherals::$type { #[inline] fn num(&self) -> u8 { $dma_num * 8 + $ch_num } + + fn regs(&self) -> dma::Dma { + $name + } } }; }