Add function to read whether the oscillator is running

pull/4/head
Diego Barrios Romero 2018-10-31 06:52:28 +01:00
parent 8c6b9ff777
commit 2aba6332e7
2 changed files with 9 additions and 0 deletions

View File

@ -8,6 +8,12 @@ impl<DI, IC, E> Ds323x<DI, IC>
where
DI: ReadData<Error = E> + WriteData<Error = E>
{
/// Read whether the oscillator is running
pub fn is_running(&mut self) -> Result<bool, Error<E>> {
let control = self.iface.read_register(Register::CONTROL)?;
Ok((control & BitFlags::EOSC) == 0)
}
/// Read the busy status
pub fn is_busy(&mut self) -> Result<bool, Error<E>> {
let status = self.iface.read_register(Register::STATUS)?;

View File

@ -8,6 +8,9 @@ use common::{ DEVICE_ADDRESS as DEV_ADDR, Register, new_ds3231,
new_ds3232, new_ds3234, destroy_ds3231, destroy_ds3232,
destroy_ds3234, BitFlags as BF };
get_param_test!(is_running, is_running, CONTROL, true, 0);
get_param_test!(is_not_running, is_running, CONTROL, false, BF::EOSC);
get_param_test!(is_busy, is_busy, STATUS, true, 0xFF);
get_param_test!(is_not_busy, is_busy, STATUS, false, 0xFF & !BF::BUSY);