stm32/rtc: remove generics and segregate clock sel
This commit is contained in:
@ -1,13 +1,12 @@
|
||||
use stm32_metapac::rtc::vals::{Init, Osel, Pol};
|
||||
|
||||
use super::{sealed, Instance, RtcClockSource, RtcConfig};
|
||||
use super::{sealed, RtcClockSource, RtcConfig};
|
||||
use crate::pac::rtc::Rtc;
|
||||
use crate::peripherals::RTC;
|
||||
use crate::rtc::sealed::Instance;
|
||||
|
||||
impl<'d, T: Instance> super::Rtc<'d, T> {
|
||||
pub(super) fn enable(clock_source: RtcClockSource) {
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
use stm32_metapac::rcc::vals::Rtcsel;
|
||||
|
||||
impl super::Rtc {
|
||||
fn unlock_registers() {
|
||||
#[cfg(any(rtc_v2f2, rtc_v2f3, rtc_v2l1))]
|
||||
let cr = crate::pac::PWR.cr();
|
||||
#[cfg(any(rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))]
|
||||
@ -16,10 +15,35 @@ impl<'d, T: Instance> super::Rtc<'d, T> {
|
||||
// TODO: Missing from PAC for l0 and f0?
|
||||
#[cfg(not(any(rtc_v2f0, rtc_v2l0)))]
|
||||
{
|
||||
cr.modify(|w| w.set_dbp(true));
|
||||
while !cr.read().dbp() {}
|
||||
if !cr.read().dbp() {
|
||||
cr.modify(|w| w.set_dbp(true));
|
||||
while !cr.read().dbp() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_clock_source(clock_source: RtcClockSource) {
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
use stm32_metapac::rcc::vals::Rtcsel;
|
||||
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
let cr = crate::pac::RCC.bdcr();
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
let cr = crate::pac::RCC.csr();
|
||||
|
||||
Self::unlock_registers();
|
||||
|
||||
cr.modify(|w| {
|
||||
// Select RTC source
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
w.set_rtcsel(Rtcsel::from_bits(clock_source as u8));
|
||||
#[cfg(rtc_v2wb)]
|
||||
w.set_rtcsel(clock_source as u8);
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn enable() {
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
let reg = crate::pac::RCC.bdcr().read();
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
@ -28,12 +52,9 @@ impl<'d, T: Instance> super::Rtc<'d, T> {
|
||||
#[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb))]
|
||||
assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
|
||||
|
||||
#[cfg(rtc_v2wb)]
|
||||
let rtcsel = reg.rtcsel();
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
let rtcsel = reg.rtcsel().to_bits();
|
||||
if !reg.rtcen() {
|
||||
Self::unlock_registers();
|
||||
|
||||
if !reg.rtcen() || rtcsel != clock_source as u8 {
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1, rtc_v2f2)))]
|
||||
crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true));
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
@ -46,12 +67,8 @@ impl<'d, T: Instance> super::Rtc<'d, T> {
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
w.set_bdrst(false);
|
||||
|
||||
// Select RTC source
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
w.set_rtcsel(Rtcsel::from_bits(clock_source as u8));
|
||||
#[cfg(rtc_v2wb)]
|
||||
w.set_rtcsel(clock_source as u8);
|
||||
w.set_rtcen(true);
|
||||
w.set_rtcsel(reg.rtcsel());
|
||||
|
||||
// Restore bcdr
|
||||
#[cfg(any(rtc_v2l4, rtc_v2wb))]
|
||||
@ -157,7 +174,7 @@ impl<'d, T: Instance> super::Rtc<'d, T> {
|
||||
where
|
||||
F: FnOnce(&crate::pac::rtc::Rtc) -> R,
|
||||
{
|
||||
let r = T::regs();
|
||||
let r = RTC::regs();
|
||||
// Disable write protection.
|
||||
// This is safe, as we're only writin the correct and expected values.
|
||||
r.wpr().write(|w| w.set_key(0xca));
|
||||
@ -218,5 +235,3 @@ impl sealed::Instance for crate::peripherals::RTC {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Instance for crate::peripherals::RTC {}
|
||||
|
Reference in New Issue
Block a user