Struct ds323x::Ds323x

source ·
pub struct Ds323x<DI, IC> { /* private fields */ }
Expand description

DS3231, DS3232 and DS3234 RTC driver

Implementations§

source§

impl<DI, IC, CommE, PinE> Ds323x<DI, IC>where DI: ReadData<Error = Error<CommE, PinE>> + WriteData<Error = Error<CommE, PinE>>,

source

pub fn set_alarm1_day( &mut self, when: DayAlarm1, matching: Alarm1Matching ) -> Result<(), Error<CommE, PinE>>

Set Alarm1 for day of the month.

Will return an Error::InvalidInputData if any of the used parameters (depending on the matching startegy) is out of range. Any unused parameter is set to the corresponding minimum valid value:

  • Second, minute, hour: 0
  • Day: 1
source

pub fn set_alarm1_hms( &mut self, when: NaiveTime ) -> Result<(), Error<CommE, PinE>>

Set Alarm1 for a time (fires when hours, minutes and seconds match).

Will return an Error::InvalidInputData if any of the parameters is out of range. The day is not used by this matching strategy and is set to 1.

source

pub fn set_alarm1_weekday( &mut self, when: WeekdayAlarm1, matching: Alarm1Matching ) -> Result<(), Error<CommE, PinE>>

Set Alarm1 for weekday.

Will return an Error::InvalidInputData if any of the used parameters (depending on the matching startegy) is out of range. Any unused parameter is set to the corresponding minimum valid value:

  • Second, minute, hour: 0
  • Weekday: 1
source

pub fn set_alarm2_day( &mut self, when: DayAlarm2, matching: Alarm2Matching ) -> Result<(), Error<CommE, PinE>>

Set Alarm2 for date (day of month).

Will return an Error::InvalidInputData if any of the used parameters (depending on the matching startegy) is out of range. Any unused parameter is set to the corresponding minimum valid value:

  • Minute, hour: 0
  • Day: 1
source

pub fn set_alarm2_hm( &mut self, when: NaiveTime ) -> Result<(), Error<CommE, PinE>>

Set Alarm2 for a time (fires when hours and minutes match).

Will return an Error::InvalidInputData if any of the parameters is out of range. The day is not used by this matching strategy and is set to 1.

source

pub fn set_alarm2_weekday( &mut self, when: WeekdayAlarm2, matching: Alarm2Matching ) -> Result<(), Error<CommE, PinE>>

Set Alarm2 for weekday.

Will return an Error::InvalidInputData if any of the used parameters (depending on the matching startegy) is out of range. Any unused parameter is set to the corresponding minimum valid value:

  • Minute, hour: 0
  • Weekday: 1
source§

impl<DI, IC, CommE, PinE> Ds323x<DI, IC>where DI: ReadData<Error = Error<CommE, PinE>> + WriteData<Error = Error<CommE, PinE>>,

source

pub fn enable(&mut self) -> Result<(), Error<CommE, PinE>>

Enable the oscillator (set the clock running) (default).

source

pub fn disable(&mut self) -> Result<(), Error<CommE, PinE>>

Disable the oscillator (stops the clock).

source

pub fn convert_temperature(&mut self) -> Result<(), Error<CommE, PinE>>

Force a temperature conversion and time compensation with TXCO algorithm.

The busy status should be checked before doing this. See busy()

source

pub fn enable_32khz_output(&mut self) -> Result<(), Error<CommE, PinE>>

Enable the 32kHz output. (enabled per default)

source

pub fn disable_32khz_output(&mut self) -> Result<(), Error<CommE, PinE>>

Disable the 32kHz output.

source

pub fn set_aging_offset(&mut self, offset: i8) -> Result<(), Error<CommE, PinE>>

Set the aging offset.

source

pub fn aging_offset(&mut self) -> Result<i8, Error<CommE, PinE>>

Read the aging offset.

source

pub fn use_int_sqw_output_as_interrupt( &mut self ) -> Result<(), Error<CommE, PinE>>

Set the interrupt/square-wave output to be used as interrupt output.

source

pub fn use_int_sqw_output_as_square_wave( &mut self ) -> Result<(), Error<CommE, PinE>>

Set the interrupt/square-wave output to be used as square-wave output. (default)

source

pub fn enable_square_wave(&mut self) -> Result<(), Error<CommE, PinE>>

Enable battery-backed square wave generation.

source

pub fn disable_square_wave(&mut self) -> Result<(), Error<CommE, PinE>>

Disable battery-backed square wave generation.

source

