Rtc

Trait Rtc 

Source
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)?)?;

Required Methods§

Source

fn get_datetime(&mut self) -> Result<DateTime, Self::Error>

Get the current date and time atomically.

§Errors

Returns Self::Error if communication with the RTC fails.

Source

fn set_datetime(&mut self, datetime: &DateTime) -> Result<(), Self::Error>

Set the current date and time atomically.

§Errors

Returns Self::Error if communication with the RTC fails or if the provided DateTime is out of range for this device.

Implementations on Foreign Types§

Source§

impl<T: Rtc + ?Sized> Rtc for &mut T

blanket impl for all &mut T

Source§

fn get_datetime(&mut self) -> Result<DateTime, Self::Error>

Source§

fn set_datetime(&mut self, datetime: &DateTime) -> Result<(), Self::Error>

Implementors§