diff options
| author | xoviat <[email protected]> | 2025-11-04 16:35:07 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-11-04 16:35:07 -0600 |
| commit | b9559c7713bc7f773cdef0df14f1158840d06d06 (patch) | |
| tree | d5e126d6c2d891bb47375925353e155177954699 /tests/stm32/src/bin/rtc.rs | |
| parent | d23c027dd1a1c5f7cdf818750dddf6a250658423 (diff) | |
rtc: use consistent api between stop and non-stop
Diffstat (limited to 'tests/stm32/src/bin/rtc.rs')
| -rw-r--r-- | tests/stm32/src/bin/rtc.rs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs index 5c80eb250..43cf4a411 100644 --- a/tests/stm32/src/bin/rtc.rs +++ b/tests/stm32/src/bin/rtc.rs | |||
| @@ -9,11 +9,9 @@ use chrono::{NaiveDate, NaiveDateTime}; | |||
| 9 | use common::*; | 9 | use common::*; |
| 10 | use defmt::assert; | 10 | use defmt::assert; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | #[cfg(feature = "stop")] | ||
| 13 | use embassy_stm32::low_power::reconfigure_rtc; | ||
| 14 | use embassy_stm32::rcc::LsConfig; | 12 | use embassy_stm32::rcc::LsConfig; |
| 15 | #[cfg(feature = "stop")] | 13 | #[cfg(feature = "stop")] |
| 16 | use embassy_stm32::rtc::RtcTimeProvider; | 14 | use embassy_stm32::rtc::Rtc; |
| 17 | #[cfg(not(feature = "stop"))] | 15 | #[cfg(not(feature = "stop"))] |
| 18 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 16 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 19 | use embassy_time::Timer; | 17 | use embassy_time::Timer; |
| @@ -31,23 +29,22 @@ async fn main(_spawner: Spawner) { | |||
| 31 | .unwrap(); | 29 | .unwrap(); |
| 32 | 30 | ||
| 33 | #[cfg(not(feature = "stop"))] | 31 | #[cfg(not(feature = "stop"))] |
| 34 | let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); | 32 | let (mut rtc, time_provider) = Rtc::new(p.RTC, RtcConfig::default()); |
| 35 | 33 | ||
| 36 | #[cfg(feature = "stop")] | 34 | #[cfg(feature = "stop")] |
| 37 | let time_provider = RtcTimeProvider::new(p.RTC); | 35 | let (rtc, time_provider) = Rtc::new(p.RTC); |
| 38 | 36 | ||
| 39 | #[cfg(not(feature = "stop"))] | 37 | #[cfg(not(feature = "stop"))] |
| 40 | rtc.set_datetime(now.into()).expect("datetime not set"); | 38 | rtc.set_datetime(now.into()).expect("datetime not set"); |
| 41 | 39 | ||
| 42 | #[cfg(feature = "stop")] | 40 | #[cfg(feature = "stop")] |
| 43 | reconfigure_rtc(|rtc| rtc.set_datetime(now.into()).expect("datetime not set")); | 41 | critical_section::with(|cs| { |
| 42 | rtc.borrow_mut(cs).set_datetime(now.into()).expect("datetime not set"); | ||
| 43 | }); | ||
| 44 | 44 | ||
| 45 | info!("Waiting 5 seconds"); | 45 | info!("Waiting 5 seconds"); |
| 46 | Timer::after_millis(5000).await; | 46 | Timer::after_millis(5000).await; |
| 47 | 47 | ||
| 48 | #[cfg(not(feature = "stop"))] | ||
| 49 | let then: NaiveDateTime = rtc.now().unwrap().into(); | ||
| 50 | #[cfg(feature = "stop")] | ||
| 51 | let then: NaiveDateTime = time_provider.now().unwrap().into(); | 48 | let then: NaiveDateTime = time_provider.now().unwrap().into(); |
| 52 | 49 | ||
| 53 | let seconds = (then - now).num_seconds(); | 50 | let seconds = (then - now).num_seconds(); |
