Struct Rtc

Source
pub struct Rtc {
    pub regs: RTC,
}

Fields§

§regs: RTC

Implementations§

Source§

impl Rtc

Source

pub fn new( regs: RTC, prediv_s: u16, prediv_a: u8, clock_source: RtcClock, clocks: Clocks, apb1: &mut APB1, pwr: &mut PWR, ) -> Option<Self>

Create and enable a new RTC, and configure its clock source and prescalers.

** Assumes 1970-01-01 00:00:00 Epoch **

See AN4759 (Rev 7) Table 7 for configuration of prediv_s and prediv_a, respectively the formula to calculate ck_spre on the same page.

For example, when using the LSE, set prediv_s to 255, and prediv_a to 127 to get a calendar clock of 1Hz.

§Panics

A panic is triggered in case the RTC returns invalid a date or time, for example, hours greater than 23.

§Note

This implementation assumes that the APB clock is greater than (>=) seven (7) times the RTC clock. This ensures a secure behavior of the synchronization mechanism.

Source

pub fn set_time(&mut self, time: &Time) -> Result<(), Error>

Set the time using time::Time.

Source

pub fn set_seconds(&mut self, seconds: u8) -> Result<(), Error>

Set the seconds [0-59].

Source

pub fn set_minutes(&mut self, minutes: u8) -> Result<(), Error>

Set the minutes [0-59].

Source

pub fn set_hours(&mut self, hours: u8) -> Result<(), Error>

Set the hours [0-23].

Source

pub fn set_weekday(&mut self, weekday: u8) -> Result<(), Error>

Set the day of week [1-7].

Source

pub fn set_day(&mut self, day: u8) -> Result<(), Error>

Set the day of month [1-31].

Source

pub fn set_month(&mut self, month: u8) -> Result<(), Error>

Set the month [1-12].

Source

pub fn set_year(&mut self, year: u16) -> Result<(), Error>

Set the year [1970-2069].

The year cannot be less than 1970, since the Unix epoch is assumed (1970-01-01 00:00:00). Also, the year cannot be greater than 2069 since the RTC range is 0 - 99.

Source

pub fn set_date(&mut self, date: &Date) -> Result<(), Error>

Set the date.

The year cannot be less than 1970, since the Unix epoch is assumed (1970-01-01 00:00:00). Also, the year cannot be greater than 2069 since the RTC range is 0 - 99.

Source

pub fn set_datetime(&mut self, date: &PrimitiveDateTime) -> Result<(), Error>

Set the date and time.

The year cannot be less than 1970, since the Unix epoch is assumed (1970-01-01 00:00:00). Also, the year cannot be greater than 2069 since the RTC range is 0 - 99.

Source

pub fn get_datetime(&mut self) -> PrimitiveDateTime

Auto Trait Implementations§

§

impl Freeze for Rtc

§

impl RefUnwindSafe for Rtc

§

impl Send for Rtc

§

impl !Sync for Rtc

§

impl Unpin for Rtc

§

impl UnwindSafe for Rtc

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.