Add function to select function of int/sqw output pin

pull/4/head
Diego Barrios Romero 2018-10-31 06:52:08 +01:00
parent 70657dd917
commit 8c6b9ff777
4 changed files with 18 additions and 0 deletions

View File

@ -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<E>> {
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<E>> {
let control = self.control;
self.write_control(control & !BitFlags::INTCN)
}
fn write_control(&mut self, control: u8) -> Result<(), Error<E>> {
self.iface.write_register(Register::CONTROL, control)?;
self.control = control;

View File

@ -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;

View File

@ -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;

View File

@ -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);