pub fn set_square_wave_frequency( &mut self, freq: SqWFreq ) -> Result<(), Error<CommE, PinE>>

Set the square-wave output frequency.

source

pub fn enable_alarm1_interrupts(&mut self) -> Result<(), Error<CommE, PinE>>

Enable Alarm1 interrupts.

source

pub fn disable_alarm1_interrupts(&mut self) -> Result<(), Error<CommE, PinE>>

Disable Alarm1 interrupts.

source

pub fn enable_alarm2_interrupts(&mut self) -> Result<(), Error<CommE, PinE>>

Enable Alarm2 interrupts.

source

pub fn disable_alarm2_interrupts(&mut self) -> Result<(), Error<CommE, PinE>>

Disable Alarm2 interrupts.

source§

impl<DI, IC, CommE, PinE> Ds323x<DI, IC>where DI: ReadData<Error = Error<CommE, PinE>> + WriteData<Error = Error<CommE, PinE>>,

source

pub fn running(&mut self) -> Result<bool, Error<CommE, PinE>>

Read whether the oscillator is running

source

pub fn busy(&mut self) -> Result<bool, Error<CommE, PinE>>

Read the busy status

source

pub fn has_been_stopped(&mut self) -> Result<bool, Error<CommE, PinE>>

Read whether the oscillator is stopped or has been stopped at some point.

This allows a better assessment of the validity of the timekeeping data.

Once this is true, it will stay as such until cleared with clear_has_been_stopped_flag()

source

pub fn clear_has_been_stopped_flag(&mut self) -> Result<(), Error<CommE, PinE>>

Clear flag signalling whether the oscillator is stopped or has been stopped at some point.

See also: has_been_stopped()

source

pub fn has_alarm1_matched(&mut self) -> Result<bool, Error<CommE, PinE>>

Read whether the Alarm1 has matched at some point.

Once this is true, it will stay as such until cleared with clear_alarm1_matched_flag()

source

pub fn clear_alarm1_matched_flag(&mut self) -> Result<(), Error<CommE, PinE>>

Clear flag signalling whether the Alarm1 has matched at some point.

See also: has_alarm1_matched()

source

pub fn has_alarm2_matched(&mut self) -> Result<bool, Error<CommE, PinE>>

Read whether the Alarm2 has matched at some point.

Once this is true, it will stay as such until cleared with clear_alarm2_matched_flag()

source

pub fn clear_alarm2_matched_flag(&mut self) -> Result<(), Error<CommE, PinE>>

Clear flag signalling whether the Alarm2 has matched at some point.

See also: has_alarm2_matched()

source

pub fn temperature(&mut self) -> Result<f32, Error<CommE, PinE>>

Read the temperature.

Note: It is possible to manually force a temperature conversion with convert_temperature()

source§

impl<I2C, E> Ds323x<I2cInterface<I2C>, DS3231>where I2C: Write<Error = E> + WriteRead<Error = E>,

source

pub fn new_ds3231(i2c: I2C) -> Self

Create a new instance of the DS3231 device.

source

pub fn destroy_ds3231(self) -> I2C

Destroy driver instance, return I²C bus instance.

source§

impl<I2C, E> Ds323x<I2cInterface<I2C>, DS3232>where I2C: Write<Error = E> + WriteRead<Error = E>,

source

pub fn new_ds3232(i2c: I2C) -> Self

Create a new instance of the DS3232 device.

source

pub fn destroy_ds3232(self) -> I2C

Destroy driver instance, return I²C bus instance.

source

pub fn enable_32khz_output_on_battery(&mut self) -> Result<(), Error<E, ()>>

Enable the 32kHz output when battery-powered. (enabled per default)

Additionally, the 32kHz output needs to be enabled. See enable_32khz_output().

Note: This is only available for DS3232 and DS3234 devices.

source

pub fn disable_32khz_output_on_battery(&mut self) -> Result<(), Error<E, ()>>

Disable the 32kHz output when battery-powered.

The 32kHz output will still generate a wave when not battery-powered if it enabled. See enable_32khz_output().

Note: This is only available for DS3232 and DS3234 devices.

source

pub fn set_temperature_conversion_rate( &mut self, rate: TempConvRate ) -> Result<(), Error<E, ()>>

Set the temperature conversion rate.

Set how often the temperature is measured and applies compensation to the oscillator. This can be used to reduce power consumption but sudden temperature changes will not be compensated for.

Note: This is only available for DS3232 and DS3234 devices.

source§

