Add function to enable/disable the square wave generation

pull/4/head
Diego Barrios Romero 2018-10-31 06:53:28 +01:00
parent 2aba6332e7
commit 5168dbe68f
4 changed files with 16 additions and 0 deletions

View File

@ -77,6 +77,17 @@ where
self.write_control(control & !BitFlags::INTCN)
}
/// Enable battery-backed square wave generation.
pub fn enable_square_wave(&mut self) -> Result<(), Error<E>> {
let control = self.control;
self.write_control(control | BitFlags::BBSQW)
}
/// Disable battery-backed square wave generation.
pub fn disable_square_wave(&mut self) -> Result<(), Error<E>> {
let control = self.control;
self.write_control(control & !BitFlags::BBSQW)
}
fn write_control(&mut self, control: u8) -> Result<(), Error<E>> {
self.iface.write_register(Register::CONTROL, control)?;
self.control = control;

View File

@ -356,6 +356,7 @@ impl BitFlags {
const AM_PM : u8 = 0b0010_0000;
const CENTURY : u8 = 0b1000_0000;
const EOSC : u8 = 0b1000_0000;
const BBSQW : u8 = 0b0100_0000;
const TEMP_CONV : u8 = 0b0010_0000;
const INTCN : u8 = 0b0000_0100;
const BUSY : u8 = 0b0000_0100;

View File

@ -29,6 +29,7 @@ pub struct BitFlags;
#[allow(unused)]
impl BitFlags {
pub const EOSC : u8 = 0b1000_0000;
pub const BBSQW : u8 = 0b0100_0000;
pub const TEMP_CONV : u8 = 0b0010_0000;
pub const INTCN : u8 = 0b0000_0100;
pub const BUSY : u8 = 0b0000_0100;

View File

@ -62,3 +62,6 @@ 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);
call_method_test!(enable_sqw, enable_square_wave, CONTROL, CONTROL_POR_VALUE | BF::BBSQW);
call_method_test!(disable_sqw, disable_square_wave, CONTROL, CONTROL_POR_VALUE & !BF::BBSQW);