pub struct Clock { /* private fields */ }
Expand description
Access to the Real Time Clock.
Instantiating a Clock
initializes the relevant registers for interacting with the RTC,
allowing subsequent reads of the RTC’s stored date and time. Dates and times are represented
using types from the time
crate.
Implementations§
Source§impl Clock
impl Clock
Sourcepub fn new(datetime: PrimitiveDateTime) -> Result<Self, Error>
pub fn new(datetime: PrimitiveDateTime) -> Result<Self, Error>
Creates a new Clock
set at the given datetime
.
Note that this does not actually change the stored date and time in the RTC itself. While RTC values are writable on real hardware, they are often not writable in GBA emulators. Therefore, the date and time are stored as being offset from the current RTC date and time to maintain maximum compatibility.
Sourcepub fn read_datetime(&self) -> Result<PrimitiveDateTime, Error>
pub fn read_datetime(&self) -> Result<PrimitiveDateTime, Error>
Reads the currently stored date and time.
Sourcepub fn write_datetime(
&mut self,
datetime: PrimitiveDateTime,
) -> Result<(), Error>
pub fn write_datetime( &mut self, datetime: PrimitiveDateTime, ) -> Result<(), Error>
Writes a new date and time.
Note that this does not actually change the stored date and time in the RTC itself. While RTC values are writable on real hardware, they are often not writable in GBA emulators. Therefore, the date and time are stored as being offset from the current RTC date and time to maintain maximum compatibility.
Sourcepub fn write_date(&mut self, date: Date) -> Result<(), Error>
pub fn write_date(&mut self, date: Date) -> Result<(), Error>
Writes a new date.
This preserves the stored time.
Note that this does not actually change the stored date in the RTC itself. While RTC values are writable on real hardware, they are often not writable in GBA emulators. Therefore, the date and time are stored as being offset from the current RTC date and time to maintain maximum compatibility.
Sourcepub fn read_time(&self) -> Result<Time, Error>
pub fn read_time(&self) -> Result<Time, Error>
Reads the currently stored time.
This is always faster than using Clock::read_datetime()
, as it only requires reading
three bytes from the RTC instead of seven.
Sourcepub fn write_time(&mut self, time: Time) -> Result<(), Error>
pub fn write_time(&mut self, time: Time) -> Result<(), Error>
Writes a new time.
This preserves the stored date.
Note that this does not actually change the stored time in the RTC itself. While RTC values are writable on real hardware, they are often not writable in GBA emulators. Therefore, the date and time are stored as being offset from the current RTC date and time to maintain maximum compatibility.