RP: Rename Rtc to match STM32 impl. Remove setting RTC in new().
This commit is contained in:
parent
029b156563
commit
a93714327e
@ -12,26 +12,24 @@ pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError};
|
||||
use crate::clocks::clk_rtc_freq;
|
||||
|
||||
/// A reference to the real time clock of the system
|
||||
pub struct RealTimeClock<'d, T: Instance> {
|
||||
pub struct Rtc<'d, T: Instance> {
|
||||
inner: PeripheralRef<'d, T>,
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> RealTimeClock<'d, T> {
|
||||
impl<'d, T: Instance> Rtc<'d, T> {
|
||||
/// Create a new instance of the real time clock, with the given date as an initial value.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Will return `RtcError::InvalidDateTime` if the datetime is not a valid range.
|
||||
pub fn new(inner: impl Peripheral<P = T> + 'd, initial_date: DateTime) -> Result<Self, RtcError> {
|
||||
pub fn new(inner: impl Peripheral<P = T> + 'd) -> Self {
|
||||
into_ref!(inner);
|
||||
|
||||
// Set the RTC divider
|
||||
inner.regs().clkdiv_m1().write(|w| w.set_clkdiv_m1(clk_rtc_freq() - 1));
|
||||
|
||||
let mut result = Self { inner };
|
||||
result.set_leap_year_check(true); // should be on by default, make sure this is the case.
|
||||
result.set_datetime(initial_date)?;
|
||||
Ok(result)
|
||||
let result = Self { inner };
|
||||
result
|
||||
}
|
||||
|
||||
/// Enable or disable the leap year check. The rp2040 chip will always add a Feb 29th on every year that is divisable by 4, but this may be incorrect (e.g. on century years). This function allows you to disable this check.
|
||||
@ -43,7 +41,7 @@ impl<'d, T: Instance> RealTimeClock<'d, T> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Checks to see if this RealTimeClock is running
|
||||
/// Checks to see if this Rtc is running
|
||||
pub fn is_running(&self) -> bool {
|
||||
self.inner.regs().ctrl().read().rtc_active()
|
||||
}
|
||||
@ -113,8 +111,8 @@ impl<'d, T: Instance> RealTimeClock<'d, T> {
|
||||
/// # fn main() { }
|
||||
/// # #[cfg(not(feature = "chrono"))]
|
||||
/// # fn main() {
|
||||
/// # use embassy_rp::rtc::{RealTimeClock, DateTimeFilter};
|
||||
/// # let mut real_time_clock: RealTimeClock<embassy_rp::peripherals::RTC> = unsafe { core::mem::zeroed() };
|
||||
/// # use embassy_rp::rtc::{Rtc, DateTimeFilter};
|
||||
/// # let mut real_time_clock: Rtc<embassy_rp::peripherals::RTC> = unsafe { core::mem::zeroed() };
|
||||
/// let now = real_time_clock.now().unwrap();
|
||||
/// real_time_clock.schedule_alarm(
|
||||
/// DateTimeFilter::default()
|
||||
@ -150,7 +148,7 @@ impl<'d, T: Instance> RealTimeClock<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors that can occur on methods on [RealTimeClock]
|
||||
/// Errors that can occur on methods on [Rtc]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum RtcError {
|
||||
/// An invalid DateTime was given or stored on the hardware.
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::rtc::{DateTime, DayOfWeek, RealTimeClock};
|
||||
use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
@ -23,11 +23,17 @@ async fn main(_spawner: Spawner) {
|
||||
second: 50,
|
||||
};
|
||||
|
||||
let rtc_result = RealTimeClock::new(p.RTC, now);
|
||||
if let Ok(rtc) = rtc_result {
|
||||
let mut rtc = Rtc::new(p.RTC);
|
||||
if rtc.set_datetime(now).is_ok() {
|
||||
// In reality the delay would be much longer
|
||||
Timer::after(Duration::from_millis(20000)).await;
|
||||
|
||||
let _then: DateTime = rtc.now().unwrap();
|
||||
if let Ok(dt) = rtc.now() {
|
||||
info!(
|
||||
"Now: {}-{}-{} {}:{}:{}",
|
||||
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
|
||||
);
|
||||
}
|
||||
}
|
||||
info!("Done.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user