aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/build.rs57
-rw-r--r--embassy-stm32/src/dcmi.rs9
-rw-r--r--embassy-stm32/src/i2c/mod.rs9
-rw-r--r--embassy-stm32/src/spi/mod.rs9
-rw-r--r--embassy-stm32/src/traits.rs8
-rw-r--r--embassy-stm32/src/usart/mod.rs15
6 files changed, 60 insertions, 47 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index 6bef745f1..fd9a07ced 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -1,6 +1,6 @@
1use proc_macro2::TokenStream; 1use proc_macro2::TokenStream;
2use quote::{format_ident, quote}; 2use quote::{format_ident, quote};
3use std::collections::HashSet; 3use std::collections::{HashMap, HashSet};
4use std::env; 4use std::env;
5use std::fs; 5use std::fs;
6use std::path::PathBuf; 6use std::path::PathBuf;
@@ -231,6 +231,61 @@ fn main() {
231 } 231 }
232 232
233 // ======== 233 // ========
234 // Generate dma_trait_impl!
235
236 let signals: HashMap<_, _> = [
237 // (kind, signal) => trait
238 (("usart", "RX"), quote!(crate::usart::RxDma)),
239 (("usart", "TX"), quote!(crate::usart::TxDma)),
240 (("spi", "RX"), quote!(crate::spi::RxDma)),
241 (("spi", "TX"), quote!(crate::spi::TxDma)),
242 (("i2c", "RX"), quote!(crate::i2c::RxDma)),
243 (("i2c", "TX"), quote!(crate::i2c::TxDma)),
244 (("dcmi", "DCMI"), quote!(crate::dcmi::FrameDma)),
245 (("dcmi", "PSSI"), quote!(crate::dcmi::FrameDma)),
246 ]
247 .into();
248
249 for p in METADATA.peripherals {
250 if let Some(regs) = &p.registers {
251 let mut dupe = HashSet::new();
252 for ch in p.dma_channels {
253 // Some chips have multiple request numbers for the same (peri, signal, channel) combos.
254 // Ignore the dupes, picking the first one. Otherwise this causes conflicting trait impls
255 let key = (ch.signal, ch.channel);
256 if !dupe.insert(key) {
257 continue;
258 }
259
260 if let Some(tr) = signals.get(&(regs.kind, ch.signal)) {
261 let peri = format_ident!("{}", p.name);
262
263 let channel = if let Some(channel) = &ch.channel {
264 let channel = format_ident!("{}", channel);
265 quote!({channel: #channel})
266 } else if let Some(dmamux) = &ch.dmamux {
267 let dmamux = format_ident!("{}", dmamux);
268 quote!({dmamux: #dmamux})
269 } else {
270 unreachable!();
271 };
272
273 let request = if let Some(request) = ch.request {
274 let request = request as u8;
275 quote!(#request)
276 } else {
277 quote!(())
278 };
279
280 g.extend(quote! {
281 dma_trait_impl!(#tr, #peri, #channel, #request);
282 });
283 }
284 }
285 }
286 }
287
288 // ========
234 // Write generated.rs 289 // Write generated.rs
235 290
236 let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); 291 let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs
index 1fa19e87a..ff6f09701 100644
--- a/embassy-stm32/src/dcmi.rs
+++ b/embassy-stm32/src/dcmi.rs
@@ -482,15 +482,6 @@ crate::pac::interrupts! {
482 482
483dma_trait!(FrameDma, Instance); 483dma_trait!(FrameDma, Instance);
484 484
485crate::pac::peripheral_dma_channels! {
486 ($peri:ident, dcmi, $kind:ident, PSSI, $channel:tt, $request:expr) => {
487 dma_trait_impl!(FrameDma, $peri, $channel, $request);
488 };
489 ($peri:ident, dcmi, $kind:ident, DCMI, $channel:tt, $request:expr) => {
490 dma_trait_impl!(FrameDma, $peri, $channel, $request);
491 };
492}
493
494crate::pac::peripheral_pins!( 485crate::pac::peripheral_pins!(
495 ($inst:ident, dcmi, DCMI, $pin:ident, D0, $af:expr) => { 486 ($inst:ident, dcmi, DCMI, $pin:ident, D0, $af:expr) => {
496 pin_trait_impl!(D0Pin, $inst, $pin, $af); 487 pin_trait_impl!(D0Pin, $inst, $pin, $af);
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs
index 0980fd9e8..ff13d9f1f 100644
--- a/embassy-stm32/src/i2c/mod.rs
+++ b/embassy-stm32/src/i2c/mod.rs
@@ -91,12 +91,3 @@ crate::pac::peripheral_pins!(
91 pin_trait_impl!(SdaPin, $inst, $pin, 0); 91 pin_trait_impl!(SdaPin, $inst, $pin, 0);
92 }; 92 };
93); 93);
94
95crate::pac::peripheral_dma_channels! {
96 ($peri:ident, i2c, $kind:ident, RX, $channel:tt, $request:expr) => {
97 dma_trait_impl!(RxDma, $peri, $channel, $request);
98 };
99 ($peri:ident, i2c, $kind:ident, TX, $channel:tt, $request:expr) => {
100 dma_trait_impl!(TxDma, $peri, $channel, $request);
101 };
102}
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index 04f95820f..e91241e97 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -911,12 +911,3 @@ crate::pac::peripheral_pins!(
911 pin_trait_impl!(MisoPin, $inst, $pin, 0); 911 pin_trait_impl!(MisoPin, $inst, $pin, 0);
912 }; 912 };
913); 913);
914
915crate::pac::peripheral_dma_channels! {
916 ($peri:ident, spi, $kind:ident, RX, $channel:tt, $request:expr) => {
917 dma_trait_impl!(RxDma, $peri, $channel, $request);
918 };
919 ($peri:ident, spi, $kind:ident, TX, $channel:tt, $request:expr) => {
920 dma_trait_impl!(TxDma, $peri, $channel, $request);
921 };
922}
diff --git a/embassy-stm32/src/traits.rs b/embassy-stm32/src/traits.rs
index b27628703..e006e31ac 100644
--- a/embassy-stm32/src/traits.rs
+++ b/embassy-stm32/src/traits.rs
@@ -31,8 +31,8 @@ macro_rules! dma_trait {
31#[allow(unused)] 31#[allow(unused)]
32macro_rules! dma_trait_impl { 32macro_rules! dma_trait_impl {
33 // DMAMUX 33 // DMAMUX
34 ($signal:ident, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => { 34 (crate::$mod:ident::$trait:ident, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => {
35 impl<T> $signal<crate::peripherals::$instance> for T 35 impl<T> crate::$mod::$trait<crate::peripherals::$instance> for T
36 where 36 where
37 T: crate::dma::MuxChannel<Mux = crate::dma::$dmamux>, 37 T: crate::dma::MuxChannel<Mux = crate::dma::$dmamux>,
38 { 38 {
@@ -43,8 +43,8 @@ macro_rules! dma_trait_impl {
43 }; 43 };
44 44
45 // No DMAMUX 45 // No DMAMUX
46 ($signal:ident, $instance:ident, {channel: $channel:ident}, $request:expr) => { 46 (crate::$mod:ident::$trait:ident, $instance:ident, {channel: $channel:ident}, $request:expr) => {
47 impl $signal<crate::peripherals::$instance> for crate::peripherals::$channel { 47 impl crate::$mod::$trait<crate::peripherals::$instance> for crate::peripherals::$channel {
48 fn request(&self) -> crate::dma::Request { 48 fn request(&self) -> crate::dma::Request {
49 $request 49 $request
50 } 50 }
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index 718559813..52c2cd84f 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -712,18 +712,3 @@ crate::pac::peripheral_pins!(
712 pin_trait_impl!(CkPin, $inst, $pin, 0); 712 pin_trait_impl!(CkPin, $inst, $pin, 0);
713 }; 713 };
714); 714);
715
716crate::pac::peripheral_dma_channels! {
717 ($peri:ident, usart, $kind:ident, RX, $channel:tt, $request:expr) => {
718 dma_trait_impl!(RxDma, $peri, $channel, $request);
719 };
720 ($peri:ident, usart, $kind:ident, TX, $channel:tt, $request:expr) => {
721 dma_trait_impl!(TxDma, $peri, $channel, $request);
722 };
723 ($peri:ident, uart, $kind:ident, RX, $channel:tt, $request:expr) => {
724 dma_trait_impl!(RxDma, $peri, $channel, $request);
725 };
726 ($peri:ident, uart, $kind:ident, TX, $channel:tt, $request:expr) => {
727 dma_trait_impl!(TxDma, $peri, $channel, $request);
728 };
729}