aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2021-05-19 10:42:10 +0200
committerDario Nieuwenhuis <[email protected]>2021-05-21 18:38:33 +0200
commit9fa5a2920feefb29451c2e2fbdfb4d2c07bc208c (patch)
tree0347f125a03ae2b6218f462bf7d5b86ccd4774ff /embassy-stm32
parent0cd3236fa3640263faa703f439b29c1a81bc0465 (diff)
Move regs trait implementation into generated pac
This allows handling devices that don't have DMA2
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/gen.py2
-rw-r--r--embassy-stm32/src/dma/mod.rs14
2 files changed, 7 insertions, 9 deletions
diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py
index 5ba05fa3a..845b297c7 100644
--- a/embassy-stm32/gen.py
+++ b/embassy-stm32/gen.py
@@ -151,7 +151,7 @@ for chip in chips.values():
151 for ch_num in range(8): 151 for ch_num in range(8):
152 channel = f'{name}_CH{ch_num}' 152 channel = f'{name}_CH{ch_num}'
153 peripheral_names.append(channel) 153 peripheral_names.append(channel)
154 f.write(f'impl_dma_channel!({channel}, {dma_num}, {ch_num});') 154 f.write(f'impl_dma_channel!({name}, {channel}, {dma_num}, {ch_num});')
155 155
156 if peri['block'] == 'sdmmc_v2/SDMMC': 156 if peri['block'] == 'sdmmc_v2/SDMMC':
157 f.write(f'impl_sdmmc!({name});') 157 f.write(f'impl_sdmmc!({name});')
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index 974b95f2f..54eed9d4c 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -20,26 +20,24 @@ pub(crate) mod sealed {
20 fn ch_num(&self) -> u8 { 20 fn ch_num(&self) -> u8 {
21 self.num() % 8 21 self.num() % 8
22 } 22 }
23 23 fn regs(&self) -> pac::dma::Dma;
24 fn regs(&self) -> pac::dma::Dma {
25 match self.dma_num() {
26 0 => pac::DMA1,
27 _ => pac::DMA2,
28 }
29 }
30 } 24 }
31} 25}
32 26
33pub trait Channel: sealed::Channel + Sized {} 27pub trait Channel: sealed::Channel + Sized {}
34 28
35macro_rules! impl_dma_channel { 29macro_rules! impl_dma_channel {
36 ($type:ident, $dma_num:expr, $ch_num:expr) => { 30 ($name:ident, $type:ident, $dma_num:expr, $ch_num:expr) => {
37 impl crate::dma::Channel for peripherals::$type {} 31 impl crate::dma::Channel for peripherals::$type {}
38 impl crate::dma::sealed::Channel for peripherals::$type { 32 impl crate::dma::sealed::Channel for peripherals::$type {
39 #[inline] 33 #[inline]
40 fn num(&self) -> u8 { 34 fn num(&self) -> u8 {
41 $dma_num * 8 + $ch_num 35 $dma_num * 8 + $ch_num
42 } 36 }
37
38 fn regs(&self) -> dma::Dma {
39 $name
40 }
43 } 41 }
44 }; 42 };
45} 43}