aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/gen.py5
-rw-r--r--embassy-stm32/src/dma/mod.rs29
2 files changed, 27 insertions, 7 deletions
diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py
index ddd4a3b88..2736cd69d 100644
--- a/embassy-stm32/gen.py
+++ b/embassy-stm32/gen.py
@@ -60,15 +60,10 @@ with open(output_file, 'w') as f:
60 60
61 if block_mod == 'dma': 61 if block_mod == 'dma':
62 custom_singletons = True 62 custom_singletons = True
63 num_dmas += 1
64 dma_num = int(name[3:])-1 # substract 1 because we want DMA1=0, DMA2=1
65
66 for ch_num in range(8): 63 for ch_num in range(8):
67 channel = f'{name}_CH{ch_num}' 64 channel = f'{name}_CH{ch_num}'
68 singletons.append(channel) 65 singletons.append(channel)
69 66
70 f.write(f'impl_dma_channel!({channel}, {dma_num}, {ch_num});')
71
72 if not custom_singletons: 67 if not custom_singletons:
73 singletons.append(name) 68 singletons.append(name)
74 69
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index aef31ce74..773cdc8b8 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -8,6 +8,7 @@ mod _version;
8pub use _version::*; 8pub use _version::*;
9 9
10use crate::pac; 10use crate::pac;
11use crate::peripherals;
11 12
12pub(crate) mod sealed { 13pub(crate) mod sealed {
13 use super::*; 14 use super::*;
@@ -31,8 +32,8 @@ pub trait Channel: sealed::Channel + Sized {}
31 32
32macro_rules! impl_dma_channel { 33macro_rules! impl_dma_channel {
33 ($type:ident, $dma_num:expr, $ch_num:expr) => { 34 ($type:ident, $dma_num:expr, $ch_num:expr) => {
34 impl crate::dma::Channel for peripherals::$type {} 35 impl Channel for peripherals::$type {}
35 impl crate::dma::sealed::Channel for peripherals::$type { 36 impl sealed::Channel for peripherals::$type {
36 #[inline] 37 #[inline]
37 fn num(&self) -> u8 { 38 fn num(&self) -> u8 {
38 $dma_num * 8 + $ch_num 39 $dma_num * 8 + $ch_num
@@ -40,3 +41,27 @@ macro_rules! impl_dma_channel {
40 } 41 }
41 }; 42 };
42} 43}
44
45crate::pac::peripherals!(
46 (dma,DMA1) => {
47 impl_dma_channel!(DMA1_CH0, 0, 0);
48 impl_dma_channel!(DMA1_CH1, 0, 1);
49 impl_dma_channel!(DMA1_CH2, 0, 2);
50 impl_dma_channel!(DMA1_CH3, 0, 3);
51 impl_dma_channel!(DMA1_CH4, 0, 4);
52 impl_dma_channel!(DMA1_CH5, 0, 5);
53 impl_dma_channel!(DMA1_CH6, 0, 6);
54 impl_dma_channel!(DMA1_CH7, 0, 7);
55 };
56
57 (dma,DMA2) => {
58 impl_dma_channel!(DMA2_CH0, 1, 0);
59 impl_dma_channel!(DMA2_CH1, 1, 1);
60 impl_dma_channel!(DMA2_CH2, 1, 2);
61 impl_dma_channel!(DMA2_CH3, 1, 3);
62 impl_dma_channel!(DMA2_CH4, 1, 4);
63 impl_dma_channel!(DMA2_CH5, 1, 5);
64 impl_dma_channel!(DMA2_CH6, 1, 6);
65 impl_dma_channel!(DMA2_CH7, 1, 7);
66 };
67);