From 546c81c52dc69b2765cd30679565fff604fcea7c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 27 Jul 2022 16:14:27 +0200 Subject: [PATCH] Add RTC initialization functions. --- src/rtc.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/rtc.rs b/src/rtc.rs index 944a0744..bf17a5be 100644 --- a/src/rtc.rs +++ b/src/rtc.rs @@ -194,6 +194,20 @@ impl Rtc { rtc_struct } + /// Check if the RTC has been initialized, i.e. if a date and time have been set. + pub fn initialized(&self) -> bool { + self.rtc.isr.read().inits().bit_is_set() + } + + /// Wait for the calendar registers to be synchronized with the shadow registers. + /// + /// This must be called after a system reset or after waking up from low-power mode. + pub fn wait_for_sync(&self) { + self.rtc.isr.modify(|r, w| w.rsf().clear_bit()); + + while self.rtc.isr.read().rsf().bit_is_clear() {} + } + /// Set date and time. pub fn set_datetime(&mut self, datetime: &PrimitiveDateTime) { self.write(true, |rtc| {