Move to a single Mux Struct.

This commit is contained in:
Eli Orona 2024-02-20 17:54:35 -08:00
parent e99ef49611
commit 2ee9b37373
3 changed files with 18 additions and 22 deletions

View file

@ -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 )*
}

View file

@ -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,

View file

@ -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