stm32/bd: consolidate enable_rtc

This commit is contained in:
xoviat 2023-08-28 15:34:08 -05:00
parent b315c28d4e
commit 70a5221b2e

View File

@ -87,13 +87,14 @@ impl BackupDomain {
} }
#[cfg(any( #[cfg(any(
rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb, rtc_v3,
rtc_v3u5
))] ))]
#[allow(dead_code)] #[allow(dead_code)]
pub fn enable_rtc() { pub fn enable_rtc() {
let reg = Self::read(); let reg = Self::read();
#[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb))] #[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))]
assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
if !reg.rtcen() { if !reg.rtcen() {
@ -102,47 +103,21 @@ impl BackupDomain {
Self::modify(|w| { Self::modify(|w| {
// Reset // Reset
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))] #[cfg(not(any(rtc_v2l0, rtc_v2l1, rtc_v2f2)))]
w.set_bdrst(false); w.set_bdrst(false);
w.set_rtcen(true); w.set_rtcen(true);
w.set_rtcsel(reg.rtcsel()); w.set_rtcsel(reg.rtcsel());
// Restore bcdr // Restore bcdr
#[cfg(any(rtc_v2l4, rtc_v2wb))] #[cfg(any(rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))]
w.set_lscosel(reg.lscosel()); w.set_lscosel(reg.lscosel());
#[cfg(any(rtc_v2l4, rtc_v2wb))] #[cfg(any(rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))]
w.set_lscoen(reg.lscoen()); w.set_lscoen(reg.lscoen());
w.set_lseon(reg.lseon()); w.set_lseon(reg.lseon());
#[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))] #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))]
w.set_lsedrv(reg.lsedrv());
w.set_lsebyp(reg.lsebyp());
});
}
}
#[cfg(any(rtc_v3, rtc_v3u5))]
#[allow(dead_code)]
pub fn enable_rtc() {
let reg = Self::read();
assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
if !reg.rtcen() {
Self::modify(|w| w.set_bdrst(true));
Self::modify(|w| {
w.set_bdrst(false);
w.set_rtcen(true);
w.set_rtcsel(reg.rtcsel());
// Restore bcdr
w.set_lscosel(reg.lscosel());
w.set_lscoen(reg.lscoen());
w.set_lseon(reg.lseon());
w.set_lsedrv(reg.lsedrv()); w.set_lsedrv(reg.lsedrv());
w.set_lsebyp(reg.lsebyp()); w.set_lsebyp(reg.lsebyp());
}); });