feat(stm32-l): provide a const constructor on rcc::Config

This commit is contained in:
ROMemories 2025-05-21 11:17:59 +02:00
parent 156bf00009
commit 65a22439d5
3 changed files with 30 additions and 13 deletions

View File

@ -92,6 +92,16 @@ pub struct LsConfig {
} }
impl LsConfig { impl LsConfig {
pub const fn new() -> Self {
// on L5, just the fact that LSI is enabled makes things crash.
// TODO: investigate.
#[cfg(not(stm32l5))]
return Self::default_lsi();
#[cfg(stm32l5)]
return Self::off();
}
pub const fn default_lse() -> Self { pub const fn default_lse() -> Self {
Self { Self {
rtc: RtcClockSource::LSE, rtc: RtcClockSource::LSE,
@ -124,13 +134,7 @@ impl LsConfig {
impl Default for LsConfig { impl Default for LsConfig {
fn default() -> Self { fn default() -> Self {
// on L5, just the fact that LSI is enabled makes things crash. Self::new()
// TODO: investigate.
#[cfg(not(stm32l5))]
return Self::default_lsi();
#[cfg(stm32l5)]
return Self::off();
} }
} }

View File

@ -18,9 +18,15 @@ pub struct Hsi48Config {
pub sync_from_usb: bool, pub sync_from_usb: bool,
} }
impl Hsi48Config {
pub const fn new() -> Self {
Self { sync_from_usb: false }
}
}
impl Default for Hsi48Config { impl Default for Hsi48Config {
fn default() -> Self { fn default() -> Self {
Self { sync_from_usb: false } Self::new()
} }
} }

View File

@ -68,9 +68,9 @@ pub struct Config {
pub mux: super::mux::ClockMux, pub mux: super::mux::ClockMux,
} }
impl Default for Config { impl Config {
#[inline] #[inline]
fn default() -> Config { pub const fn new() -> Self {
Config { Config {
hse: None, hse: None,
hsi: false, hsi: false,
@ -90,15 +90,22 @@ impl Default for Config {
#[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))] #[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))]
pllsai2: None, pllsai2: None,
#[cfg(crs)] #[cfg(crs)]
hsi48: Some(Default::default()), hsi48: Some(crate::rcc::Hsi48Config::new()),
ls: Default::default(), ls: crate::rcc::LsConfig::new(),
#[cfg(any(stm32l0, stm32l1))] #[cfg(any(stm32l0, stm32l1))]
voltage_scale: VoltageScale::RANGE1, voltage_scale: VoltageScale::RANGE1,
mux: Default::default(), mux: super::mux::ClockMux::default(),
} }
} }
} }
impl Default for Config {
#[inline]
fn default() -> Config {
Self::new()
}
}
#[cfg(stm32wb)] #[cfg(stm32wb)]
pub const WPAN_DEFAULT: Config = Config { pub const WPAN_DEFAULT: Config = Config {
hse: Some(Hse { hse: Some(Hse {