From 6a84554788b18d36c1177d7bbfd9fda2fbb1c9b2 Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 4 Nov 2025 13:00:22 -0600 Subject: minor rtc opt --- embassy-stm32/src/rtc/mod.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index a26637d18..2c25e1e36 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -154,19 +154,13 @@ pub enum RtcCalibrationCyclePeriod { } impl Rtc { - #[cfg(feature = "low-power")] - /// Create a new RTC instance. - pub(crate) fn new(rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { - Self::new_inner(rtc, rtc_config) - } - #[cfg(not(feature = "low-power"))] /// Create a new RTC instance. - pub fn new(rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { - Self::new_inner(rtc, rtc_config) + pub fn new(_rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { + Self::new_inner(rtc_config, false) } - fn new_inner(_rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { + pub(self) fn new_inner(rtc_config: RtcConfig, enable_wakeup_line: bool) -> Self { #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] crate::rcc::enable_and_reset::(); @@ -189,6 +183,10 @@ impl Rtc { while now == this.time_provider().read(|_, _, ss| Ok(ss)).unwrap() {} } + if enable_wakeup_line { + this.enable_wakeup_line(); + } + this } @@ -338,10 +336,7 @@ trait SealedInstance { #[cfg(feature = "low-power")] pub(crate) fn init_rtc(_cs: CriticalSection, config: RtcConfig) { - let rtc = Rtc::new(unsafe { core::mem::transmute(()) }, config); - - crate::time_driver::get_driver().set_rtc(rtc); - crate::time_driver::get_driver().reconfigure_rtc(|rtc| rtc.enable_wakeup_line()); + crate::time_driver::get_driver().set_rtc(Rtc::new_inner(config, true)); trace!("low power: stop with rtc configured"); } -- cgit