Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RTC initialization functions. #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down