diff options
| author | xoviat <[email protected]> | 2025-11-04 12:26:37 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-11-04 12:26:37 -0600 |
| commit | 488d06c0e9da673f770b41d8f79bf26227dc6d53 (patch) | |
| tree | 6112eab36b08caccc0ea9f6b4389c90b84f564d7 /embassy-stm32/src/rtc | |
| parent | 871189d198b4c8876e8dba36b9cf43bbfd64391c (diff) | |
stm32/stop: move stop_with_rtc into init
Diffstat (limited to 'embassy-stm32/src/rtc')
| -rw-r--r-- | embassy-stm32/src/rtc/mod.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index bc6df528b..a26637d18 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -8,6 +8,8 @@ mod low_power; | |||
| 8 | use core::cell::Cell; | 8 | use core::cell::Cell; |
| 9 | 9 | ||
| 10 | #[cfg(feature = "low-power")] | 10 | #[cfg(feature = "low-power")] |
| 11 | use critical_section::CriticalSection; | ||
| 12 | #[cfg(feature = "low-power")] | ||
| 11 | use embassy_sync::blocking_mutex::Mutex; | 13 | use embassy_sync::blocking_mutex::Mutex; |
| 12 | #[cfg(feature = "low-power")] | 14 | #[cfg(feature = "low-power")] |
| 13 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 15 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| @@ -44,11 +46,18 @@ pub enum RtcError { | |||
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | /// Provides immutable access to the current time of the RTC. | 48 | /// Provides immutable access to the current time of the RTC. |
| 49 | #[derive(Clone)] | ||
| 47 | pub struct RtcTimeProvider { | 50 | pub struct RtcTimeProvider { |
| 48 | _private: (), | 51 | _private: (), |
| 49 | } | 52 | } |
| 50 | 53 | ||
| 51 | impl RtcTimeProvider { | 54 | impl RtcTimeProvider { |
| 55 | #[cfg(feature = "low-power")] | ||
| 56 | /// Create a new RTC time provider instance. | ||
| 57 | pub fn new(_rtc: Peri<'static, RTC>) -> Self { | ||
| 58 | Self { _private: () } | ||
| 59 | } | ||
| 60 | |||
| 52 | /// Return the current datetime. | 61 | /// Return the current datetime. |
| 53 | /// | 62 | /// |
| 54 | /// # Errors | 63 | /// # Errors |
| @@ -145,8 +154,19 @@ pub enum RtcCalibrationCyclePeriod { | |||
| 145 | } | 154 | } |
| 146 | 155 | ||
| 147 | impl Rtc { | 156 | impl Rtc { |
| 157 | #[cfg(feature = "low-power")] | ||
| 158 | /// Create a new RTC instance. | ||
| 159 | pub(crate) fn new(rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { | ||
| 160 | Self::new_inner(rtc, rtc_config) | ||
| 161 | } | ||
| 162 | |||
| 163 | #[cfg(not(feature = "low-power"))] | ||
| 148 | /// Create a new RTC instance. | 164 | /// Create a new RTC instance. |
| 149 | pub fn new(_rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { | 165 | pub fn new(rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { |
| 166 | Self::new_inner(rtc, rtc_config) | ||
| 167 | } | ||
| 168 | |||
| 169 | fn new_inner(_rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { | ||
| 150 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] | 170 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] |
| 151 | crate::rcc::enable_and_reset::<RTC>(); | 171 | crate::rcc::enable_and_reset::<RTC>(); |
| 152 | 172 | ||
| @@ -315,3 +335,13 @@ trait SealedInstance { | |||
| 315 | 335 | ||
| 316 | // fn apply_config(&mut self, rtc_config: RtcConfig); | 336 | // fn apply_config(&mut self, rtc_config: RtcConfig); |
| 317 | } | 337 | } |
| 338 | |||
| 339 | #[cfg(feature = "low-power")] | ||
| 340 | pub(crate) fn init_rtc(_cs: CriticalSection, config: RtcConfig) { | ||
| 341 | let rtc = Rtc::new(unsafe { core::mem::transmute(()) }, config); | ||
| 342 | |||
| 343 | crate::time_driver::get_driver().set_rtc(rtc); | ||
| 344 | crate::time_driver::get_driver().reconfigure_rtc(|rtc| rtc.enable_wakeup_line()); | ||
| 345 | |||
| 346 | trace!("low power: stop with rtc configured"); | ||
| 347 | } | ||
