Struct Clock

Source
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

Source

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.

Source

pub fn read_datetime(&self) -> Result<PrimitiveDateTime, Error>

Reads the currently stored date and time.

Source

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.

Source

pub fn read_date(&self) -> Result<Date, Error>

Reads the currently stored date.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Clock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Clock

§

impl RefUnwindSafe for Clock

§

impl Send for Clock

§

impl Sync for Clock

§

impl Unpin for Clock

§

impl UnwindSafe for Clock

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.