diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-23 18:42:33 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-23 18:42:33 +0000 |
| commit | 042e7d6de7771f3b70cc7a1e9c46661dc68f1042 (patch) | |
| tree | dd52a905209c7821c6adc09b990882df46a7fcfe | |
| parent | bc053404caa801ff00f021525e5adb34bc1d3fb1 (diff) | |
| parent | 2c8fee59d6e663a9f6825b6c02cb58090fb160a5 (diff) | |
Merge #638
638: stm32: move dma trait impls from macrotables to build.rs r=Dirbaio a=Dirbaio
Continuation of work from #601
Co-authored-by: Dario Nieuwenhuis <[email protected]>
| -rw-r--r-- | embassy-stm32/build.rs | 57 | ||||
| -rw-r--r-- | embassy-stm32/src/dcmi.rs | 9 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/mod.rs | 9 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 9 | ||||
| -rw-r--r-- | embassy-stm32/src/traits.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 15 | ||||
| -rw-r--r-- | stm32-metapac-gen/src/lib.rs | 35 |
7 files changed, 60 insertions, 82 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 @@ | |||
| 1 | use proc_macro2::TokenStream; | 1 | use proc_macro2::TokenStream; |
| 2 | use quote::{format_ident, quote}; | 2 | use quote::{format_ident, quote}; |
| 3 | use std::collections::HashSet; | 3 | use std::collections::{HashMap, HashSet}; |
| 4 | use std::env; | 4 | use std::env; |
| 5 | use std::fs; | 5 | use std::fs; |
| 6 | use std::path::PathBuf; | 6 | use 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 | ||
| 483 | dma_trait!(FrameDma, Instance); | 483 | dma_trait!(FrameDma, Instance); |
| 484 | 484 | ||
| 485 | crate::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 | |||
| 494 | crate::pac::peripheral_pins!( | 485 | crate::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 | |||
| 95 | crate::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 | |||
| 915 | crate::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)] |
| 32 | macro_rules! dma_trait_impl { | 32 | macro_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 | |||
| 716 | crate::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 | } | ||
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 10d67869a..d167da49c 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs | |||
| @@ -127,7 +127,6 @@ pub fn gen_chip( | |||
| 127 | let mut peripherals_table: Vec<Vec<String>> = Vec::new(); | 127 | let mut peripherals_table: Vec<Vec<String>> = Vec::new(); |
| 128 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); | 128 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); |
| 129 | let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); | 129 | let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); |
| 130 | let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); | ||
| 131 | let mut peripheral_counts: BTreeMap<String, u8> = BTreeMap::new(); | 130 | let mut peripheral_counts: BTreeMap<String, u8> = BTreeMap::new(); |
| 132 | let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new(); | 131 | let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new(); |
| 133 | let mut dbgmcu_table: Vec<Vec<String>> = Vec::new(); | 132 | let mut dbgmcu_table: Vec<Vec<String>> = Vec::new(); |
| @@ -198,35 +197,6 @@ pub fn gen_chip( | |||
| 198 | interrupt_table.push(row) | 197 | interrupt_table.push(row) |
| 199 | } | 198 | } |
| 200 | 199 | ||
| 201 | for ch in &p.dma_channels { | ||
| 202 | let mut row = Vec::new(); | ||
| 203 | row.push(p.name.clone()); | ||
| 204 | row.push(bi.kind.clone()); | ||
| 205 | row.push(bi.block.clone()); | ||
| 206 | row.push(ch.signal.clone()); | ||
| 207 | row.push(if let Some(channel) = &ch.channel { | ||
| 208 | format!("{{channel: {}}}", channel) | ||
| 209 | } else if let Some(dmamux) = &ch.dmamux { | ||
| 210 | format!("{{dmamux: {}}}", dmamux) | ||
| 211 | } else { | ||
| 212 | unreachable!(); | ||
| 213 | }); | ||
| 214 | |||
| 215 | row.push(if let Some(request) = ch.request { | ||
| 216 | request.to_string() | ||
| 217 | } else { | ||
| 218 | "()".to_string() | ||
| 219 | }); | ||
| 220 | |||
| 221 | if peripheral_dma_channels_table | ||
| 222 | .iter() | ||
| 223 | .find(|a| a[..a.len() - 1] == row[..row.len() - 1]) | ||
| 224 | .is_none() | ||
| 225 | { | ||
| 226 | peripheral_dma_channels_table.push(row); | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | let mut peripheral_row = Vec::new(); | 200 | let mut peripheral_row = Vec::new(); |
| 231 | peripheral_row.push(bi.kind.clone()); | 201 | peripheral_row.push(bi.kind.clone()); |
| 232 | peripheral_row.push(p.name.clone()); | 202 | peripheral_row.push(p.name.clone()); |
| @@ -388,11 +358,6 @@ pub fn gen_chip( | |||
| 388 | make_table(&mut data, "peripherals", &peripherals_table); | 358 | make_table(&mut data, "peripherals", &peripherals_table); |
| 389 | make_table(&mut data, "peripheral_versions", &peripheral_version_table); | 359 | make_table(&mut data, "peripheral_versions", &peripheral_version_table); |
| 390 | make_table(&mut data, "peripheral_pins", &peripheral_pins_table); | 360 | make_table(&mut data, "peripheral_pins", &peripheral_pins_table); |
| 391 | make_table( | ||
| 392 | &mut data, | ||
| 393 | "peripheral_dma_channels", | ||
| 394 | &peripheral_dma_channels_table, | ||
| 395 | ); | ||
| 396 | make_table(&mut data, "dma_channels", &dma_channels_table); | 361 | make_table(&mut data, "dma_channels", &dma_channels_table); |
| 397 | make_table(&mut data, "dbgmcu", &dbgmcu_table); | 362 | make_table(&mut data, "dbgmcu", &dbgmcu_table); |
| 398 | make_peripheral_counts(&mut data, &peripheral_counts); | 363 | make_peripheral_counts(&mut data, &peripheral_counts); |
