From a886e97a33690cf9724dedd272d3073a577f9fa4 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 18 Dec 2025 09:13:05 -0600 Subject: stm32: use datemath to resume time --- embassy-stm32/src/rtc/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'embassy-stm32/src/rtc/mod.rs') diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index e88bd7ab2..94ba13ae1 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -5,7 +5,7 @@ mod datetime; mod low_power; #[cfg(feature = "low-power")] -use core::cell::{Cell, RefCell, RefMut}; +use core::cell::{RefCell, RefMut}; #[cfg(feature = "low-power")] use core::ops; @@ -163,7 +163,7 @@ impl<'a> ops::DerefMut for RtcBorrow<'a> { /// RTC driver. pub struct Rtc { #[cfg(feature = "low-power")] - stop_time: Mutex>>, + epoch: chrono::DateTime, _private: (), } @@ -225,7 +225,7 @@ impl Rtc { let mut this = Self { #[cfg(feature = "low-power")] - stop_time: Mutex::const_new(CriticalSectionRawMutex::new(), Cell::new(None)), + epoch: chrono::DateTime::from_timestamp_secs(0).unwrap(), _private: (), }; @@ -243,7 +243,10 @@ impl Rtc { } #[cfg(feature = "low-power")] - this.enable_wakeup_line(); + { + this.enable_wakeup_line(); + this.epoch = this.calc_epoch(); + } this } @@ -293,6 +296,11 @@ impl Rtc { }); }); + #[cfg(feature = "low-power")] + { + self.epoch = self.calc_epoch(); + } + Ok(()) } -- cgit