pub fn try_open(
        rtc: RTC,
        prec: backup::Rtc,
        clock_source: RtcClock,
        clocks: &CoreClocks,
    ) -> Result<Self, (RTC, backup::Rtc, InitError)> {
        if !prec.is_enabled() {
            return Err((rtc, prec, InitError::RtcNotRunning));
        }

        let rcc = unsafe { &*RCC::ptr() };
        let bdcr = rcc.bdcr.read();

        let clock_source_matches =
            match (clock_source, prec.get_kernel_clk_mux()) {
                (RtcClock::Lsi, backup::RtcClkSel::LSI) => true,
                (RtcClock::Hse { divider }, backup::RtcClkSel::HSE) => {
                    rcc.cfgr.read().rtcpre().bits() == divider
                }
                (RtcClock::Lse { bypass, css, .. }, backup::RtcClkSel::LSE) => {
                    bdcr.lseon().is_on()
                        && bypass == bdcr.lsebyp().is_bypassed()
                        && css == bdcr.lsecsson().is_security_on()
                }
                _ => false,
            };
        if !clock_source_matches {
            return Err((rtc, prec, InitError::ConfigMismatch));
        }

        let clock_source_running = match clock_source {
            RtcClock::Lsi => clocks.lsi_ck().is_some(),
            RtcClock::Hse { .. } => clocks.hse_ck().is_some(),
            RtcClock::Lse { .. } => bdcr.lserdy().is_ready(),
        };
        if !clock_source_running {
            return Err((rtc, prec, InitError::ClockNotRunning));
        }

        Ok(Rtc { reg: rtc, prec })
    }
/// Opens the RTC if it is running and its configuration matches
Opens the RTC if it is running and its configuration matches
Opens the RTC if it is running and its configuration matches
pub fn try_open(
        rtc: RTC,
        prec: backup::Rtc,
        clock_source: RtcClock,
        clocks: &CoreClocks,
    ) -> Result<Self, (RTC, backup::Rtc, InitError)> {
        if !prec.is_enabled() {
            return Err((rtc, prec, InitError::RtcNotRunning));
        }
        let rcc = unsafe { &*RCC::ptr() };
        let bdcr = rcc.bdcr.read();
        let clock_source_matches =
            match (clock_source, prec.get_kernel_clk_mux()) {
                (RtcClock::Lsi, backup::RtcClkSel::LSI) => true,
                (RtcClock::Hse { divider }, backup::RtcClkSel::HSE) => {
                    rcc.cfgr.read().rtcpre().bits() == divider
                }
                (RtcClock::Lse { bypass, css, .. }, backup::RtcClkSel::LSE) => {
                    bdcr.lseon().is_on()
                        && bypass == bdcr.lsebyp().is_bypassed()
                        && css == bdcr.lsecsson().is_security_on()
                }
                _ => false,
            };
        if !clock_source_matches {
            return Err((rtc, prec, InitError::ConfigMismatch));
        }
        let clock_source_running = match clock_source {
            RtcClock::Lsi => clocks.lsi_ck().is_some(),
            RtcClock::Hse { .. } => clocks.hse_ck().is_some(),
            RtcClock::Lse { .. } => bdcr.lserdy().is_ready(),
        };
        if !clock_source_running {
            return Err((rtc, prec, InitError::ClockNotRunning));
        }
        Ok(Rtc { reg: rtc, prec })
    }
pub fn try_open ( rtc : RTC , prec : backup :: Rtc , clock_source : RtcClock , clocks : & CoreClocks , ) -> Result < Self , ( RTC , backup :: Rtc , InitError ) > { if ! prec . is_enabled ( ) { return Err ( ( rtc , prec , InitError :: RtcNotRunning ) ) ; } let rcc = unsafe { & * RCC :: ptr ( ) } ; let bdcr = rcc . bdcr . read ( ) ; let clock_source_matches = match ( clock_source , prec . get_kernel_clk_mux ( ) ) { ( RtcClock :: Lsi , backup :: RtcClkSel :: LSI ) => true , ( RtcClock :: Hse { divider } , backup :: RtcClkSel :: HSE ) => { rcc . cfgr . read ( ) . rtcpre ( ) . bits ( ) == divider } ( RtcClock :: Lse { bypass , css , .. } , backup :: RtcClkSel :: LSE ) => { bdcr . lseon ( ) . is_on ( ) && bypass == bdcr . lsebyp ( ) . is_bypassed ( ) && css == bdcr . lsecsson ( ) . is_security_on ( ) } _ => false , } ; if ! clock_source_matches { return Err ( ( rtc , prec , InitError :: ConfigMismatch ) ) ; } let clock_source_running = match clock_source { RtcClock :: Lsi => clocks . lsi_ck ( ) . is_some ( ) , RtcClock :: Hse { .. } => clocks . hse_ck ( ) . is_some ( ) , RtcClock :: Lse { .. } => bdcr . lserdy ( ) . is_ready ( ) , } ; if ! clock_source_running { return Err ( ( rtc , prec , InitError :: ClockNotRunning ) ) ; } Ok ( Rtc { reg : rtc , prec } ) }
Opens the RTC if it is running and its configuration matches
Opens the RTC if it is running and its configuration matches
rtc
RTC
prec
backup::Rtc
clock_source
RtcClock
clocks
&CoreClocks
rtc
RTC
prec
backup::Rtc
clock_source
RtcClock
clocks
&CoreClocks