impl<SPI, CS, CommE, PinE> Ds323x<SpiInterface<SPI, CS>, DS3234>where SPI: Transfer<u8, Error = CommE> + Write<u8, Error = CommE>, CS: OutputPin<Error = PinE>,

source

pub fn new_ds3234(spi: SPI, chip_select: CS) -> Self

Create a new instance.

source

pub fn destroy_ds3234(self) -> (SPI, CS)

Destroy driver instance, return SPI bus instance and CS output pin.

source

pub fn enable_32khz_output_on_battery( &mut self ) -> Result<(), Error<CommE, PinE>>

Enable the 32kHz output when battery-powered. (enabled per default)

Additionally, the 32kHz output needs to be enabled. See enable_32khz_output().

Note: This is only available for DS3232 and DS3234 devices.

source

pub fn disable_32khz_output_on_battery( &mut self ) -> Result<(), Error<CommE, PinE>>

Disable the 32kHz output when battery-powered.

The 32kHz output will still generate a wave when not battery-powered if it enabled. See enable_32khz_output().

Note: This is only available for DS3232 and DS3234 devices.

source

pub fn set_temperature_conversion_rate( &mut self, rate: TempConvRate ) -> Result<(), Error<CommE, PinE>>

Set the temperature conversion rate.

Set how often the temperature is measured and applies compensation to the oscillator. This can be used to reduce power consumption but sudden temperature changes will not be compensated for.

Note: This is only available for DS3232 and DS3234 devices.

source

pub fn enable_temperature_conversions_on_battery( &mut self ) -> Result<(), Error<CommE, PinE>>

Enable the temperature conversions when battery-powered. (enabled per default)

Note: This is only available for DS3234 devices.

source

pub fn disable_temperature_conversions_on_battery( &mut self ) -> Result<(), Error<CommE, PinE>>

Disable the temperature conversions when battery-powered.

Note: This is only available for DS3234 devices.

Trait Implementations§

source§

impl<DI, IC, CommE, PinE> DateTimeAccess for Ds323x<DI, IC>where DI: ReadData<Error = Error<CommE, PinE>> + WriteData<Error = Error<CommE, PinE>>,

§

type Error = Error<CommE, PinE>

Error type
source§

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

Read the date and time.
source§

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

Set the date and time. Read more
source§

impl<DI: Debug, IC: Debug> Debug for Ds323x<DI, IC>

source§

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

Formats the value using the given formatter. Read more
source§

impl<DI: Default, IC: Default> Default for Ds323x<DI, IC>

source§

fn default() -> Ds323x<DI, IC>

Returns the “default value” for a type. Read more
source§

impl<DI, IC, CommE, PinE> Rtcc for Ds323x<DI, IC>where DI: ReadData<Error = Error<CommE, PinE>> + WriteData<Error = Error<CommE, PinE>>,

source§

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

Read the seconds.
source§

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

Read the minutes.
source§

fn hours(&mut self) -> Result<Hours, Self::Error>

Read the hours.
source§

fn time(&mut self) -> Result<NaiveTime, Self::Error>

Read the time.
source§

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

Read the day of the week [1-7].
source§

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

Read the day of the month [1-31].
source§

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

Read the month [1-12].
source§

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

Read the year (e.g. 2000).
source§

fn date(&mut self) -> Result<NaiveDate, Self::Error>

Read the date.
source§

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

Set the seconds [0-59].
source§

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

Set the minutes [0-59].
source§

fn set_hours(&mut self, hours: Hours) -> Result<(), Self::Error>

Set the hours. Read more
source§

fn set_time(&mut self, time: &NaiveTime) -> Result<(), Self::Error>

Set the time.
source§

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

Set the day of week [1-7].
source§

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

Set the day of month [1-31].
source§

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

Set the month [1-12].
source§

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

Set the year. (e.g. 2000)
source§

fn set_date(&mut self, date: &NaiveDate) -> Result<(), Self::Error>

Set the date.

Auto Trait Implementations§

§

impl<DI, IC> RefUnwindSafe for Ds323x<DI, IC>where DI: RefUnwindSafe, IC: RefUnwindSafe,

§

impl<DI, IC> Send for Ds323x<DI, IC>where DI: Send, IC: Send,

§

impl<DI, IC> Sync for Ds323x<DI, IC>where DI: Sync, IC: Sync,

§

impl<DI, IC> Unpin for Ds323x<DI, IC>where DI: Unpin, IC: Unpin,

§

impl<DI, IC> UnwindSafe for Ds323x<DI, IC>where DI: UnwindSafe, IC: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.