diff --git a/src/ds323x/configuration.rs b/src/ds323x/configuration.rs index eb955f7..3951195 100644 --- a/src/ds323x/configuration.rs +++ b/src/ds323x/configuration.rs @@ -64,6 +64,19 @@ where let offset = self.iface.read_register(Register::AGING_OFFSET)?; Ok(offset as i8) } + + /// Set the interrupt/square-wave output to be used as interrupt output. + pub fn use_int_sqw_output_as_interrupt(&mut self) -> Result<(), Error> { + let control = self.control; + self.write_control(control | BitFlags::INTCN) + } + + /// Set the interrupt/square-wave output to be used as square-wave output. + pub fn use_int_sqw_output_as_square_wave(&mut self) -> Result<(), Error> { + let control = self.control; + self.write_control(control & !BitFlags::INTCN) + } + fn write_control(&mut self, control: u8) -> Result<(), Error> { self.iface.write_register(Register::CONTROL, control)?; self.control = control; diff --git a/src/lib.rs b/src/lib.rs index a4878e0..fcf77fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -357,6 +357,7 @@ impl BitFlags { const CENTURY : u8 = 0b1000_0000; const EOSC : u8 = 0b1000_0000; const TEMP_CONV : u8 = 0b0010_0000; + const INTCN : u8 = 0b0000_0100; const BUSY : u8 = 0b0000_0100; const EN32KHZ : u8 = 0b0000_1000; const OSC_STOP : u8 = 0b1000_0000; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index cac730a..199fa30 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -30,6 +30,7 @@ pub struct BitFlags; impl BitFlags { pub const EOSC : u8 = 0b1000_0000; pub const TEMP_CONV : u8 = 0b0010_0000; + pub const INTCN : u8 = 0b0000_0100; pub const BUSY : u8 = 0b0000_0100; pub const EN32KHZ : u8 = 0b0000_1000; pub const OSC_STOP : u8 = 0b1000_0000; diff --git a/tests/configuration.rs b/tests/configuration.rs index dacc521..04cd333 100644 --- a/tests/configuration.rs +++ b/tests/configuration.rs @@ -59,3 +59,6 @@ set_param_test!(set_aging_offset_max, set_aging_offset, AGING_OFFSET, 127, 127) get_param_test!(get_aging_offset_min, get_aging_offset, AGING_OFFSET, -128, 0b1000_0000); get_param_test!(get_aging_offset_max, get_aging_offset, AGING_OFFSET, 127, 127); +call_method_test!(int_sqw_out_int, use_int_sqw_output_as_interrupt, CONTROL, CONTROL_POR_VALUE | BF::INTCN); +call_method_test!(int_sqw_out_sqw, use_int_sqw_output_as_square_wave, CONTROL, CONTROL_POR_VALUE & !BF::INTCN); +