Add support for enabling/disabling alarm interrupts

pull/4/head
Diego Barrios Romero 2018-11-03 07:59:41 +01:00
parent d883c9c499
commit 7e9bfcff13
5 changed files with 37 additions and 0 deletions

View File

@ -21,6 +21,7 @@ This driver allows you to:
- 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`. - 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`. - 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`.
- 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

@ -91,6 +91,30 @@ where
self.write_control(new_control) self.write_control(new_control)
} }
/// Enable Alarm1 interrupts.
pub fn enable_alarm1_interrupts(&mut self) -> Result<(), Error<E>> {
let control = self.control;
self.write_control(control | BitFlags::ALARM1_INT_EN)
}
/// Disable Alarm1 interrupts.
pub fn disable_alarm1_interrupts(&mut self) -> Result<(), Error<E>> {
let control = self.control;
self.write_control(control & !BitFlags::ALARM1_INT_EN)
}
/// Enable Alarm2 interrupts.
pub fn enable_alarm2_interrupts(&mut self) -> Result<(), Error<E>> {
let control = self.control;
self.write_control(control | BitFlags::ALARM2_INT_EN)
}
/// Disable Alarm2 interrupts.
pub fn disable_alarm2_interrupts(&mut self) -> Result<(), Error<E>> {
let control = self.control;
self.write_control(control & !BitFlags::ALARM2_INT_EN)
}
fn write_control(&mut self, control: u8) -> Result<(), Error<E>> { fn write_control(&mut self, control: u8) -> Result<(), Error<E>> {
self.iface.write_register(Register::CONTROL, control)?; self.iface.write_register(Register::CONTROL, control)?;
self.control = control; self.control = control;

View File

@ -19,6 +19,7 @@
//! - 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`]. //! - 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`]. //! - 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`].
//! - 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`].
@ -38,6 +39,7 @@
//! [`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 //! [`has_alarm1_matched`]: struct.Ds323x.html#method.has_alarm1_matched
//! [`clear_alarm1_matched_flag`]: struct.Ds323x.html#method.clear_alarm1_matched_flag //! [`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 //! [`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
@ -459,6 +461,8 @@ impl BitFlags {
const RS2 : u8 = 0b0001_0000; const RS2 : u8 = 0b0001_0000;
const RS1 : u8 = 0b0000_1000; const RS1 : u8 = 0b0000_1000;
const INTCN : u8 = 0b0000_0100; const INTCN : u8 = 0b0000_0100;
const ALARM2_INT_EN : u8 = 0b0000_0010;
const ALARM1_INT_EN : u8 = 0b0000_0001;
const OSC_STOP : u8 = 0b1000_0000; const OSC_STOP : u8 = 0b1000_0000;
const BB32KHZ : u8 = 0b0100_0000; const BB32KHZ : u8 = 0b0100_0000;
const CRATE1 : u8 = 0b0010_0000; const CRATE1 : u8 = 0b0010_0000;

View File

@ -39,6 +39,8 @@ impl BitFlags {
pub const RS2 : u8 = 0b0001_0000; pub const RS2 : u8 = 0b0001_0000;
pub const RS1 : u8 = 0b0000_1000; pub const RS1 : u8 = 0b0000_1000;
pub const INTCN : u8 = 0b0000_0100; pub const INTCN : u8 = 0b0000_0100;
pub const ALARM2_INT_EN : u8 = 0b0000_0010;
pub const ALARM1_INT_EN : u8 = 0b0000_0001;
pub const OSC_STOP : u8 = 0b1000_0000; pub const OSC_STOP : u8 = 0b1000_0000;
pub const BB32KHZ : u8 = 0b0100_0000; pub const BB32KHZ : u8 = 0b0100_0000;
pub const CRATE1 : u8 = 0b0010_0000; pub const CRATE1 : u8 = 0b0010_0000;

View File

@ -87,6 +87,12 @@ call_method_status_test!(clr_stop, clear_has_been_stopped_flag,
change_if_necessary_test!(conv_temp, convert_temperature, CONTROL, CONTROL_POR_VALUE | BF::TEMP_CONV, CONTROL_POR_VALUE & !BF::TEMP_CONV); change_if_necessary_test!(conv_temp, convert_temperature, CONTROL, CONTROL_POR_VALUE | BF::TEMP_CONV, CONTROL_POR_VALUE & !BF::TEMP_CONV);
call_method_test!(en_al1_int, enable_alarm1_interrupts, CONTROL, CONTROL_POR_VALUE | BF::ALARM1_INT_EN);
call_method_test!(dis_al1_int, disable_alarm1_interrupts, CONTROL, CONTROL_POR_VALUE & !BF::ALARM1_INT_EN);
call_method_test!(en_al2_int, enable_alarm2_interrupts, CONTROL, CONTROL_POR_VALUE | BF::ALARM2_INT_EN);
call_method_test!(dis_al2_int, disable_alarm2_interrupts, CONTROL, CONTROL_POR_VALUE & !BF::ALARM2_INT_EN);
set_param_test!(set_aging_offset_min, set_aging_offset, AGING_OFFSET, -128, 0b1000_0000); set_param_test!(set_aging_offset_min, set_aging_offset, AGING_OFFSET, -128, 0b1000_0000);
set_param_test!(set_aging_offset_max, set_aging_offset, AGING_OFFSET, 127, 127); set_param_test!(set_aging_offset_max, set_aging_offset, AGING_OFFSET, 127, 127);