ds323x/
ds3231.rs

1//! Functions exclusive of DS3231
2
3use crate::{ic, interface::I2cInterface, BitFlags, Ds323x, CONTROL_POR_VALUE};
4use core::marker::PhantomData;
5use embedded_hal::i2c;
6
7impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3231>
8where
9    I2C: i2c::I2c<Error = E>,
10{
11    /// Create a new instance of the DS3231 device.
12    pub fn new_ds3231(i2c: I2C) -> Self {
13        const STATUS_POR_VALUE: u8 = BitFlags::OSC_STOP | BitFlags::EN32KHZ;
14        Ds323x {
15            iface: I2cInterface { i2c },
16            control: CONTROL_POR_VALUE,
17            status: STATUS_POR_VALUE,
18            _ic: PhantomData,
19        }
20    }
21
22    /// Destroy driver instance, return I²C bus instance.
23    pub fn destroy_ds3231(self) -> I2C {
24        self.iface.i2c
25    }
26}