Add functions to enable/disable the 32kHz output

pull/4/head
Diego Barrios Romero 2018-10-29 18:24:20 +01:00
parent 7f3d1220d0
commit 08f83660d0
4 changed files with 26 additions and 0 deletions

View File

@ -29,4 +29,26 @@ where
} }
Ok(()) Ok(())
} }
/// Enable the 32kHz output.
///
/// (Does not alter the device register if already enabled).
pub fn enable_32khz_output(&mut self) -> Result<(), Error<E>> {
let control = self.iface.read_register(Register::STATUS)?;
if (control & BitFlags::EN32KHZ) == 0 {
self.iface.write_register(Register::STATUS, control | BitFlags::EN32KHZ)?;
}
Ok(())
}
/// Disable the 32kHz output.
///
/// (Does not alter the device register if already disabled).
pub fn disable_32khz_output(&mut self) -> Result<(), Error<E>> {
let control = self.iface.read_register(Register::STATUS)?;
if (control & BitFlags::EN32KHZ) != 0 {
self.iface.write_register(Register::STATUS, control & !BitFlags::EN32KHZ)?;
}
Ok(())
}
} }

View File

@ -296,6 +296,7 @@ impl BitFlags {
const CENTURY : u8 = 0b1000_0000; const CENTURY : u8 = 0b1000_0000;
const EOSC : u8 = 0b1000_0000; const EOSC : u8 = 0b1000_0000;
const BUSY : u8 = 0b0000_0100; const BUSY : u8 = 0b0000_0100;
const EN32KHZ : u8 = 0b0000_1000;
const OSC_STOP : u8 = 0b1000_0000; const OSC_STOP : u8 = 0b1000_0000;
} }

View File

@ -26,6 +26,7 @@ pub struct BitFlags;
impl BitFlags { impl BitFlags {
pub const EOSC : u8 = 0b1000_0000; pub const EOSC : u8 = 0b1000_0000;
pub const BUSY : u8 = 0b0000_0100; pub const BUSY : u8 = 0b0000_0100;
pub const EN32KHZ : u8 = 0b0000_1000;
pub const OSC_STOP : u8 = 0b1000_0000; pub const OSC_STOP : u8 = 0b1000_0000;
} }

View File

@ -39,5 +39,7 @@ macro_rules! change_if_necessary_test {
change_if_necessary_test!(enable, enable, CONTROL, 0xFF & !BF::EOSC, 0xFF); change_if_necessary_test!(enable, enable, CONTROL, 0xFF & !BF::EOSC, 0xFF);
change_if_necessary_test!(disable, disable, CONTROL, 0xFF, 0xFF & !BF::EOSC); change_if_necessary_test!(disable, disable, CONTROL, 0xFF, 0xFF & !BF::EOSC);
change_if_necessary_test!(en_32khz_out, enable_32khz_output, STATUS, 0xFF, 0xFF & !BF::EN32KHZ);
change_if_necessary_test!(dis_32khz_out, disable_32khz_output, STATUS, 0xFF & !BF::EN32KHZ, 0xFF);
change_if_necessary_test!(clr_stop, clear_has_been_stopped_flag, STATUS, 0xFF & !BF::OSC_STOP, 0xFF); change_if_necessary_test!(clr_stop, clear_has_been_stopped_flag, STATUS, 0xFF & !BF::OSC_STOP, 0xFF);