pub trait Rtc: ErrorType {
// Required methods
fn get_datetime(&mut self) -> Result<DateTime, Self::Error>;
fn set_datetime(&mut self, datetime: &DateTime) -> Result<(), Self::Error>;
}Expand description
Core trait for Real-Time Clock (RTC) devices.
This trait provides a platform-agnostic interface for reading and
writing date/time values from hardware RTC chips. It is designed
to be similar in style to embedded-hal traits.
Each RTC implementation should define:
- An associated error type for hardware-specific errors
The DateTime struct used here is hardware-agnostic. Drivers must
validate that provided values fall within the supported range.
§Example
ⓘ
let mut rtc = Ds1307::new(i2c);
let now = rtc.get_datetime()?;
rtc.set_datetime(&DateTime::new(2024, 8, 16, 12, 0, 0)?)?;