diff options
| author | xoviat <[email protected]> | 2023-08-06 11:58:28 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-08-06 11:58:28 -0500 |
| commit | 28618d12a11a73a5c0c4e2b176b7096796f79cdb (patch) | |
| tree | 7ea43543b60c1b1191f129ab0ecfbe1a453d499f /embassy-stm32/src/rtc/v3.rs | |
| parent | 66c171211822e9b680976f73f971ac27e5870934 (diff) | |
stm32/rtc: restructure
Diffstat (limited to 'embassy-stm32/src/rtc/v3.rs')
| -rw-r--r-- | embassy-stm32/src/rtc/v3.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index 8ef0ec51d..64ecf4fbd 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs | |||
| @@ -1,12 +1,10 @@ | |||
| 1 | use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Init, Key, Osel, Pol, TampalrmPu, TampalrmType}; | 1 | use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Init, Key, Osel, Pol, TampalrmPu, TampalrmType}; |
| 2 | 2 | ||
| 3 | use super::{sealed, Instance, RtcCalibrationCyclePeriod, RtcConfig}; | 3 | use super::{sealed, Instance, RtcCalibrationCyclePeriod, RtcClockSource, RtcConfig}; |
| 4 | use crate::pac::rtc::Rtc; | 4 | use crate::pac::rtc::Rtc; |
| 5 | 5 | ||
| 6 | impl<'d, T: Instance> super::Rtc<'d, T> { | 6 | impl<'d, T: Instance> super::Rtc<'d, T> { |
| 7 | /// Applies the RTC config | 7 | pub(super) fn enable(clock_source: RtcClockSource) { |
| 8 | /// It this changes the RTC clock source the time will be reset | ||
| 9 | pub(super) fn apply_config(&mut self, rtc_config: RtcConfig) { | ||
| 10 | // Unlock the backup domain | 8 | // Unlock the backup domain |
| 11 | #[cfg(not(any(rtc_v3u5, rcc_wl5, rcc_wle)))] | 9 | #[cfg(not(any(rtc_v3u5, rcc_wl5, rcc_wle)))] |
| 12 | { | 10 | { |
| @@ -24,11 +22,10 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 24 | let reg = crate::pac::RCC.bdcr().read(); | 22 | let reg = crate::pac::RCC.bdcr().read(); |
| 25 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); | 23 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); |
| 26 | 24 | ||
| 27 | let config_rtcsel = rtc_config.clock_config as u8; | ||
| 28 | #[cfg(not(any(rcc_wl5, rcc_wle)))] | 25 | #[cfg(not(any(rcc_wl5, rcc_wle)))] |
| 29 | let config_rtcsel = crate::pac::rcc::vals::Rtcsel::from_bits(config_rtcsel); | 26 | let config_rtcsel = crate::pac::rcc::vals::Rtcsel::from_bits(clock_source as u8); |
| 30 | 27 | ||
| 31 | if !reg.rtcen() || reg.rtcsel() != config_rtcsel { | 28 | if !reg.rtcen() || reg.rtcsel() != clock_source as u8 { |
| 32 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); | 29 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); |
| 33 | 30 | ||
| 34 | crate::pac::RCC.bdcr().modify(|w| { | 31 | crate::pac::RCC.bdcr().modify(|w| { |
| @@ -36,7 +33,7 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 36 | w.set_bdrst(false); | 33 | w.set_bdrst(false); |
| 37 | 34 | ||
| 38 | // Select RTC source | 35 | // Select RTC source |
| 39 | w.set_rtcsel(config_rtcsel); | 36 | w.set_rtcsel(clock_source as u8); |
| 40 | 37 | ||
| 41 | w.set_rtcen(true); | 38 | w.set_rtcen(true); |
| 42 | 39 | ||
| @@ -49,7 +46,11 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 49 | w.set_lsebyp(reg.lsebyp()); | 46 | w.set_lsebyp(reg.lsebyp()); |
| 50 | }); | 47 | }); |
| 51 | } | 48 | } |
| 49 | } | ||
| 52 | 50 | ||
| 51 | /// Applies the RTC config | ||
| 52 | /// It this changes the RTC clock source the time will be reset | ||
| 53 | pub(super) fn configure(&mut self, rtc_config: RtcConfig) { | ||
| 53 | self.write(true, |rtc| { | 54 | self.write(true, |rtc| { |
| 54 | rtc.cr().modify(|w| { | 55 | rtc.cr().modify(|w| { |
| 55 | w.set_fmt(Fmt::TWENTYFOURHOUR); | 56 | w.set_fmt(Fmt::TWENTYFOURHOUR); |
| @@ -69,8 +70,6 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 69 | w.set_tampalrm_pu(TampalrmPu::NOPULLUP); | 70 | w.set_tampalrm_pu(TampalrmPu::NOPULLUP); |
| 70 | }); | 71 | }); |
| 71 | }); | 72 | }); |
| 72 | |||
| 73 | self.rtc_config = rtc_config; | ||
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | const RTC_CALR_MIN_PPM: f32 = -487.1; | 75 | const RTC_CALR_MIN_PPM: f32 = -487.1; |
