mirror of https://github.com/eldruin/ds323x-rs
Update to rtcc 0.3
parent
fd66a531e2
commit
774b3cf527
|
@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
...
|
||||
### Changed
|
||||
|
||||
- [breaking-change] Update `rtcc` to version 0.3.
|
||||
- [breaking-change] Remove `get_` from all public method names to comply with the Rust API guidelines.
|
||||
|
||||
## [0.4.0] - 2021-05-22
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ include = [
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
embedded-hal = "0.2.6"
|
||||
rtcc = "0.2.1"
|
||||
embedded-hal = "0.2.7"
|
||||
rtcc = "0.3"
|
||||
|
||||
[dev-dependencies]
|
||||
embedded-hal-mock = "0.8.0"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (C) 2018-2021 Diego Barrios Romero
|
||||
Copyright (C) 2018-2022 Diego Barrios Romero
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
|
10
README.md
10
README.md
|
@ -12,8 +12,8 @@ extremely accurate real-time clocks, based on the [`embedded-hal`] traits.
|
|||
[`embedded-hal`]: https://github.com/rust-embedded/embedded-hal
|
||||
|
||||
This driver allows you to:
|
||||
- Read and set date and time in 12-hour and 24-hour format. See: `get_datetime`.
|
||||
- Read and set date and time individual elements. For example, see: `get_year`.
|
||||
- Read and set date and time in 12-hour and 24-hour format. See: `datetime`.
|
||||
- Read and set date and time individual elements. For example, see: `year`.
|
||||
- Enable and disable the real-time clock. See: `enable`.
|
||||
- Read the busy status. See `busy`.
|
||||
- Read whether the oscillator is or has been stopped. See `has_been_stopped`.
|
||||
|
@ -32,7 +32,7 @@ This driver allows you to:
|
|||
- Enable and disable the 32kHz output. See `enable_32khz_output`.
|
||||
- Enable and disable the 32kHz output when battery powered. See `enable_32khz_output_on_battery`.
|
||||
- Temperature conversion:
|
||||
- Read the temperature. See `get_temperature`.
|
||||
- Read the temperature. See `temperature`.
|
||||
- Force a temperature conversion and time compensation. See `convert_temperature`.
|
||||
- Set the temperature conversion rate. See `set_temperature_conversion_rate`.
|
||||
- Enable and disable the temperature conversions when battery-powered. See `enable_temperature_conversions_on_battery`.
|
||||
|
@ -111,7 +111,7 @@ Please find additional examples using hardware in this repository: [driver-examp
|
|||
[driver-examples]: https://github.com/eldruin/driver-examples
|
||||
|
||||
```rust
|
||||
use ds323x::{Ds323x, NaiveDate, Rtcc};
|
||||
use ds323x::{DateTimeAccess, Ds323x, NaiveDate, Rtcc};
|
||||
use linux_embedded_hal::I2cdev;
|
||||
|
||||
fn main() {
|
||||
|
@ -120,7 +120,7 @@ fn main() {
|
|||
let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58);
|
||||
rtc.set_datetime(&datetime).unwrap();
|
||||
// do something else...
|
||||
let time = rtc.get_time().unwrap();
|
||||
let time = rtc.time().unwrap();
|
||||
println!("Time: {}", time);
|
||||
|
||||
let _dev = rtc.destroy_ds3231();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ds323x::{Ds323x, NaiveDate, Rtcc};
|
||||
use ds323x::{DateTimeAccess, Ds323x, NaiveDate, Rtcc};
|
||||
use linux_embedded_hal::I2cdev;
|
||||
|
||||
fn main() {
|
||||
|
@ -7,7 +7,7 @@ fn main() {
|
|||
let datetime = NaiveDate::from_ymd(2020, 5, 1).and_hms(19, 59, 58);
|
||||
rtc.set_datetime(&datetime).unwrap();
|
||||
// do something else...
|
||||
let time = rtc.get_time().unwrap();
|
||||
let time = rtc.time().unwrap();
|
||||
println!("Time: {}", time);
|
||||
|
||||
let _dev = rtc.destroy_ds3231();
|
||||
|
|
|
@ -53,7 +53,7 @@ where
|
|||
}
|
||||
|
||||
/// Read the aging offset.
|
||||
pub fn get_aging_offset(&mut self) -> Result<i8, Error<CommE, PinE>> {
|
||||
pub fn aging_offset(&mut self) -> Result<i8, Error<CommE, PinE>> {
|
||||
let offset = self.iface.read_register(Register::AGING_OFFSET)?;
|
||||
Ok(offset as i8)
|
||||
}
|
||||
|
|
|
@ -5,79 +5,17 @@ use super::{
|
|||
};
|
||||
use crate::{
|
||||
interface::{ReadData, WriteData},
|
||||
BitFlags, Datelike, Ds323x, Error, Hours, NaiveDate, NaiveDateTime, NaiveTime, Register, Rtcc,
|
||||
Timelike,
|
||||
BitFlags, DateTimeAccess, 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> DateTimeAccess for Ds323x<DI, IC>
|
||||
where
|
||||
DI: ReadData<Error = Error<CommE, PinE>> + WriteData<Error = Error<CommE, PinE>>,
|
||||
{
|
||||
type Error = Error<CommE, PinE>;
|
||||
|
||||
fn get_seconds(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::SECONDS)
|
||||
}
|
||||
|
||||
fn get_minutes(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::MINUTES)
|
||||
}
|
||||
|
||||
fn get_hours(&mut self) -> Result<Hours, Self::Error> {
|
||||
let data = self.iface.read_register(Register::HOURS)?;
|
||||
Ok(hours_from_register(data))
|
||||
}
|
||||
|
||||
fn get_time(&mut self) -> Result<NaiveTime, Self::Error> {
|
||||
let mut data = [0; 4];
|
||||
self.iface.read_data(&mut data)?;
|
||||
let hour = hours_from_register(data[Register::HOURS as usize + 1]);
|
||||
let minute = packed_bcd_to_decimal(data[Register::MINUTES as usize + 1]);
|
||||
let second = packed_bcd_to_decimal(data[Register::SECONDS as usize + 1]);
|
||||
|
||||
let time = NaiveTime::from_hms_opt(get_h24(hour).into(), minute.into(), second.into());
|
||||
some_or_invalid_error(time)
|
||||
}
|
||||
|
||||
fn get_weekday(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::DOW)
|
||||
}
|
||||
|
||||
fn get_day(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::DOM)
|
||||
}
|
||||
|
||||
fn get_month(&mut self) -> Result<u8, Self::Error> {
|
||||
let data = self.iface.read_register(Register::MONTH)?;
|
||||
let value = data & !BitFlags::CENTURY;
|
||||
Ok(packed_bcd_to_decimal(value))
|
||||
}
|
||||
|
||||
fn get_year(&mut self) -> Result<u16, Self::Error> {
|
||||
let mut data = [0; 3];
|
||||
data[0] = Register::MONTH;
|
||||
self.iface.read_data(&mut data)?;
|
||||
Ok(year_from_registers(data[1], data[2]))
|
||||
}
|
||||
|
||||
fn get_date(&mut self) -> Result<NaiveDate, Self::Error> {
|
||||
let mut data = [0; 4];
|
||||
data[0] = Register::DOM;
|
||||
self.iface.read_data(&mut data)?;
|
||||
|
||||
let offset = Register::DOM as usize;
|
||||
let year = year_from_registers(
|
||||
data[Register::MONTH as usize + 1 - offset],
|
||||
data[Register::YEAR as usize + 1 - offset],
|
||||
);
|
||||
let month =
|
||||
packed_bcd_to_decimal(data[Register::MONTH as usize + 1 - offset] & !BitFlags::CENTURY);
|
||||
let day = packed_bcd_to_decimal(data[Register::DOM as usize + 1 - offset]);
|
||||
let date = NaiveDate::from_ymd_opt(year.into(), month.into(), day.into());
|
||||
some_or_invalid_error(date)
|
||||
}
|
||||
|
||||
fn get_datetime(&mut self) -> Result<NaiveDateTime, Self::Error> {
|
||||
fn datetime(&mut self) -> Result<NaiveDateTime, Self::Error> {
|
||||
let mut data = [0; 8];
|
||||
self.iface.read_data(&mut data)?;
|
||||
|
||||
|
@ -97,6 +35,91 @@ where
|
|||
some_or_invalid_error(datetime)
|
||||
}
|
||||
|
||||
fn set_datetime(&mut self, datetime: &NaiveDateTime) -> Result<(), Self::Error> {
|
||||
if datetime.year() < 2000 || datetime.year() > 2100 {
|
||||
return Err(Error::InvalidInputData);
|
||||
}
|
||||
let (month, year) = month_year_to_registers(datetime.month() as u8, datetime.year() as u16);
|
||||
let mut payload = [
|
||||
Register::SECONDS,
|
||||
decimal_to_packed_bcd(datetime.second() as u8),
|
||||
decimal_to_packed_bcd(datetime.minute() as u8),
|
||||
hours_to_register(Hours::H24(datetime.hour() as u8))?,
|
||||
datetime.weekday().number_from_sunday() as u8,
|
||||
decimal_to_packed_bcd(datetime.day() as u8),
|
||||
month,
|
||||
year,
|
||||
];
|
||||
self.iface.write_data(&mut payload)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DI, IC, CommE, PinE> Rtcc for Ds323x<DI, IC>
|
||||
where
|
||||
DI: ReadData<Error = Error<CommE, PinE>> + WriteData<Error = Error<CommE, PinE>>,
|
||||
{
|
||||
fn seconds(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::SECONDS)
|
||||
}
|
||||
|
||||
fn minutes(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::MINUTES)
|
||||
}
|
||||
|
||||
fn hours(&mut self) -> Result<Hours, Self::Error> {
|
||||
let data = self.iface.read_register(Register::HOURS)?;
|
||||
Ok(hours_from_register(data))
|
||||
}
|
||||
|
||||
fn time(&mut self) -> Result<NaiveTime, Self::Error> {
|
||||
let mut data = [0; 4];
|
||||
self.iface.read_data(&mut data)?;
|
||||
let hour = hours_from_register(data[Register::HOURS as usize + 1]);
|
||||
let minute = packed_bcd_to_decimal(data[Register::MINUTES as usize + 1]);
|
||||
let second = packed_bcd_to_decimal(data[Register::SECONDS as usize + 1]);
|
||||
|
||||
let time = NaiveTime::from_hms_opt(get_h24(hour).into(), minute.into(), second.into());
|
||||
some_or_invalid_error(time)
|
||||
}
|
||||
|
||||
fn weekday(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::DOW)
|
||||
}
|
||||
|
||||
fn day(&mut self) -> Result<u8, Self::Error> {
|
||||
self.read_register_decimal(Register::DOM)
|
||||
}
|
||||
|
||||
fn month(&mut self) -> Result<u8, Self::Error> {
|
||||
let data = self.iface.read_register(Register::MONTH)?;
|
||||
let value = data & !BitFlags::CENTURY;
|
||||
Ok(packed_bcd_to_decimal(value))
|
||||
}
|
||||
|
||||
fn year(&mut self) -> Result<u16, Self::Error> {
|
||||
let mut data = [0; 3];
|
||||
data[0] = Register::MONTH;
|
||||
self.iface.read_data(&mut data)?;
|
||||
Ok(year_from_registers(data[1], data[2]))
|
||||
}
|
||||
|
||||
fn date(&mut self) -> Result<NaiveDate, Self::Error> {
|
||||
let mut data = [0; 4];
|
||||
data[0] = Register::DOM;
|
||||
self.iface.read_data(&mut data)?;
|
||||
|
||||
let offset = Register::DOM as usize;
|
||||
let year = year_from_registers(
|
||||
data[Register::MONTH as usize + 1 - offset],
|
||||
data[Register::YEAR as usize + 1 - offset],
|
||||
);
|
||||
let month =
|
||||
packed_bcd_to_decimal(data[Register::MONTH as usize + 1 - offset] & !BitFlags::CENTURY);
|
||||
let day = packed_bcd_to_decimal(data[Register::DOM as usize + 1 - offset]);
|
||||
let date = NaiveDate::from_ymd_opt(year.into(), month.into(), day.into());
|
||||
some_or_invalid_error(date)
|
||||
}
|
||||
|
||||
fn set_seconds(&mut self, seconds: u8) -> Result<(), Self::Error> {
|
||||
if seconds > 59 {
|
||||
return Err(Error::InvalidInputData);
|
||||
|
@ -187,24 +210,6 @@ where
|
|||
];
|
||||
self.iface.write_data(&mut payload)
|
||||
}
|
||||
|
||||
fn set_datetime(&mut self, datetime: &NaiveDateTime) -> Result<(), Self::Error> {
|
||||
if datetime.year() < 2000 || datetime.year() > 2100 {
|
||||
return Err(Error::InvalidInputData);
|
||||
}
|
||||
let (month, year) = month_year_to_registers(datetime.month() as u8, datetime.year() as u16);
|
||||
let mut payload = [
|
||||
Register::SECONDS,
|
||||
decimal_to_packed_bcd(datetime.second() as u8),
|
||||
decimal_to_packed_bcd(datetime.minute() as u8),
|
||||
hours_to_register(Hours::H24(datetime.hour() as u8))?,
|
||||
datetime.weekday().number_from_sunday() as u8,
|
||||
decimal_to_packed_bcd(datetime.day() as u8),
|
||||
month,
|
||||
year,
|
||||
];
|
||||
self.iface.write_data(&mut payload)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DI, IC, CommE, PinE> Ds323x<DI, IC>
|
||||
|
|
|
@ -80,7 +80,7 @@ where
|
|||
///
|
||||
/// Note: It is possible to manually force a temperature conversion with
|
||||
/// [`convert_temperature()`](#method.convert_temperature)
|
||||
pub fn get_temperature(&mut self) -> Result<f32, Error<CommE, PinE>> {
|
||||
pub fn temperature(&mut self) -> Result<f32, Error<CommE, PinE>> {
|
||||
let mut data = [Register::TEMP_MSB, 0, 0];
|
||||
self.iface.read_data(&mut data)?;
|
||||
let is_negative = (data[1] & 0b1000_0000) != 0;
|
||||
|
|
62
src/lib.rs
62
src/lib.rs
|
@ -4,8 +4,8 @@
|
|||
//! [`embedded-hal`]: https://github.com/rust-embedded/embedded-hal
|
||||
//!
|
||||
//! This driver allows you to:
|
||||
//! - Read and set date and time in 12-hour and 24-hour format. See: [`get_datetime`].
|
||||
//! - Read and set date and time individual elements. For example, see: [`get_year`].
|
||||
//! - Read and set date and time in 12-hour and 24-hour format. See: [`datetime`].
|
||||
//! - Read and set date and time individual elements. For example, see: [`year`].
|
||||
//! - Enable and disable the real-time clock. See: [`enable`].
|
||||
//! - Read the busy status. See [`busy`].
|
||||
//! - Read whether the oscillator is or has been stopped. See [`has_been_stopped`].
|
||||
|
@ -24,32 +24,32 @@
|
|||
//! - Enable and disable the 32kHz output. See [`enable_32khz_output`].
|
||||
//! - Enable and disable the 32kHz output when battery powered. See [`enable_32khz_output_on_battery`].
|
||||
//! - Temperature conversion:
|
||||
//! - Read the temperature. See [`get_temperature`].
|
||||
//! - Read the temperature. See [`temperature`].
|
||||
//! - Force a temperature conversion and time compensation. See [`convert_temperature`].
|
||||
//! - Set the temperature conversion rate. See [`set_temperature_conversion_rate`].
|
||||
//! - Enable and disable the temperature conversions when battery-powered. See [`enable_temperature_conversions_on_battery`].
|
||||
//!
|
||||
//! [`get_datetime`]: struct.Ds323x.html#method.get_datetime
|
||||
//! [`get_year`]: struct.Ds323x.html#method.get_year
|
||||
//! [`enable`]: struct.Ds323x.html#method.enable
|
||||
//! [`get_temperature`]: struct.Ds323x.html#method.get_temperature
|
||||
//! [`convert_temperature`]: struct.Ds323x.html#method.convert_temperature
|
||||
//! [`busy`]: struct.Ds323x.html#method.busy
|
||||
//! [`has_been_stopped`]: struct.Ds323x.html#method.has_been_stopped
|
||||
//! [`clear_has_been_stopped_flag`]: struct.Ds323x.html#method.clear_has_been_stopped_flag
|
||||
//! [`set_aging_offset`]: struct.Ds323x.html#method.set_aging_offset
|
||||
//! [`enable_32khz_output`]: struct.Ds323x.html#method.enable_32khz_output
|
||||
//! [`use_int_sqw_output_as_interrupt`]: struct.Ds323x.html#method.use_int_sqw_output_as_interrupt
|
||||
//! [`enable_square_wave`]: struct.Ds323x.html#method.enable_square_wave
|
||||
//! [`set_square_wave_frequency`]: struct.Ds323x.html#method.set_square_wave_frequency
|
||||
//! [`set_alarm1_day`]: struct.Ds323x.html#method.set_alarm1_day
|
||||
//! [`set_alarm1_hms`]: struct.Ds323x.html#method.set_alarm1_hms
|
||||
//! [`has_alarm1_matched`]: struct.Ds323x.html#method.has_alarm1_matched
|
||||
//! [`clear_alarm1_matched_flag`]: struct.Ds323x.html#method.clear_alarm1_matched_flag
|
||||
//! [`enable_alarm1_interrupts`]: struct.Ds323x.html#method.enable_alarm1_interrupts
|
||||
//! [`enable_32khz_output_on_battery`]: struct.Ds323x.html#method.enable_32khz_output_on_battery
|
||||
//! [`set_temperature_conversion_rate`]: struct.Ds323x.html#method.set_temperature_conversion_rate
|
||||
//! [`enable_temperature_conversions_on_battery`]: struct.Ds323x.html#method.enable_temperature_conversions_on_battery
|
||||
//! [`datetime`]: Ds323x::datetime
|
||||
//! [`year`]: Ds323x::year
|
||||
//! [`enable`]: Ds323x::enable
|
||||
//! [`temperature`]: Ds323x::temperature
|
||||
//! [`convert_temperature`]: Ds323x::convert_temperature
|
||||
//! [`busy`]: Ds323x::busy
|
||||
//! [`has_been_stopped`]: Ds323x::has_been_stopped
|
||||
//! [`clear_has_been_stopped_flag`]: Ds323x::clear_has_been_stopped_flag
|
||||
//! [`set_aging_offset`]: Ds323x::set_aging_offset
|
||||
//! [`enable_32khz_output`]: Ds323x::enable_32khz_output
|
||||
//! [`use_int_sqw_output_as_interrupt`]: Ds323x::use_int_sqw_output_as_interrupt
|
||||
//! [`enable_square_wave`]: Ds323x::enable_square_wave
|
||||
//! [`set_square_wave_frequency`]: Ds323x::set_square_wave_frequency
|
||||
//! [`set_alarm1_day`]: Ds323x::set_alarm1_day
|
||||
//! [`set_alarm1_hms`]: Ds323x::set_alarm1_hms
|
||||
//! [`has_alarm1_matched`]: Ds323x::has_alarm1_matched
|
||||
//! [`clear_alarm1_matched_flag`]: Ds323x::clear_alarm1_matched_flag
|
||||
//! [`enable_alarm1_interrupts`]: Ds323x::enable_alarm1_interrupts
|
||||
//! [`enable_32khz_output_on_battery`]: Ds323x::enable_32khz_output_on_battery
|
||||
//! [`set_temperature_conversion_rate`]: Ds323x::set_temperature_conversion_rate
|
||||
//! [`enable_temperature_conversions_on_battery`]: Ds323x::enable_temperature_conversions_on_battery
|
||||
//!
|
||||
//! ## The devices
|
||||
//!
|
||||
|
@ -198,7 +198,7 @@
|
|||
//! ### Set the current date and time at once
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use ds323x::{Ds323x, NaiveDate, Rtcc};
|
||||
//! use ds323x::{Ds323x, NaiveDate, DateTimeAccess};
|
||||
//! use linux_embedded_hal::I2cdev;
|
||||
//!
|
||||
//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
|
||||
|
@ -210,12 +210,12 @@
|
|||
//! ### Get the current date and time at once
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use ds323x::{Ds323x, Rtcc};
|
||||
//! use ds323x::{Ds323x, DateTimeAccess};
|
||||
//! use linux_embedded_hal::I2cdev;
|
||||
//!
|
||||
//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
|
||||
//! let mut rtc = Ds323x::new_ds3231(dev);
|
||||
//! let dt = rtc.get_datetime().unwrap();
|
||||
//! let dt = rtc.datetime().unwrap();
|
||||
//! println!("{}", dt);
|
||||
//! // This will print something like: 2020-05-01 19:59:58
|
||||
//! ```
|
||||
|
@ -230,7 +230,7 @@
|
|||
//!
|
||||
//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
|
||||
//! let mut rtc = Ds323x::new_ds3231(dev);
|
||||
//! let year = rtc.get_year().unwrap();
|
||||
//! let year = rtc.year().unwrap();
|
||||
//! println!("Year: {}", year);
|
||||
//! ```
|
||||
//!
|
||||
|
@ -270,7 +270,7 @@
|
|||
//!
|
||||
//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
|
||||
//! let mut rtc = Ds323x::new_ds3231(dev);
|
||||
//! let temperature = rtc.get_temperature().unwrap();
|
||||
//! let temperature = rtc.temperature().unwrap();
|
||||
//! ```
|
||||
//!
|
||||
//! ### Read busy status
|
||||
|
@ -392,7 +392,9 @@
|
|||
|
||||
use core::marker::PhantomData;
|
||||
use embedded_hal::spi::{Mode, MODE_1, MODE_3};
|
||||
pub use rtcc::{Datelike, Hours, NaiveDate, NaiveDateTime, NaiveTime, Rtcc, Timelike};
|
||||
pub use rtcc::{
|
||||
DateTimeAccess, Datelike, Hours, NaiveDate, NaiveDateTime, NaiveTime, Rtcc, Timelike,
|
||||
};
|
||||
|
||||
/// SPI mode 1 (CPOL = 0, CPHA = 1)
|
||||
pub const SPI_MODE_1: Mode = MODE_1;
|
||||
|
|
|
@ -220,18 +220,12 @@ set_param_test!(
|
|||
|
||||
get_param_test!(
|
||||
get_aging_offset_min,
|
||||
get_aging_offset,
|
||||
aging_offset,
|
||||
AGING_OFFSET,
|
||||
-128,
|
||||
0b1000_0000
|
||||
);
|
||||
get_param_test!(
|
||||
get_aging_offset_max,
|
||||
get_aging_offset,
|
||||
AGING_OFFSET,
|
||||
127,
|
||||
127
|
||||
);
|
||||
get_param_test!(get_aging_offset_max, aging_offset, AGING_OFFSET, 127, 127);
|
||||
|
||||
call_method_test!(
|
||||
int_sqw_out_int,
|
||||
|
|
|
@ -6,7 +6,7 @@ use self::common::{
|
|||
};
|
||||
#[allow(unused)] // Rust 1.31.0 is confused due to the macros
|
||||
use ds323x::Rtcc;
|
||||
use ds323x::{Error, Hours, NaiveDate, NaiveTime};
|
||||
use ds323x::{DateTimeAccess, Error, Hours, NaiveDate, NaiveTime};
|
||||
|
||||
macro_rules! read_set_param_write_two_test {
|
||||
($name:ident, $method:ident, $value:expr, $register:ident, $binary_value1_read:expr, $bin1:expr, $bin2:expr) => {
|
||||
|
@ -113,76 +113,69 @@ macro_rules! for_all {
|
|||
|
||||
mod seconds {
|
||||
use super::*;
|
||||
get_param_test!(get, get_seconds, SECONDS, 1, 1);
|
||||
get_param_test!(get, seconds, SECONDS, 1, 1);
|
||||
set_param_test!(set, set_seconds, SECONDS, 1, 1);
|
||||
set_invalid_param_test!(invalid, set_seconds, 60);
|
||||
}
|
||||
|
||||
mod minutes {
|
||||
use super::*;
|
||||
get_param_test!(get, get_minutes, MINUTES, 1, 1);
|
||||
get_param_test!(get, minutes, MINUTES, 1, 1);
|
||||
set_param_test!(set, set_minutes, MINUTES, 1, 1);
|
||||
set_invalid_param_test!(invalid, set_minutes, 60);
|
||||
}
|
||||
|
||||
mod hours_24h {
|
||||
use super::*;
|
||||
get_param_test!(get, get_hours, HOURS, Hours::H24(21), 0b0010_0001);
|
||||
get_param_test!(get, hours, HOURS, Hours::H24(21), 0b0010_0001);
|
||||
set_param_test!(set, set_hours, HOURS, Hours::H24(21), 0b0010_0001);
|
||||
set_invalid_param_test!(invalid, set_hours, Hours::H24(24));
|
||||
}
|
||||
|
||||
mod hours_12h_am {
|
||||
use super::*;
|
||||
get_param_test!(get, get_hours, HOURS, Hours::AM(12), 0b0101_0010);
|
||||
get_param_test!(get, hours, HOURS, Hours::AM(12), 0b0101_0010);
|
||||
set_param_test!(set, set_hours, HOURS, Hours::AM(12), 0b0101_0010);
|
||||
set_invalid_param_range_test!(invalid, set_hours, Hours::AM(0), Hours::AM(13));
|
||||
}
|
||||
|
||||
mod hours_12h_pm {
|
||||
use super::*;
|
||||
get_param_test!(get, get_hours, HOURS, Hours::PM(12), 0b0111_0010);
|
||||
get_param_test!(get, hours, HOURS, Hours::PM(12), 0b0111_0010);
|
||||
set_param_test!(set, set_hours, HOURS, Hours::PM(12), 0b0111_0010);
|
||||
set_invalid_param_range_test!(invalid, set_hours, Hours::PM(0), Hours::PM(13));
|
||||
}
|
||||
|
||||
mod weekday {
|
||||
use super::*;
|
||||
get_param_test!(get, get_weekday, DOW, 1, 1);
|
||||
get_param_test!(get, weekday, DOW, 1, 1);
|
||||
set_param_test!(set, set_weekday, DOW, 1, 1);
|
||||
set_invalid_param_range_test!(invalid, set_weekday, 0, 8);
|
||||
}
|
||||
|
||||
mod day {
|
||||
use super::*;
|
||||
get_param_test!(get, get_day, DOM, 1, 1);
|
||||
get_param_test!(get, day, DOM, 1, 1);
|
||||
set_param_test!(set, set_day, DOM, 1, 1);
|
||||
set_invalid_param_range_test!(invalid, set_day, 0, 32);
|
||||
}
|
||||
|
||||
mod month {
|
||||
use super::*;
|
||||
get_param_test!(get, get_month, MONTH, 1, 1);
|
||||
get_param_test!(get, month, MONTH, 1, 1);
|
||||
read_set_param_test!(set, set_month, MONTH, 12, 0b0000_0010, 0b0001_0010);
|
||||
set_invalid_param_range_test!(invalid, set_month, 0, 13);
|
||||
|
||||
mod keeps_century {
|
||||
use super::*;
|
||||
get_param_test!(get, get_month, MONTH, 12, 0b1001_0010);
|
||||
get_param_test!(get, month, MONTH, 12, 0b1001_0010);
|
||||
read_set_param_test!(set, set_month, MONTH, 12, 0b1000_0010, 0b1001_0010);
|
||||
}
|
||||
}
|
||||
|
||||
mod year {
|
||||
use super::*;
|
||||
get_param_read_array_test!(
|
||||
century0_get,
|
||||
get_year,
|
||||
2099,
|
||||
MONTH,
|
||||
[0, 0b1001_1001],
|
||||
[0, 0]
|
||||
);
|
||||
get_param_read_array_test!(century0_get, year, 2099, MONTH, [0, 0b1001_1001], [0, 0]);
|
||||
read_set_param_write_two_test!(
|
||||
century0_set,
|
||||
set_year,
|
||||
|
@ -193,14 +186,7 @@ mod year {
|
|||
0b1001_1001
|
||||
);
|
||||
|
||||
get_param_read_array_test!(
|
||||
century1_get,
|
||||
get_year,
|
||||
2100,
|
||||
MONTH,
|
||||
[0b1000_0000, 0],
|
||||
[0, 0]
|
||||
);
|
||||
get_param_read_array_test!(century1_get, year, 2100, MONTH, [0b1000_0000, 0], [0, 0]);
|
||||
read_set_param_write_two_test!(
|
||||
century1_set,
|
||||
set_year,
|
||||
|
@ -283,7 +269,7 @@ macro_rules! dt_test {
|
|||
],
|
||||
[0, 0, 0, 0, 0, 0, 0]
|
||||
));
|
||||
assert_eq!(dt, dev.get_datetime().unwrap());
|
||||
assert_eq!(dt, dev.datetime().unwrap());
|
||||
$destroy_method(dev);
|
||||
}
|
||||
|
||||
|
@ -314,7 +300,7 @@ macro_rules! dt_test {
|
|||
[0b0001_0011, 0b0000_1000, 0b0001_1000],
|
||||
[0, 0, 0]
|
||||
));
|
||||
assert_eq!(d, dev.get_date().unwrap());
|
||||
assert_eq!(d, dev.date().unwrap());
|
||||
$destroy_method(dev);
|
||||
}
|
||||
|
||||
|
@ -348,7 +334,7 @@ macro_rules! dt_test {
|
|||
[0b0101_1000, 0b0101_1001, 0b0010_0011],
|
||||
[0, 0, 0]
|
||||
));
|
||||
assert_eq!(t, dev.get_time().unwrap());
|
||||
assert_eq!(t, dev.time().unwrap());
|
||||
$destroy_method(dev);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ get_param_test!(
|
|||
!BF::ALARM2F
|
||||
);
|
||||
|
||||
get_param_read_array_test!(temp_0, get_temperature, 0.0, TEMP_MSB, [0, 0], [0, 0]);
|
||||
get_param_read_array_test!(temp_0, temperature, 0.0, TEMP_MSB, [0, 0], [0, 0]);
|
||||
get_param_read_array_test!(
|
||||
temp_min,
|
||||
get_temperature,
|
||||
temperature,
|
||||
-128.0,
|
||||
TEMP_MSB,
|
||||
[0b1000_0000, 0],
|
||||
|
@ -43,7 +43,7 @@ get_param_read_array_test!(
|
|||
);
|
||||
get_param_read_array_test!(
|
||||
temp_max,
|
||||
get_temperature,
|
||||
temperature,
|
||||
127.75,
|
||||
TEMP_MSB,
|
||||
[0b0111_1111, 0b1100_0000],
|
||||
|
|
Loading…
Reference in New Issue