diff options
| -rw-r--r-- | embassy-stm32/gen.py | 19 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/mod.rs | 10 |
2 files changed, 22 insertions, 7 deletions
diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py index 7bbf0b52c..40904e3c5 100644 --- a/embassy-stm32/gen.py +++ b/embassy-stm32/gen.py | |||
| @@ -75,6 +75,7 @@ for chip in chips.values(): | |||
| 75 | # ========= peripherals | 75 | # ========= peripherals |
| 76 | 76 | ||
| 77 | peripheral_names.extend((f'EXTI{x}' for x in range(16))) | 77 | peripheral_names.extend((f'EXTI{x}' for x in range(16))) |
| 78 | num_dmas = 0 | ||
| 78 | 79 | ||
| 79 | for (name, peri) in chip['peripherals'].items(): | 80 | for (name, peri) in chip['peripherals'].items(): |
| 80 | if 'block' not in peri: | 81 | if 'block' not in peri: |
| @@ -147,11 +148,14 @@ for chip in chips.values(): | |||
| 147 | 148 | ||
| 148 | if block_mod == 'dma': | 149 | if block_mod == 'dma': |
| 149 | custom_singletons = True | 150 | custom_singletons = True |
| 151 | num_dmas += 1 | ||
| 150 | dma_num = int(name[3:])-1 # substract 1 because we want DMA1=0, DMA2=1 | 152 | dma_num = int(name[3:])-1 # substract 1 because we want DMA1=0, DMA2=1 |
| 153 | |||
| 151 | for ch_num in range(8): | 154 | for ch_num in range(8): |
| 152 | channel = f'{name}_CH{ch_num}' | 155 | channel = f'{name}_CH{ch_num}' |
| 153 | peripheral_names.append(channel) | 156 | peripheral_names.append(channel) |
| 154 | f.write(f'impl_dma_channel!({name}, {channel}, {dma_num}, {ch_num});') | 157 | |
| 158 | f.write(f'impl_dma_channel!({channel}, {dma_num}, {ch_num});') | ||
| 155 | 159 | ||
| 156 | if peri['block'] == 'sdmmc_v2/SDMMC': | 160 | if peri['block'] == 'sdmmc_v2/SDMMC': |
| 157 | f.write(f'impl_sdmmc!({name});') | 161 | f.write(f'impl_sdmmc!({name});') |
| @@ -198,6 +202,19 @@ for chip in chips.values(): | |||
| 198 | """) | 202 | """) |
| 199 | 203 | ||
| 200 | 204 | ||
| 205 | # ========= DMA peripherals | ||
| 206 | if num_dmas > 0: | ||
| 207 | f.write(f""" | ||
| 208 | pub fn DMA(n: u8) -> dma::Dma {{ | ||
| 209 | match n {{ | ||
| 210 | """) | ||
| 211 | for n in range(num_dmas - 1): | ||
| 212 | f.write(f'{n} => DMA{n + 1},') | ||
| 213 | f.write(f""" | ||
| 214 | _ => DMA{num_dmas}, | ||
| 215 | }} | ||
| 216 | }} | ||
| 217 | """) | ||
| 201 | 218 | ||
| 202 | # ========= exti interrupts | 219 | # ========= exti interrupts |
| 203 | 220 | ||
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 54eed9d4c..7f282cde9 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -20,24 +20,22 @@ 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 | fn regs(&self) -> pac::dma::Dma; | 23 | fn regs(&self) -> pac::dma::Dma { |
| 24 | pac::DMA(self.num()) | ||
| 25 | } | ||
| 24 | } | 26 | } |
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | pub trait Channel: sealed::Channel + Sized {} | 29 | pub trait Channel: sealed::Channel + Sized {} |
| 28 | 30 | ||
| 29 | macro_rules! impl_dma_channel { | 31 | macro_rules! impl_dma_channel { |
| 30 | ($name:ident, $type:ident, $dma_num:expr, $ch_num:expr) => { | 32 | ($type:ident, $dma_num:expr, $ch_num:expr) => { |
| 31 | impl crate::dma::Channel for peripherals::$type {} | 33 | impl crate::dma::Channel for peripherals::$type {} |
| 32 | impl crate::dma::sealed::Channel for peripherals::$type { | 34 | impl crate::dma::sealed::Channel for peripherals::$type { |
| 33 | #[inline] | 35 | #[inline] |
| 34 | fn num(&self) -> u8 { | 36 | fn num(&self) -> u8 { |
| 35 | $dma_num * 8 + $ch_num | 37 | $dma_num * 8 + $ch_num |
| 36 | } | 38 | } |
| 37 | |||
| 38 | fn regs(&self) -> dma::Dma { | ||
| 39 | $name | ||
| 40 | } | ||
| 41 | } | 39 | } |
| 42 | }; | 40 | }; |
| 43 | } | 41 | } |
