aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-08-31 23:48:51 +0200
committerDario Nieuwenhuis <[email protected]>2025-09-05 15:19:22 +0200
commit90d403fd0a33ac7a3cde4fe9c417b5976b924020 (patch)
treebb3c16e68dd05d8c6d093e3c58752bfa22c4da39
parent60b640bd977ac2d056061e0c0b7a497f815417f4 (diff)
stm32: peri_v1_bar now enables cfgs peri_v1 and peri_v1_bar.
-rw-r--r--embassy-stm32/build.rs29
-rw-r--r--embassy-stm32/src/sai/mod.rs10
2 files changed, 32 insertions, 7 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index deefb13c1..b731012c6 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -16,6 +16,27 @@ use stm32_metapac::metadata::{
16#[path = "./build_common.rs"] 16#[path = "./build_common.rs"]
17mod common; 17mod common;
18 18
19/// Helper function to handle peripheral versions with underscores.
20/// For a version like "v1_foo_bar", this generates all prefix combinations:
21/// - "kind_v1"
22/// - "kind_v1_foo"
23/// - "kind_v1_foo_bar"
24fn foreach_version_cfg(
25 cfgs: &mut common::CfgSet,
26 kind: &str,
27 version: &str,
28 mut cfg_fn: impl FnMut(&mut common::CfgSet, &str),
29) {
30 let parts: Vec<&str> = version.split('_').collect();
31
32 // Generate all possible prefix combinations
33 for i in 1..=parts.len() {
34 let partial_version = parts[0..i].join("_");
35 let cfg_name = format!("{}_{}", kind, partial_version);
36 cfg_fn(cfgs, &cfg_name);
37 }
38}
39
19fn main() { 40fn main() {
20 let mut cfgs = common::CfgSet::new(); 41 let mut cfgs = common::CfgSet::new();
21 common::set_target_cfgs(&mut cfgs); 42 common::set_target_cfgs(&mut cfgs);
@@ -38,14 +59,18 @@ fn main() {
38 for p in METADATA.peripherals { 59 for p in METADATA.peripherals {
39 if let Some(r) = &p.registers { 60 if let Some(r) = &p.registers {
40 cfgs.enable(r.kind); 61 cfgs.enable(r.kind);
41 cfgs.enable(format!("{}_{}", r.kind, r.version)); 62 foreach_version_cfg(&mut cfgs, r.kind, r.version, |cfgs, cfg_name| {
63 cfgs.enable(cfg_name);
64 });
42 } 65 }
43 } 66 }
44 67
45 for &(kind, versions) in ALL_PERIPHERAL_VERSIONS.iter() { 68 for &(kind, versions) in ALL_PERIPHERAL_VERSIONS.iter() {
46 cfgs.declare(kind); 69 cfgs.declare(kind);
47 for &version in versions.iter() { 70 for &version in versions.iter() {
48 cfgs.declare(format!("{}_{}", kind, version)); 71 foreach_version_cfg(&mut cfgs, kind, version, |cfgs, cfg_name| {
72 cfgs.declare(cfg_name);
73 });
49 } 74 }
50 } 75 }
51 76
diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs
index ff81dabed..cde2a56c2 100644
--- a/embassy-stm32/src/sai/mod.rs
+++ b/embassy-stm32/src/sai/mod.rs
@@ -182,7 +182,7 @@ pub enum SyncInput {
182 /// Syncs with the other A/B sub-block within the SAI unit 182 /// Syncs with the other A/B sub-block within the SAI unit
183 Internal, 183 Internal,
184 /// Syncs with a sub-block in the other SAI unit 184 /// Syncs with a sub-block in the other SAI unit
185 #[cfg(any(sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] 185 #[cfg(any(sai_v3, sai_v4))]
186 External(SyncInputInstance), 186 External(SyncInputInstance),
187} 187}
188 188
@@ -191,14 +191,14 @@ impl SyncInput {
191 match self { 191 match self {
192 SyncInput::None => vals::Syncen::ASYNCHRONOUS, 192 SyncInput::None => vals::Syncen::ASYNCHRONOUS,
193 SyncInput::Internal => vals::Syncen::INTERNAL, 193 SyncInput::Internal => vals::Syncen::INTERNAL,
194 #[cfg(any(sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] 194 #[cfg(any(sai_v3, sai_v4))]
195 SyncInput::External(_) => vals::Syncen::EXTERNAL, 195 SyncInput::External(_) => vals::Syncen::EXTERNAL,
196 } 196 }
197 } 197 }
198} 198}
199 199
200/// SAI instance to sync from. 200/// SAI instance to sync from.
201#[cfg(any(sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] 201#[cfg(any(sai_v3, sai_v4))]
202#[derive(Copy, Clone, PartialEq)] 202#[derive(Copy, Clone, PartialEq)]
203#[allow(missing_docs)] 203#[allow(missing_docs)]
204pub enum SyncInputInstance { 204pub enum SyncInputInstance {
@@ -500,7 +500,7 @@ fn update_synchronous_config(config: &mut Config) {
500 config.sync_input = SyncInput::Internal; 500 config.sync_input = SyncInput::Internal;
501 } 501 }
502 502
503 #[cfg(any(sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] 503 #[cfg(any(sai_v3, sai_v4))]
504 { 504 {
505 //this must either be Internal or External 505 //this must either be Internal or External
506 //The asynchronous sub-block on the same SAI needs to enable sync_output 506 //The asynchronous sub-block on the same SAI needs to enable sync_output
@@ -645,7 +645,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> {
645 645
646 ch.cr2().modify(|w| w.set_fflush(true)); 646 ch.cr2().modify(|w| w.set_fflush(true));
647 647
648 #[cfg(any(sai_v3_2pdm, sai_v3_4pdm, sai_v4_2pdm, sai_v4_4pdm))] 648 #[cfg(any(sai_v3, sai_v4))]
649 { 649 {
650 if let SyncInput::External(i) = config.sync_input { 650 if let SyncInput::External(i) = config.sync_input {
651 T::REGS.gcr().modify(|w| { 651 T::REGS.gcr().modify(|w| {