aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/build.rs
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 /embassy-stm32/build.rs
parent60b640bd977ac2d056061e0c0b7a497f815417f4 (diff)
stm32: peri_v1_bar now enables cfgs peri_v1 and peri_v1_bar.
Diffstat (limited to 'embassy-stm32/build.rs')
-rw-r--r--embassy-stm32/build.rs29
1 files changed, 27 insertions, 2 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