Add function to force a temperature conversion and time compensation

pull/4/head
Diego Barrios Romero 2018-10-29 18:25:16 +01:00
parent 08f83660d0
commit c41526b7ec
4 changed files with 14 additions and 0 deletions

View File

@ -30,6 +30,17 @@ where
Ok(()) Ok(())
} }
/// Force a temperature conversion and time compensation with TXCO algorithm.
///
/// The *busy* status should be checked before doing this. See [`is_busy()`](#method.is_busy)
pub fn convert_temperature(&mut self) -> Result<(), Error<E>> {
let control = self.iface.read_register(Register::CONTROL)?;
if (control & BitFlags::TEMP_CONV) == 0 {
self.iface.write_register(Register::CONTROL, control | BitFlags::TEMP_CONV)?;
}
Ok(())
}
/// Enable the 32kHz output. /// Enable the 32kHz output.
/// ///
/// (Does not alter the device register if already enabled). /// (Does not alter the device register if already enabled).

View File

@ -295,6 +295,7 @@ impl BitFlags {
const AM_PM : u8 = 0b0010_0000; const AM_PM : u8 = 0b0010_0000;
const CENTURY : u8 = 0b1000_0000; const CENTURY : u8 = 0b1000_0000;
const EOSC : u8 = 0b1000_0000; const EOSC : u8 = 0b1000_0000;
const TEMP_CONV : u8 = 0b0010_0000;
const BUSY : u8 = 0b0000_0100; const BUSY : u8 = 0b0000_0100;
const EN32KHZ : u8 = 0b0000_1000; const EN32KHZ : u8 = 0b0000_1000;
const OSC_STOP : u8 = 0b1000_0000; const OSC_STOP : u8 = 0b1000_0000;

View File

@ -25,6 +25,7 @@ pub struct BitFlags;
#[allow(unused)] #[allow(unused)]
impl BitFlags { impl BitFlags {
pub const EOSC : u8 = 0b1000_0000; pub const EOSC : u8 = 0b1000_0000;
pub const TEMP_CONV : u8 = 0b0010_0000;
pub const BUSY : u8 = 0b0000_0100; pub const BUSY : u8 = 0b0000_0100;
pub const EN32KHZ : u8 = 0b0000_1000; pub const EN32KHZ : u8 = 0b0000_1000;
pub const OSC_STOP : u8 = 0b1000_0000; pub const OSC_STOP : u8 = 0b1000_0000;

View File

@ -39,6 +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!(conv_temp, convert_temperature, CONTROL, 0xFF, 0xFF & !BF::TEMP_CONV);
change_if_necessary_test!(en_32khz_out, enable_32khz_output, STATUS, 0xFF, 0xFF & !BF::EN32KHZ); 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!(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);