Rename date to day as it is a day of the month.

pull/4/head
Diego Barrios Romero 2018-11-16 18:22:30 +01:00
parent 5bff87333c
commit c10bf7de9d
5 changed files with 59 additions and 59 deletions

View File

@ -25,7 +25,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`.
- Alarms:
- Set alarms 1 and 2 with several matching policies. See `set_alarm1_date`.
- Set alarms 1 and 2 with several matching policies. See `set_alarm1_day`.
- Read whether alarms 1 or 2 have matched. See `has_alarm1_matched`.
- Clear flag indicating that alarms 1 or 2 have matched. See `clear_alarm1_matched_flag`.
- Enable and disable alarms 1 and 2 interrupt generation. See `enable_alarm1_interrupts`.

View File

@ -5,11 +5,11 @@ use super::super::{ Ds323x, Hours, Register, BitFlags, Error };
use interface::{ ReadData, WriteData };
use super::{ decimal_to_packed_bcd, hours_to_register };
/// Parameters for setting Alarm1 on a date
/// Parameters for setting Alarm1 on a day of the month
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DateAlarm1 {
/// Date (day of month) [1-31]
pub date: u8,
pub struct DayAlarm1 {
/// Day of the month [1-31]
pub day: u8,
/// Hour
pub hour: Hours,
/// Minute [0-59]
@ -47,11 +47,11 @@ pub enum Alarm1Matching {
}
/// Parameters for setting Alarm2 on a date
/// Parameters for setting Alarm2 on a day of the month
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DateAlarm2 {
/// Date (day of month) [1-31]
pub date: u8,
pub struct DayAlarm2 {
/// Day of month [1-31]
pub day: u8,
/// Hour
pub hour: Hours,
/// Minute [0-59]
@ -108,11 +108,11 @@ impl<DI, IC, E> Ds323x<DI, IC>
where
DI: ReadData<Error = E> + WriteData<Error = E>
{
/// Set Alarm1 for date (day of month).
/// Set Alarm1 for day of the month.
///
/// Will return an `Error::InvalidInputData` if any of the parameters is out of range.
pub fn set_alarm1_date(&mut self, when: DateAlarm1, matching: Alarm1Matching) -> Result<(), Error<E>> {
if when.date < 1 || when.date > 31 ||
pub fn set_alarm1_day(&mut self, when: DayAlarm1, matching: Alarm1Matching) -> Result<(), Error<E>> {
if when.day < 1 || when.day > 31 ||
when.minute > 59 ||
when.second > 59 {
return Err(Error::InvalidInputData);
@ -122,7 +122,7 @@ where
decimal_to_packed_bcd(when.second) | match_mask[0],
decimal_to_packed_bcd(when.minute) | match_mask[1],
hours_to_register(when.hour)? | match_mask[2],
decimal_to_packed_bcd(when.date) | match_mask[3]];
decimal_to_packed_bcd(when.day) | match_mask[3]];
self.iface.write_data(&mut data)
}
@ -147,8 +147,8 @@ where
/// Set Alarm2 for date (day of month).
///
/// Will return an `Error::InvalidInputData` if any of the parameters is out of range.
pub fn set_alarm2_date(&mut self, when: DateAlarm2, matching: Alarm2Matching) -> Result<(), Error<E>> {
if when.date < 1 || when.date > 31 ||
pub fn set_alarm2_day(&mut self, when: DayAlarm2, matching: Alarm2Matching) -> Result<(), Error<E>> {
if when.day < 1 || when.day > 31 ||
when.minute > 59 {
return Err(Error::InvalidInputData);
}
@ -156,7 +156,7 @@ where
let mut data = [ Register::ALARM2_MINUTES,
decimal_to_packed_bcd(when.minute) | match_mask[0],
hours_to_register(when.hour)? | match_mask[1],
decimal_to_packed_bcd(when.date) | match_mask[2]];
decimal_to_packed_bcd(when.day) | match_mask[2]];
self.iface.write_data(&mut data)
}

View File

@ -1,8 +1,8 @@
mod configuration;
mod status;
mod alarms;
pub use self::alarms::{ DateAlarm1, WeekdayAlarm1, Alarm1Matching,
DateAlarm2, WeekdayAlarm2, Alarm2Matching };
pub use self::alarms::{ DayAlarm1, WeekdayAlarm1, Alarm1Matching,
DayAlarm2, WeekdayAlarm2, Alarm2Matching };
mod datetime;
pub use self::datetime::{ Hours, DateTime };
use super::{ BitFlags, Error };

View File

@ -18,7 +18,7 @@
//! - 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`].
//! - Alarms:
//! - Set alarms 1 and 2 with several matching policies. See [`set_alarm1_date`].
//! - Set alarms 1 and 2 with several matching policies. See [`set_alarm1_day`].
//! - Read whether alarms 1 or 2 have matched. See [`has_alarm1_matched`].
//! - Clear flag indicating that alarms 1 or 2 have matched. See [`clear_alarm1_matched_flag`].
//! - Enable and disable alarms 1 and 2 interrupt generation. See [`enable_alarm1_interrupts`].
@ -41,7 +41,7 @@
//! [`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_date`]: struct.Ds323x.html#method.set_alarm1_date
//! [`set_alarm1_day`]: struct.Ds323x.html#method.set_alarm1_day
//! [`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
@ -419,17 +419,17 @@
//! ```no_run
//! extern crate linux_embedded_hal as hal;
//! extern crate ds323x;
//! use ds323x::{ Ds323x, Hours, DateAlarm2, Alarm2Matching };
//! use ds323x::{ Ds323x, Hours, DayAlarm2, Alarm2Matching };
//!
//! # fn main() {
//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
//! let mut rtc = Ds323x::new_ds3231(dev);
//! let alarm2 = DateAlarm2 {
//! date: 1, // does not matter given the chosen matching
//! let alarm2 = DayAlarm2 {
//! day: 1, // does not matter given the chosen matching
//! hour: Hours::AM(11),
//! minute: 2
//! };
//! rtc.set_alarm2_date(alarm2, Alarm2Matching::HoursAndMinutesMatch).unwrap();
//! rtc.set_alarm2_day(alarm2, Alarm2Matching::HoursAndMinutesMatch).unwrap();
//! rtc.use_int_sqw_output_as_interrupt().unwrap();
//! rtc.enable_alarm2_interrupts().unwrap();
//! # }
@ -549,8 +549,8 @@ pub struct Ds323x<DI, IC> {
pub mod interface;
mod ds323x;
pub use ds323x::{ Hours, DateTime, DateAlarm1, WeekdayAlarm1, Alarm1Matching,
DateAlarm2, WeekdayAlarm2, Alarm2Matching };
pub use ds323x::{ Hours, DateTime, DayAlarm1, WeekdayAlarm1, Alarm1Matching,
DayAlarm2, WeekdayAlarm2, Alarm2Matching };
mod ds3231;
mod ds3232;
mod ds3234;

View File

@ -8,7 +8,7 @@ use common::{ DEVICE_ADDRESS as DEV_ADDR, Register, new_ds3231,
new_ds3232, new_ds3234, destroy_ds3231, destroy_ds3232,
destroy_ds3234, BitFlags as BF };
extern crate ds323x;
use ds323x::{ DateAlarm1, WeekdayAlarm1, Alarm1Matching as A1M, DateAlarm2,
use ds323x::{ DayAlarm1, WeekdayAlarm1, Alarm1Matching as A1M, DayAlarm2,
WeekdayAlarm2, Alarm2Matching as A2M, Hours, Error };
#[macro_export]
@ -36,15 +36,15 @@ macro_rules! set_invalid_alarm_test {
mod alarm1 {
use super::*;
set_invalid_alarm_test!(date_invalid_s, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(1), minute: 1, second: 60 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_min, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(1), minute: 60, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_h, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(24), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_am1, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::AM(0), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_am2, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::AM(13), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_pm1, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::PM(0), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_pm2, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::PM(13), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_d1, set_alarm1_date, DateAlarm1{ date: 0, hour: Hours::H24(1), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(date_invalid_d2, set_alarm1_date, DateAlarm1{ date: 32, hour: Hours::H24(1), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_s, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(1), minute: 1, second: 60 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_min, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(1), minute: 60, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_h, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(24), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_am1, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::AM(0), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_am2, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::AM(13), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_pm1, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::PM(0), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_pm2, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::PM(13), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_d1, set_alarm1_day, DayAlarm1{ day: 0, hour: Hours::H24(1), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(day_invalid_d2, set_alarm1_day, DayAlarm1{ day: 32, hour: Hours::H24(1), minute: 1, second: 1 }, A1M::AllMatch);
set_invalid_alarm_test!(wd_invalid_s, set_alarm1_weekday, WeekdayAlarm1{ weekday: 1, hour: Hours::H24(1), minute: 1, second: 60 }, A1M::AllMatch);
set_invalid_alarm_test!(wd_invalid_min, set_alarm1_weekday, WeekdayAlarm1{ weekday: 1, hour: Hours::H24(1), minute: 60, second: 1 }, A1M::AllMatch);
@ -59,14 +59,14 @@ mod alarm1 {
mod alarm2 {
use super::*;
set_invalid_alarm_test!(date_invalid_min, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::H24(1), minute: 60 }, A2M::AllMatch);
set_invalid_alarm_test!(date_invalid_h, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::H24(24), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(date_invalid_am1, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::AM(0), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(date_invalid_am2, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::AM(13), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(date_invalid_pm1, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::PM(0), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(date_invalid_pm2, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::PM(13), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(date_invalid_d1, set_alarm2_date, DateAlarm2{ date: 0, hour: Hours::H24(1), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(date_invalid_d2, set_alarm2_date, DateAlarm2{ date: 32, hour: Hours::H24(1), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_min, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::H24(1), minute: 60 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_h, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::H24(24), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_am1, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::AM(0), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_am2, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::AM(13), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_pm1, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::PM(0), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_pm2, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::PM(13), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_d1, set_alarm2_day, DayAlarm2{ day: 0, hour: Hours::H24(1), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(day_invalid_d2, set_alarm2_day, DayAlarm2{ day: 32, hour: Hours::H24(1), minute: 1 }, A2M::AllMatch);
set_invalid_alarm_test!(wd_invalid_min, set_alarm2_weekday, WeekdayAlarm2{ weekday: 1, hour: Hours::H24(1), minute: 60 }, A2M::AllMatch);
set_invalid_alarm_test!(wd_invalid_h, set_alarm2_weekday, WeekdayAlarm2{ weekday: 1, hour: Hours::H24(24), minute: 1 }, A2M::AllMatch);
@ -112,22 +112,22 @@ macro_rules! set_alarm_test {
const AM : u8 = BF::ALARM_MATCH;
mod alarm1_date {
mod alarm1_day {
use super::*;
set_alarm_test!(h24, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::AllMatch,
set_alarm_test!(h24, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::AllMatch,
ALARM1_SECONDS, [4, 3, 2, 1]);
set_alarm_test!(am, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::AM(2), minute: 3, second: 4 }, A1M::AllMatch,
set_alarm_test!(am, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::AM(2), minute: 3, second: 4 }, A1M::AllMatch,
ALARM1_SECONDS, [4, 3, 0b0100_0010, 1]);
set_alarm_test!(pm, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::PM(2), minute: 3, second: 4 }, A1M::AllMatch,
set_alarm_test!(pm, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::PM(2), minute: 3, second: 4 }, A1M::AllMatch,
ALARM1_SECONDS, [4, 3, 0b0110_0010, 1]);
set_alarm_test!(match_hms, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::HoursMinutesAndSecondsMatch,
set_alarm_test!(match_hms, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::HoursMinutesAndSecondsMatch,
ALARM1_SECONDS, [ 4, 3, 2, AM | 1]);
set_alarm_test!(match_ms, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::MinutesAndSecondsMatch,
set_alarm_test!(match_ms, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::MinutesAndSecondsMatch,
ALARM1_SECONDS, [ 4, 3, AM | 2, AM | 1]);
set_alarm_test!(match_s, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::SecondsMatch,
set_alarm_test!(match_s, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::SecondsMatch,
ALARM1_SECONDS, [ 4, AM | 3, AM | 2, AM | 1]);
set_alarm_test!(match_ops, set_alarm1_date, DateAlarm1{ date: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::OncePerSecond,
set_alarm_test!(match_ops, set_alarm1_day, DayAlarm1{ day: 1, hour: Hours::H24(2), minute: 3, second: 4 }, A1M::OncePerSecond,
ALARM1_SECONDS, [AM | 4, AM | 3, AM | 2, AM | 1]);
}
@ -150,20 +150,20 @@ mod alarm1_weekday {
ALARM1_SECONDS, [AM | 4, AM | 3, AM | 2, AM | BF::WEEKDAY | 1]);
}
mod alarm2_date {
mod alarm2_day {
use super::*;
set_alarm_test!(h24, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::H24(2), minute: 3 }, A2M::AllMatch,
set_alarm_test!(h24, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::H24(2), minute: 3 }, A2M::AllMatch,
ALARM2_MINUTES, [3, 2, 1]);
set_alarm_test!(am, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::AM(2), minute: 3 }, A2M::AllMatch,
set_alarm_test!(am, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::AM(2), minute: 3 }, A2M::AllMatch,
ALARM2_MINUTES, [3, 0b0100_0010, 1]);
set_alarm_test!(pm, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::PM(2), minute: 3 }, A2M::AllMatch,
set_alarm_test!(pm, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::PM(2), minute: 3 }, A2M::AllMatch,
ALARM2_MINUTES, [3, 0b0110_0010, 1]);
set_alarm_test!(match_hm, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::H24(2), minute: 3 }, A2M::HoursAndMinutesMatch,
set_alarm_test!(match_hm, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::H24(2), minute: 3 }, A2M::HoursAndMinutesMatch,
ALARM2_MINUTES, [ 3, 2, AM | 1]);
set_alarm_test!(match_m, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::H24(2), minute: 3 }, A2M::MinutesMatch,
set_alarm_test!(match_m, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::H24(2), minute: 3 }, A2M::MinutesMatch,
ALARM2_MINUTES, [ 3, AM | 2, AM | 1]);
set_alarm_test!(match_opm, set_alarm2_date, DateAlarm2{ date: 1, hour: Hours::H24(2), minute: 3 }, A2M::OncePerMinute,
set_alarm_test!(match_opm, set_alarm2_day, DayAlarm2{ day: 1, hour: Hours::H24(2), minute: 3 }, A2M::OncePerMinute,
ALARM2_MINUTES, [AM | 3, AM | 2, AM | 1]);
}