Use Rust edition 2018

pull/5/head
Diego Barrios Romero 2020-07-10 22:24:29 +02:00
parent ff632625b2
commit f146d1d26e
20 changed files with 97 additions and 159 deletions

View File

@ -18,6 +18,7 @@ include = [
"/LICENSE-MIT", "/LICENSE-MIT",
"/LICENSE-APACHE", "/LICENSE-APACHE",
] ]
edition = "2018"
[badges] [badges]
travis-ci = { repository = "eldruin/ds323x-rs", branch = "master" } travis-ci = { repository = "eldruin/ds323x-rs", branch = "master" }

View File

@ -137,12 +137,11 @@ Please find additional examples using hardware in this repository: [driver-examp
[driver-examples]: https://github.com/eldruin/driver-examples [driver-examples]: https://github.com/eldruin/driver-examples
```rust ```rust
extern crate ds323x;
extern crate linux_embedded_hal as hal;
use ds323x::{Ds323x, NaiveDate, Rtcc}; use ds323x::{Ds323x, NaiveDate, Rtcc};
use linux_embedded_hal::I2cdev;
fn main() { fn main() {
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap(); let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut rtc = Ds323x::new_ds3231(dev); let mut rtc = Ds323x::new_ds3231(dev);
let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58); let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58);
rtc.set_datetime(&datetime).unwrap(); rtc.set_datetime(&datetime).unwrap();

View File

@ -1,9 +1,8 @@
extern crate ds323x;
extern crate linux_embedded_hal as hal;
use ds323x::{Ds323x, NaiveDate, Rtcc}; use ds323x::{Ds323x, NaiveDate, Rtcc};
use linux_embedded_hal::I2cdev;
fn main() { fn main() {
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap(); let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut rtc = Ds323x::new_ds3231(dev); let mut rtc = Ds323x::new_ds3231(dev);
let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58); let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58);
rtc.set_datetime(&datetime).unwrap(); rtc.set_datetime(&datetime).unwrap();

View File

@ -1,13 +1,12 @@
//! Functions exclusive of DS3231 //! Functions exclusive of DS3231
use super::{ic, BitFlags, Ds323x, CONTROL_POR_VALUE}; use crate::{ic, interface::I2cInterface, BitFlags, Ds323x, CONTROL_POR_VALUE};
use core::marker::PhantomData; use core::marker::PhantomData;
use hal::blocking; use embedded_hal::blocking::i2c;
use interface::I2cInterface;
impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3231> impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3231>
where where
I2C: blocking::i2c::Write<Error = E> + blocking::i2c::WriteRead<Error = E>, I2C: i2c::Write<Error = E> + i2c::WriteRead<Error = E>,
{ {
/// Create a new instance of the DS3231 device. /// Create a new instance of the DS3231 device.
pub fn new_ds3231(i2c: I2C) -> Self { pub fn new_ds3231(i2c: I2C) -> Self {

View File

@ -1,13 +1,14 @@
//! Functions exclusive of DS3232 //! Functions exclusive of DS3232
use super::{ic, BitFlags, Ds323x, Error, TempConvRate, CONTROL_POR_VALUE}; use crate::{
ic, interface::I2cInterface, BitFlags, Ds323x, Error, TempConvRate, CONTROL_POR_VALUE,
};
use core::marker::PhantomData; use core::marker::PhantomData;
use hal::blocking; use embedded_hal::blocking::i2c;
use interface::I2cInterface;
impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3232> impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3232>
where where
I2C: blocking::i2c::Write<Error = E> + blocking::i2c::WriteRead<Error = E>, I2C: i2c::Write<Error = E> + i2c::WriteRead<Error = E>,
{ {
/// Create a new instance of the DS3232 device. /// Create a new instance of the DS3232 device.
pub fn new_ds3232(i2c: I2C) -> Self { pub fn new_ds3232(i2c: I2C) -> Self {

View File

@ -1,13 +1,13 @@
//! Functions exclusive of DS3234 //! Functions exclusive of DS3234
use super::{ic, BitFlags, Ds323x, Error, Register, TempConvRate, CONTROL_POR_VALUE}; use crate::interface::{SpiInterface, WriteData};
use crate::{ic, BitFlags, Ds323x, Error, Register, TempConvRate, CONTROL_POR_VALUE};
use core::marker::PhantomData; use core::marker::PhantomData;
use hal::blocking; use embedded_hal::{blocking::spi, digital::v2::OutputPin};
use interface::{SpiInterface, WriteData};
impl<SPI, CS, CommE, PinE> Ds323x<SpiInterface<SPI, CS>, ic::DS3234> impl<SPI, CS, CommE, PinE> Ds323x<SpiInterface<SPI, CS>, ic::DS3234>
where where
SPI: blocking::spi::Transfer<u8, Error = CommE> + blocking::spi::Write<u8, Error = CommE>, SPI: spi::Transfer<u8, Error = CommE> + spi::Write<u8, Error = CommE>,
CS: hal::digital::v2::OutputPin<Error = PinE>, CS: OutputPin<Error = PinE>,
{ {
/// Create a new instance. /// Create a new instance.
pub fn new_ds3234(spi: SPI, chip_select: CS) -> Self { pub fn new_ds3234(spi: SPI, chip_select: CS) -> Self {

View File

@ -1,9 +1,11 @@
//! Alarm support //! Alarm support
use super::super::{BitFlags, Ds323x, Error, Hours, Register};
use super::{decimal_to_packed_bcd, hours_to_register}; use super::{decimal_to_packed_bcd, hours_to_register};
use crate::ds323x::{NaiveTime, Timelike}; use crate::{
use interface::{ReadData, WriteData}; ds323x::{NaiveTime, Timelike},
interface::{ReadData, WriteData},
BitFlags, Ds323x, Error, Hours, Register,
};
/// Parameters for setting Alarm1 on a day of the month /// Parameters for setting Alarm1 on a day of the month
/// ///

View File

@ -1,7 +1,9 @@
//! Device configuration //! Device configuration
use super::super::{BitFlags, Ds323x, Error, Register, SqWFreq}; use crate::{
use interface::{ReadData, WriteData}; interface::{ReadData, WriteData},
BitFlags, Ds323x, Error, Register, SqWFreq,
};
impl<DI, IC, CommE, PinE> Ds323x<DI, IC> impl<DI, IC, CommE, PinE> Ds323x<DI, IC>
where where

View File

@ -1,9 +1,11 @@
//! Common implementation //! Common implementation
use super::super::{BitFlags, Ds323x, Error, Register};
use super::{decimal_to_packed_bcd, hours_to_register, packed_bcd_to_decimal}; use super::{decimal_to_packed_bcd, hours_to_register, packed_bcd_to_decimal};
use super::{Datelike, Hours, NaiveDate, NaiveDateTime, NaiveTime, Rtcc, Timelike}; use crate::{
use interface::{ReadData, WriteData}; interface::{ReadData, WriteData},
BitFlags, Datelike, Ds323x, Error, Hours, NaiveDate, NaiveDateTime, NaiveTime, Register, Rtcc,
Timelike,
};
impl<DI, IC, CommE, PinE> Rtcc for Ds323x<DI, IC> impl<DI, IC, CommE, PinE> Rtcc for Ds323x<DI, IC>
where where

View File

@ -5,8 +5,7 @@ pub use self::alarms::{
Alarm1Matching, Alarm2Matching, DayAlarm1, DayAlarm2, WeekdayAlarm1, WeekdayAlarm2, Alarm1Matching, Alarm2Matching, DayAlarm1, DayAlarm2, WeekdayAlarm1, WeekdayAlarm2,
}; };
mod datetime; mod datetime;
use super::{BitFlags, Error}; use crate::{BitFlags, Error, Hours, NaiveTime, Timelike};
use super::{Datelike, Hours, NaiveDate, NaiveDateTime, NaiveTime, Rtcc, Timelike};
// Transforms a decimal number to packed BCD format // Transforms a decimal number to packed BCD format
fn decimal_to_packed_bcd(dec: u8) -> u8 { fn decimal_to_packed_bcd(dec: u8) -> u8 {

View File

@ -1,7 +1,9 @@
//! Device status //! Device status
use super::super::{BitFlags, Ds323x, Error, Register}; use crate::{
use interface::{ReadData, WriteData}; interface::{ReadData, WriteData},
BitFlags, Ds323x, Error, Register,
};
impl<DI, IC, CommE, PinE> Ds323x<DI, IC> impl<DI, IC, CommE, PinE> Ds323x<DI, IC>
where where

View File

@ -1,7 +1,10 @@
//! I2C/SPI interfaces //! I2C/SPI interfaces
use super::{private, Error, DEVICE_ADDRESS}; use crate::{private, Error, DEVICE_ADDRESS};
use hal::blocking; use embedded_hal::{
blocking::{i2c, spi},
digital::v2::OutputPin,
};
/// I2C interface /// I2C interface
#[derive(Debug, Default)] #[derive(Debug, Default)]
@ -28,7 +31,7 @@ pub trait WriteData: private::Sealed {
impl<I2C, E> WriteData for I2cInterface<I2C> impl<I2C, E> WriteData for I2cInterface<I2C>
where where
I2C: blocking::i2c::Write<Error = E>, I2C: i2c::Write<Error = E>,
{ {
type Error = Error<E, ()>; type Error = Error<E, ()>;
fn write_register(&mut self, register: u8, data: u8) -> Result<(), Self::Error> { fn write_register(&mut self, register: u8, data: u8) -> Result<(), Self::Error> {
@ -47,8 +50,8 @@ where
impl<SPI, CS, CommE, PinE> WriteData for SpiInterface<SPI, CS> impl<SPI, CS, CommE, PinE> WriteData for SpiInterface<SPI, CS>
where where
SPI: blocking::spi::Write<u8, Error = CommE>, SPI: spi::Write<u8, Error = CommE>,
CS: hal::digital::v2::OutputPin<Error = PinE>, CS: OutputPin<Error = PinE>,
{ {
type Error = Error<CommE, PinE>; type Error = Error<CommE, PinE>;
fn write_register(&mut self, register: u8, data: u8) -> Result<(), Self::Error> { fn write_register(&mut self, register: u8, data: u8) -> Result<(), Self::Error> {
@ -83,7 +86,7 @@ pub trait ReadData: private::Sealed {
impl<I2C, E> ReadData for I2cInterface<I2C> impl<I2C, E> ReadData for I2cInterface<I2C>
where where
I2C: blocking::i2c::WriteRead<Error = E>, I2C: i2c::WriteRead<Error = E>,
{ {
type Error = Error<E, ()>; type Error = Error<E, ()>;
fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> { fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> {
@ -104,8 +107,8 @@ where
impl<SPI, CS, CommE, PinE> ReadData for SpiInterface<SPI, CS> impl<SPI, CS, CommE, PinE> ReadData for SpiInterface<SPI, CS>
where where
SPI: blocking::spi::Transfer<u8, Error = CommE>, SPI: spi::Transfer<u8, Error = CommE>,
CS: hal::digital::v2::OutputPin<Error = PinE>, CS: OutputPin<Error = PinE>,
{ {
type Error = Error<CommE, PinE>; type Error = Error<CommE, PinE>;
fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> { fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> {

View File

@ -155,84 +155,69 @@
//! ### Create a driver instance for the DS3231 //! ### Create a driver instance for the DS3231
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::Ds323x; //! use ds323x::Ds323x;
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let rtc = Ds323x::new_ds3231(dev); //! let rtc = Ds323x::new_ds3231(dev);
//! // do something... //! // do something...
//! //!
//! // get the I2C device back //! // get the I2C device back
//! let dev = rtc.destroy_ds3231(); //! let dev = rtc.destroy_ds3231();
//! # }
//! ``` //! ```
//! //!
//! ### Create a driver instance for the DS3232 //! ### Create a driver instance for the DS3232
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::Ds323x; //! use ds323x::Ds323x;
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let rtc = Ds323x::new_ds3232(dev); //! let rtc = Ds323x::new_ds3232(dev);
//! // do something... //! // do something...
//! //!
//! // get the I2C device back //! // get the I2C device back
//! let dev = rtc.destroy_ds3232(); //! let dev = rtc.destroy_ds3232();
//! # }
//! ``` //! ```
//! //!
//! ### Create a driver instance for the DS3234 //! ### Create a driver instance for the DS3234
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::Ds323x; //! use ds323x::Ds323x;
//! use linux_embedded_hal::{Pin, Spidev};
//! //!
//! # fn main() { //! let dev = Spidev::open("/dev/spidev0.0").unwrap();
//! let dev = hal::Spidev::open("/dev/spidev0.0").unwrap(); //! let chip_select = Pin::new(24);
//! let chip_select = hal::Pin::new(24);
//! let rtc = Ds323x::new_ds3234(dev, chip_select); //! let rtc = Ds323x::new_ds3234(dev, chip_select);
//! // do something... //! // do something...
//! //!
//! // get the SPI device and chip select pin back //! // get the SPI device and chip select pin back
//! let (dev, chip_select) = rtc.destroy_ds3234(); //! let (dev, chip_select) = rtc.destroy_ds3234();
//! # }
//! ``` //! ```
//! //!
//! ### Set the current date and time at once //! ### Set the current date and time at once
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, NaiveDate, Rtcc}; //! use ds323x::{Ds323x, NaiveDate, Rtcc};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58); //! let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58);
//! rtc.set_datetime(&datetime).unwrap(); //! rtc.set_datetime(&datetime).unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Get the current date and time at once //! ### Get the current date and time at once
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, Rtcc}; //! use ds323x::{Ds323x, Rtcc};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let dt = rtc.get_datetime().unwrap(); //! let dt = rtc.get_datetime().unwrap();
//! println!("{}", dt); //! println!("{}", dt);
//! // This will print something like: 2020-05-01 19:59:58 //! // This will print something like: 2020-05-01 19:59:58
//! # }
//! ``` //! ```
//! //!
//! ### Get the year //! ### Get the year
@ -240,16 +225,13 @@
//! Similar methods exist for month, day, weekday, hours, minutes and seconds. //! Similar methods exist for month, day, weekday, hours, minutes and seconds.
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, Rtcc}; //! use ds323x::{Ds323x, Rtcc};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let year = rtc.get_year().unwrap(); //! let year = rtc.get_year().unwrap();
//! println!("Year: {}", year); //! println!("Year: {}", year);
//! # }
//! ``` //! ```
//! //!
//! ### Set the year //! ### Set the year
@ -257,78 +239,63 @@
//! Similar methods exist for month, day, weekday, hours, minutes and seconds. //! Similar methods exist for month, day, weekday, hours, minutes and seconds.
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, Rtcc}; //! use ds323x::{Ds323x, Rtcc};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! rtc.set_year(2018).unwrap(); //! rtc.set_year(2018).unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Enable/disable the device //! ### Enable/disable the device
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::Ds323x; //! use ds323x::Ds323x;
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! rtc.disable().unwrap(); // stops the clock //! rtc.disable().unwrap(); // stops the clock
//! let running = rtc.running().unwrap(); //! let running = rtc.running().unwrap();
//! println!("Is running: {}", running); // will print false //! println!("Is running: {}", running); // will print false
//! rtc.enable().unwrap(); // set clock to run //! rtc.enable().unwrap(); // set clock to run
//! println!("Is running: {}", running); // will print true //! println!("Is running: {}", running); // will print true
//! # }
//! ``` //! ```
//! //!
//! ### Read the temperature //! ### Read the temperature
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::Ds323x; //! use ds323x::Ds323x;
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let temperature = rtc.get_temperature().unwrap(); //! let temperature = rtc.get_temperature().unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Read busy status //! ### Read busy status
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::Ds323x; //! use ds323x::Ds323x;
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let busy = rtc.busy().unwrap(); //! let busy = rtc.busy().unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Enable the square-wave output with a frequency of 4.096Hz //! ### Enable the square-wave output with a frequency of 4.096Hz
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, SqWFreq}; //! use ds323x::{Ds323x, SqWFreq};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! rtc.set_square_wave_frequency(SqWFreq::_4_096Hz).unwrap(); //! rtc.set_square_wave_frequency(SqWFreq::_4_096Hz).unwrap();
//! // The same output pin can be used for interrupts or as square-wave output //! // The same output pin can be used for interrupts or as square-wave output
//! rtc.use_int_sqw_output_as_square_wave().unwrap(); //! rtc.use_int_sqw_output_as_square_wave().unwrap();
//! rtc.enable_square_wave().unwrap(); //! rtc.enable_square_wave().unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Enable the 32kHz output except when on battery power //! ### Enable the 32kHz output except when on battery power
@ -337,30 +304,24 @@
//! available for the devices DS3232 and DS3234. //! available for the devices DS3232 and DS3234.
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, SqWFreq}; //! use ds323x::{Ds323x, SqWFreq};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3232(dev); //! let mut rtc = Ds323x::new_ds3232(dev);
//! rtc.disable_32khz_output_on_battery().unwrap(); // only available for DS3232 and DS3234 //! rtc.disable_32khz_output_on_battery().unwrap(); // only available for DS3232 and DS3234
//! rtc.enable_32khz_output().unwrap(); //! rtc.enable_32khz_output().unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Set the aging offset //! ### Set the aging offset
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::Ds323x; //! use ds323x::Ds323x;
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! rtc.set_aging_offset(-15).unwrap(); //! rtc.set_aging_offset(-15).unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Set the temperature conversion rate to once every 128 seconds //! ### Set the temperature conversion rate to once every 128 seconds
@ -368,26 +329,21 @@
//! This is only available for the devices DS3232 and DS3234. //! This is only available for the devices DS3232 and DS3234.
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, TempConvRate}; //! use ds323x::{Ds323x, TempConvRate};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3232(dev); //! let mut rtc = Ds323x::new_ds3232(dev);
//! rtc.set_temperature_conversion_rate(TempConvRate::_128s).unwrap(); //! rtc.set_temperature_conversion_rate(TempConvRate::_128s).unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Set the Alarm1 to each week on a week day at a specific time //! ### Set the Alarm1 to each week on a week day at a specific time
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, Hours, WeekdayAlarm1, Alarm1Matching}; //! use ds323x::{Ds323x, Hours, WeekdayAlarm1, Alarm1Matching};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let alarm1 = WeekdayAlarm1 { //! let alarm1 = WeekdayAlarm1 {
//! weekday: 1, //! weekday: 1,
@ -396,7 +352,6 @@
//! second: 15 //! second: 15
//! }; //! };
//! rtc.set_alarm1_weekday(alarm1, Alarm1Matching::AllMatch).unwrap(); //! rtc.set_alarm1_weekday(alarm1, Alarm1Matching::AllMatch).unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Set the Alarm2 to each day at the same time and enable interrupts on output //! ### Set the Alarm2 to each day at the same time and enable interrupts on output
@ -404,12 +359,10 @@
//! The INT/SQW output pin will be set to 1 when it the alarm matches. //! The INT/SQW output pin will be set to 1 when it the alarm matches.
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, Hours, DayAlarm2, Alarm2Matching}; //! use ds323x::{Ds323x, Hours, DayAlarm2, Alarm2Matching};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let alarm2 = DayAlarm2 { //! let alarm2 = DayAlarm2 {
//! day: 1, // does not matter given the chosen matching //! day: 1, // does not matter given the chosen matching
@ -419,32 +372,26 @@
//! rtc.set_alarm2_day(alarm2, Alarm2Matching::HoursAndMinutesMatch).unwrap(); //! rtc.set_alarm2_day(alarm2, Alarm2Matching::HoursAndMinutesMatch).unwrap();
//! rtc.use_int_sqw_output_as_interrupt().unwrap(); //! rtc.use_int_sqw_output_as_interrupt().unwrap();
//! rtc.enable_alarm2_interrupts().unwrap(); //! rtc.enable_alarm2_interrupts().unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Set the Alarm1 to a specific time //! ### Set the Alarm1 to a specific time
//! //!
//! ```no_run //! ```no_run
//! extern crate ds323x;
//! extern crate linux_embedded_hal as hal;
//! use ds323x::{Ds323x, Hours, NaiveTime}; //! use ds323x::{Ds323x, Hours, NaiveTime};
//! use linux_embedded_hal::I2cdev;
//! //!
//! # fn main() { //! let dev = I2cdev::new("/dev/i2c-1").unwrap();
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev); //! let mut rtc = Ds323x::new_ds3231(dev);
//! let time = NaiveTime::from_hms(19, 59, 58); //! let time = NaiveTime::from_hms(19, 59, 58);
//! rtc.set_alarm1_hms(time).unwrap(); //! rtc.set_alarm1_hms(time).unwrap();
//! # }
//! ``` //! ```
#![deny(unsafe_code, missing_docs)] #![deny(unsafe_code, missing_docs)]
#![no_std] #![no_std]
extern crate embedded_hal as hal;
use core::marker::PhantomData; use core::marker::PhantomData;
use hal::spi::{Mode, MODE_1, MODE_3}; use embedded_hal::spi::{Mode, MODE_1, MODE_3};
extern crate rtcc; pub use rtcc::{Datelike, Hours, NaiveDate, NaiveDateTime, NaiveTime, Rtcc, Timelike};
pub use self::rtcc::{Datelike, Hours, NaiveDate, NaiveDateTime, NaiveTime, Rtcc, Timelike};
/// SPI mode 1 (CPOL = 0, CPHA = 1) /// SPI mode 1 (CPOL = 0, CPHA = 1)
pub const SPI_MODE_1: Mode = MODE_1; pub const SPI_MODE_1: Mode = MODE_1;
@ -560,7 +507,7 @@ pub struct Ds323x<DI, IC> {
mod ds323x; mod ds323x;
pub mod interface; pub mod interface;
pub use ds323x::{ pub use crate::ds323x::{
Alarm1Matching, Alarm2Matching, DayAlarm1, DayAlarm2, WeekdayAlarm1, WeekdayAlarm2, Alarm1Matching, Alarm2Matching, DayAlarm1, DayAlarm2, WeekdayAlarm1, WeekdayAlarm2,
}; };
mod ds3231; mod ds3231;

View File

@ -1,12 +1,9 @@
extern crate embedded_hal_mock as hal; use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans};
use hal::i2c::Transaction as I2cTrans;
use hal::spi::Transaction as SpiTrans;
mod common; mod common;
use common::{ use common::{
destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234, destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234,
BitFlags as BF, Register, DEVICE_ADDRESS as DEV_ADDR, BitFlags as BF, Register, DEVICE_ADDRESS as DEV_ADDR,
}; };
extern crate ds323x;
use ds323x::{ use ds323x::{
Alarm1Matching as A1M, Alarm2Matching as A2M, DayAlarm1, DayAlarm2, Error, Hours, NaiveTime, Alarm1Matching as A1M, Alarm2Matching as A2M, DayAlarm1, DayAlarm2, Error, Hours, NaiveTime,
WeekdayAlarm1, WeekdayAlarm2, WeekdayAlarm1, WeekdayAlarm2,

View File

@ -1,9 +1,8 @@
extern crate ds323x; use ds323x::{ic, interface, Ds323x};
extern crate embedded_hal; use embedded_hal_mock::{
use self::ds323x::{ic, interface, Ds323x}; i2c::{Mock as I2cMock, Transaction as I2cTrans},
extern crate embedded_hal_mock as hal; spi::{Mock as SpiMock, Transaction as SpiTrans},
use self::hal::i2c::{Mock as I2cMock, Transaction as I2cTrans}; };
use self::hal::spi::{Mock as SpiMock, Transaction as SpiTrans};
#[allow(unused)] #[allow(unused)]
pub const DEVICE_ADDRESS: u8 = 0b110_1000; pub const DEVICE_ADDRESS: u8 = 0b110_1000;

View File

@ -1,9 +1,5 @@
extern crate embedded_hal_mock as hal;
use hal::i2c::Transaction as I2cTrans;
use hal::spi::Transaction as SpiTrans;
extern crate ds323x;
use ds323x::SqWFreq; use ds323x::SqWFreq;
use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans};
mod common; mod common;
use common::{ use common::{

View File

@ -1,12 +1,9 @@
extern crate embedded_hal_mock as hal; use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans};
use hal::i2c::Transaction as I2cTrans;
use hal::spi::Transaction as SpiTrans;
mod common; mod common;
use common::{ use common::{
destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234, Register, destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234, Register,
DEVICE_ADDRESS as DEV_ADDR, DEVICE_ADDRESS as DEV_ADDR,
}; };
extern crate ds323x;
#[allow(unused)] // Rust 1.31.0 is confused due to the macros #[allow(unused)] // Rust 1.31.0 is confused due to the macros
use ds323x::Rtcc; use ds323x::Rtcc;
use ds323x::{Error, Hours, NaiveDate, NaiveTime}; use ds323x::{Error, Hours, NaiveDate, NaiveTime};

View File

@ -1,9 +1,5 @@
extern crate embedded_hal_mock as hal;
use hal::i2c::Transaction as I2cTrans;
use hal::spi::Transaction as SpiTrans;
extern crate ds323x;
use ds323x::TempConvRate; use ds323x::TempConvRate;
use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans};
#[allow(unused)] #[allow(unused)]
mod common; mod common;

View File

@ -1,5 +1,4 @@
extern crate embedded_hal_mock as hal; use embedded_hal_mock::spi::Transaction as SpiTrans;
use hal::spi::Transaction as SpiTrans;
#[allow(unused)] #[allow(unused)]
mod common; mod common;

View File

@ -1,6 +1,4 @@
extern crate embedded_hal_mock as hal; use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans};
use hal::i2c::Transaction as I2cTrans;
use hal::spi::Transaction as SpiTrans;
mod common; mod common;
use common::{ use common::{
destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234, destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234,