From 2ee9b373738cf78cf784bf8753a7f55568f85d9b Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Tue, 20 Feb 2024 17:54:35 -0800 Subject: [PATCH] Move to a single Mux Struct. --- embassy-stm32/build.rs | 26 ++++++++++---------------- embassy-stm32/src/rcc/f013.rs | 12 ++++++------ embassy-stm32/src/rcc/mod.rs | 2 ++ 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index f45a571f2..2ffbadfc3 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -430,7 +430,7 @@ fn main() { let mut clock_names = BTreeSet::new(); - let mut rcc_cfgr_regs = BTreeMap::new(); + let mut rcc_cfgr_regs = BTreeSet::new(); for p in METADATA.peripherals { if !singletons.contains(&p.name.to_string()) { @@ -510,11 +510,7 @@ fn main() { let field_name = format_ident!("{}", field_name); let enum_name = format_ident!("{}", enum_name); - if !rcc_cfgr_regs.contains_key(mux.register) { - rcc_cfgr_regs.insert(mux.register, Vec::new()); - } - - rcc_cfgr_regs.get_mut(mux.register).unwrap().push(( + rcc_cfgr_regs.insert(( fieldset_name.clone(), field_name.clone(), enum_name.clone(), @@ -602,10 +598,10 @@ fn main() { } } - for (rcc_cfgr_reg, fields) in rcc_cfgr_regs { - println!("cargo:rustc-cfg={}", rcc_cfgr_reg.to_ascii_lowercase()); + if !rcc_cfgr_regs.is_empty() { + println!("cargo:rustc-cfg=clock_mux"); - let struct_fields: Vec<_> = fields + let struct_fields: Vec<_> = rcc_cfgr_regs .iter() .map(|(_fieldset, fieldname, enum_name)| { quote! { @@ -614,12 +610,12 @@ fn main() { }) .collect(); - let field_names: Vec<_> = fields + let field_names: Vec<_> = rcc_cfgr_regs .iter() .map(|(_fieldset, fieldname, _enum_name)| fieldname) .collect(); - let inits: Vec<_> = fields + let inits: Vec<_> = rcc_cfgr_regs .iter() .map(|(fieldset, fieldname, _enum_name)| { let setter = format_ident!("set_{}", fieldname); @@ -635,15 +631,13 @@ fn main() { }) .collect(); - let cfgr_reg = format_ident!("{}", rcc_cfgr_reg); - g.extend(quote! { #[derive(Clone, Copy)] - pub struct #cfgr_reg { + pub struct ClockMux { #( #struct_fields, )* } - impl Default for #cfgr_reg { + impl Default for ClockMux { fn default() -> Self { Self { #( #field_names: None, )* @@ -651,7 +645,7 @@ fn main() { } } - impl #cfgr_reg { + impl ClockMux { pub fn init(self) { #( #inits )* } diff --git a/embassy-stm32/src/rcc/f013.rs b/embassy-stm32/src/rcc/f013.rs index a61aae0e8..86af4bd68 100644 --- a/embassy-stm32/src/rcc/f013.rs +++ b/embassy-stm32/src/rcc/f013.rs @@ -99,8 +99,8 @@ pub struct Config { pub adc34: AdcClockSource, #[cfg(stm32f334)] pub hrtim: HrtimClockSource, - #[cfg(cfgr3)] - pub cfgr3: crate::_generated::CFGR3, + #[cfg(clock_mux)] + pub mux: crate::rcc::ClockMux, pub ls: super::LsConfig, } @@ -130,8 +130,8 @@ impl Default for Config { adc34: AdcClockSource::Hclk(AdcHclkPrescaler::Div1), #[cfg(stm32f334)] hrtim: HrtimClockSource::BusClk, - #[cfg(cfgr3)] - cfgr3: Default::default(), + #[cfg(clock_mux)] + mux: Default::default(), } } } @@ -367,8 +367,8 @@ pub(crate) unsafe fn init(config: Config) { } }; - #[cfg(cfgr3)] - config.cfgr3.init(); + #[cfg(clock_mux)] + config.mux.init(); set_clocks!( hsi: hsi, diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 0f3467151..f71211925 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs @@ -32,6 +32,8 @@ mod _version; pub use _version::*; pub use crate::_generated::Clocks; +#[cfg(clock_mux)] +pub use crate::_generated::ClockMux; #[cfg(feature = "low-power")] /// Must be written within a critical section