Skip to content

Commit

Permalink
Add free function
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthbdn committed Dec 11, 2023
1 parent 28ec527 commit 9372dce
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rp2040-hal/src/rtc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError};
/// A reference to the real time clock of the system
pub struct RealTimeClock {
rtc: RTC,
clock: RtcClock,
}

impl RealTimeClock {
Expand Down Expand Up @@ -68,7 +69,7 @@ impl RealTimeClock {
let freq = clock.freq().to_Hz() - 1;
rtc.clkdiv_m1.write(|w| unsafe { w.bits(freq) });

let mut result = Self { rtc };
let mut result = Self { rtc, clock };
result.set_leap_year_check(true); // should be on by default, make sure this is the case.
result.set_datetime(initial_date)?;
Ok(result)
Expand Down Expand Up @@ -196,6 +197,12 @@ impl RealTimeClock {
self.set_match_ena(false);
self.set_match_ena(true);
}

/// Free the RTC peripheral and RTC clock
pub fn free(self, resets: &mut RESETS) -> (RTC, RtcClock) {
resets.reset.modify(|_, w| w.rtc().set_bit());
(self.rtc, self.clock)
}
}

/// Errors that can occur on methods on [RtcClock]
Expand Down

0 comments on commit 9372dce

Please sign in to comment.