aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/bdma/mod.rs67
1 files changed, 29 insertions, 38 deletions
diff --git a/embassy-stm32/src/bdma/mod.rs b/embassy-stm32/src/bdma/mod.rs
index d36361e4c..b94563e32 100644
--- a/embassy-stm32/src/bdma/mod.rs
+++ b/embassy-stm32/src/bdma/mod.rs
@@ -150,7 +150,7 @@ unsafe fn on_irq() {
150 (bdma, $dma:ident) => { 150 (bdma, $dma:ident) => {
151 let isr = pac::$dma.isr().read(); 151 let isr = pac::$dma.isr().read();
152 pac::$dma.ifcr().write_value(isr); 152 pac::$dma.ifcr().write_value(isr);
153 let dman = <crate::peripherals::$dma as sealed::Dma>::num() as usize; 153 let dman = <crate::peripherals::$dma as sealed::Dma>::NUM as usize;
154 154
155 for chn in 0..crate::pac::dma_channels_count!($dma) { 155 for chn in 0..crate::pac::dma_channels_count!($dma) {
156 let n = dman * 8 + chn; 156 let n = dman * 8 + chn;
@@ -186,18 +186,18 @@ pub(crate) mod sealed {
186 use super::*; 186 use super::*;
187 187
188 pub trait Dma { 188 pub trait Dma {
189 fn num() -> u8; 189 const NUM: u8;
190 } 190 }
191 191
192 pub trait Channel { 192 pub trait Channel {
193 const CH_NUM: u8;
194
193 fn dma_regs() -> pac::bdma::Dma; 195 fn dma_regs() -> pac::bdma::Dma;
194 196
195 fn state_num(&self) -> usize; 197 fn state_num(&self) -> usize;
196 198
197 fn ch_num(&self) -> u8;
198
199 fn regs(&self) -> pac::bdma::Ch { 199 fn regs(&self) -> pac::bdma::Ch {
200 Self::dma_regs().ch(self.ch_num() as usize) 200 Self::dma_regs().ch(Self::CH_NUM as usize)
201 } 201 }
202 } 202 }
203} 203}
@@ -206,31 +206,27 @@ pub trait Dma: sealed::Dma + Sized {}
206pub trait Channel: sealed::Channel + Sized {} 206pub trait Channel: sealed::Channel + Sized {}
207 207
208macro_rules! impl_dma { 208macro_rules! impl_dma {
209 ($peri:ident, $num:expr) => { 209 ($peri:ident) => {
210 impl Dma for crate::peripherals::$peri {} 210 impl Dma for crate::peripherals::$peri {}
211 impl sealed::Dma for crate::peripherals::$peri { 211 impl sealed::Dma for crate::peripherals::$peri {
212 fn num() -> u8 { 212 const NUM: u8 = dma_num!($peri);
213 $num
214 }
215 } 213 }
216 }; 214 };
217} 215}
218 216
219macro_rules! impl_dma_channel { 217macro_rules! impl_dma_channel {
220 ($channel_peri:ident, $dma_peri:ident, $dma_num:expr, $ch_num:expr) => { 218 ($channel_peri:ident, $dma_peri:ident, $ch_num:expr) => {
221 impl Channel for crate::peripherals::$channel_peri {} 219 impl Channel for crate::peripherals::$channel_peri {}
222 impl sealed::Channel for crate::peripherals::$channel_peri { 220 impl sealed::Channel for crate::peripherals::$channel_peri {
221 const CH_NUM: u8 = $ch_num;
222
223 #[inline] 223 #[inline]
224 fn dma_regs() -> pac::bdma::Dma { 224 fn dma_regs() -> pac::bdma::Dma {
225 crate::pac::$dma_peri 225 crate::pac::$dma_peri
226 } 226 }
227 227
228 fn state_num(&self) -> usize { 228 fn state_num(&self) -> usize {
229 ($dma_num * 8) + $ch_num 229 (dma_num!($dma_peri) * 8) + $ch_num
230 }
231
232 fn ch_num(&self) -> u8 {
233 $ch_num
234 } 230 }
235 } 231 }
236 232
@@ -363,31 +359,26 @@ macro_rules! impl_dma_channel {
363 }; 359 };
364} 360}
365 361
366pac::peripherals! { 362macro_rules! dma_num {
367 (bdma, DMA1) => { 363 (DMA1) => {
368 impl_dma!(DMA1, 0); 364 0
369 pac::bdma_channels! {
370 ($channel_peri:ident, DMA1, $channel_num:expr) => {
371 impl_dma_channel!($channel_peri, DMA1, 0, $channel_num);
372 };
373 }
374 }; 365 };
375 (bdma, DMA2) => { 366 (DMA2) => {
376 impl_dma!(DMA2, 1); 367 1
377 pac::bdma_channels! {
378 ($channel_peri:ident, DMA2, $channel_num:expr) => {
379 impl_dma_channel!($channel_peri, DMA2, 1, $channel_num);
380 };
381 }
382 }; 368 };
383 // Because H7cm changes the naming 369 (BDMA) => {
384 (bdma, BDMA) => { 370 0
385 impl_dma!(BDMA, 0); 371 };
386 pac::bdma_channels! { 372}
387 ($channel_peri:ident, BDMA, $channel_num:expr) => { 373pac::peripherals! {
388 impl_dma_channel!($channel_peri, BDMA, 0, $channel_num); 374 (bdma, $peri:ident) => {
389 }; 375 impl_dma!($peri);
390 } 376 };
377}
378
379pac::bdma_channels! {
380 ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => {
381 impl_dma_channel!($channel_peri, $dma_peri, $channel_num);
391 }; 382 };
392} 383}
393 384