Add support for checking if alarms have matched and clearing the flag

pull/4/head
Diego Barrios Romero 2018-11-03 07:58:24 +01:00
parent 0dec4954e9
commit d883c9c499
5 changed files with 53 additions and 4 deletions

View File

@ -19,6 +19,8 @@ This driver allows you to:
- Select the function of the INT/SQW output pin. See `use_int_sqw_output_as_interrupt`. - Select the function of the INT/SQW output pin. See `use_int_sqw_output_as_interrupt`.
- Enable and disable the square-wave generation. See `enable_square_wave`. - Enable and disable the square-wave generation. See `enable_square_wave`.
- Select the square-wave frequency. See `set_square_wave_frequency`. - Select the square-wave frequency. See `set_square_wave_frequency`.
- 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 the 32kHz output when battery-powered. See `enable_32khz_output_on_battery`. - Enable and disable the 32kHz output when battery-powered. See `enable_32khz_output_on_battery`.
- Set the temperature conversion rate. See `set_temperature_conversion_rate`. - 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`. - Enable and disable the temperature conversions when battery-powered. See `enable_temperature_conversions_on_battery`.

View File

@ -40,11 +40,39 @@ where
let status = self.status & !BitFlags::OSC_STOP; let status = self.status & !BitFlags::OSC_STOP;
self.write_status_without_clearing_alarm(status) self.write_status_without_clearing_alarm(status)
} }
/// 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()`](#method.clear_alarm1_matched_flag)
pub fn has_alarm1_matched(&mut self) -> Result<bool, Error<E>> {
let status = self.iface.read_register(Register::STATUS)?; let status = self.iface.read_register(Register::STATUS)?;
if (status & BitFlags::OSC_STOP) != 0 { Ok((status & BitFlags::ALARM1F) != 0)
self.iface.write_register(Register::STATUS, status & !BitFlags::OSC_STOP)?; }
}
Ok(()) /// Clear flag signalling whether the Alarm1 has matched at some point.
///
/// See also: [`has_alarm1_matched()`](#method.has_alarm1_matched)
pub fn clear_alarm1_matched_flag(&mut self) -> Result<(), Error<E>> {
let status = self.status | BitFlags::ALARM2F;
self.iface.write_register(Register::STATUS, status)
}
/// 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()`](#method.clear_alarm2_matched_flag)
pub fn has_alarm2_matched(&mut self) -> Result<bool, Error<E>> {
let status = self.iface.read_register(Register::STATUS)?;
Ok((status & BitFlags::ALARM2F) != 0)
}
/// Clear flag signalling whether the Alarm2 has matched at some point.
///
/// See also: [`has_alarm2_matched()`](#method.has_alarm2_matched)
pub fn clear_alarm2_matched_flag(&mut self) -> Result<(), Error<E>> {
let status = self.status | BitFlags::ALARM1F;
self.iface.write_register(Register::STATUS, status)
} }
/// Read the temperature. /// Read the temperature.

View File

@ -17,6 +17,8 @@
//! - Select the function of the INT/SQW output pin. See [`use_int_sqw_output_as_interrupt`]. //! - Select the function of the INT/SQW output pin. See [`use_int_sqw_output_as_interrupt`].
//! - Enable and disable the square-wave generation. See [`enable_square_wave`]. //! - Enable and disable the square-wave generation. See [`enable_square_wave`].
//! - Select the square-wave frequency. See [`set_square_wave_frequency`]. //! - Select the square-wave frequency. See [`set_square_wave_frequency`].
//! - 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 the 32kHz output when battery powered. See [`enable_32khz_output_on_battery`]. //! - Enable and disable the 32kHz output when battery powered. See [`enable_32khz_output_on_battery`].
//! - Set the temperature conversion rate. See [`set_temperature_conversion_rate`]. //! - 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`]. //! - Enable and disable the temperature conversions when battery-powered. See [`enable_temperature_conversions_on_battery`].
@ -34,6 +36,8 @@
//! [`use_int_sqw_output_as_interrupt`]: struct.Ds323x.html#method.use_int_sqw_output_as_interrupt //! [`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 //! [`enable_square_wave`]: struct.Ds323x.html#method.enable_square_wave
//! [`set_square_wave_frequency`]: struct.Ds323x.html#method.set_square_wave_frequency //! [`set_square_wave_frequency`]: struct.Ds323x.html#method.set_square_wave_frequency
//! [`has_alarm1_matched`]: struct.Ds323x.html#method.has_alarm1_matched
//! [`clear_alarm1_matched_flag`]: struct.Ds323x.html#method.clear_alarm1_matched_flag
//! [`enable_32khz_output_on_battery`]: struct.Ds323x.html#method.enable_32khz_output_on_battery //! [`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 //! [`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 //! [`enable_temperature_conversions_on_battery`]: struct.Ds323x.html#method.enable_temperature_conversions_on_battery

View File

@ -72,6 +72,15 @@ call_method_status_test!(en_32khz_out, enable_32khz_output,
call_method_status_test!(dis_32khz_out, disable_32khz_output, call_method_status_test!(dis_32khz_out, disable_32khz_output,
DS3231_POR_STATUS & !BF::EN32KHZ | BF::ALARM2F | BF::ALARM1F, DS3231_POR_STATUS & !BF::EN32KHZ | BF::ALARM2F | BF::ALARM1F,
DS323X_POR_STATUS & !BF::EN32KHZ | BF::ALARM2F | BF::ALARM1F); DS323X_POR_STATUS & !BF::EN32KHZ | BF::ALARM2F | BF::ALARM1F);
call_method_status_test!(clear_alarm1_matched, clear_alarm1_matched_flag,
DS3231_POR_STATUS | BF::ALARM2F,
DS323X_POR_STATUS | BF::ALARM2F);
call_method_status_test!(clear_alarm2_matched, clear_alarm2_matched_flag,
DS3231_POR_STATUS | BF::ALARM1F,
DS323X_POR_STATUS | BF::ALARM1F);
call_method_status_test!(clr_stop, clear_has_been_stopped_flag, call_method_status_test!(clr_stop, clear_has_been_stopped_flag,
DS3231_POR_STATUS & !BF::OSC_STOP | BF::ALARM2F | BF::ALARM1F, DS3231_POR_STATUS & !BF::OSC_STOP | BF::ALARM2F | BF::ALARM1F,
DS323X_POR_STATUS & !BF::OSC_STOP | BF::ALARM2F | BF::ALARM1F); DS323X_POR_STATUS & !BF::OSC_STOP | BF::ALARM2F | BF::ALARM1F);

View File

@ -17,6 +17,12 @@ get_param_test!(is_not_busy, is_busy, STATUS, false, 0xFF & !BF::BUSY);
get_param_test!(stopped, has_been_stopped, STATUS, true, 0xFF); get_param_test!(stopped, has_been_stopped, STATUS, true, 0xFF);
get_param_test!(not_stopped, has_been_stopped, STATUS, false, 0xFF & !BF::OSC_STOP); get_param_test!(not_stopped, has_been_stopped, STATUS, false, 0xFF & !BF::OSC_STOP);
get_param_test!(alarm1_matched, has_alarm1_matched, STATUS, true, 0xFF);
get_param_test!(alarm1_not_matched, has_alarm1_matched, STATUS, false, 0xFF & !BF::ALARM1F);
get_param_test!(alarm2_matched, has_alarm2_matched, STATUS, true, 0xFF);
get_param_test!(alarm2_not_matched, has_alarm2_matched, STATUS, false, 0xFF & !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, get_temperature, 0.0, TEMP_MSB, [0, 0], [0, 0]);
get_param_read_array_test!(temp_min, get_temperature, -128.0, TEMP_MSB, [0b1000_0000, 0], [0, 0]); get_param_read_array_test!(temp_min, get_temperature, -128.0, TEMP_MSB, [0b1000_0000, 0], [0, 0]);
get_param_read_array_test!(temp_max, get_temperature, 127.75, TEMP_MSB, [0b0111_1111, 0b1100_0000], [0, 0]); get_param_read_array_test!(temp_max, get_temperature, 127.75, TEMP_MSB, [0b0111_1111, 0b1100_0000], [0, 0]);