Extract function to write the status register

pull/4/head
Diego Barrios Romero 2018-10-31 10:01:47 +01:00
parent 73ca2703c9
commit 8bea870813
1 changed files with 12 additions and 10 deletions

View File

@ -34,20 +34,14 @@ where
/// Enable the 32kHz output.
pub fn enable_32khz_output(&mut self) -> Result<(), Error<E>> {
// avoid clearing alarm flags
let status = self.status | BitFlags::EN32KHZ | BitFlags::ALARM2F | BitFlags::ALARM1F;
self.iface.write_register(Register::STATUS, status)?;
self.status = status;
Ok(())
let status = self.status | BitFlags::EN32KHZ;
self.write_status_without_clearing_alarm(status)
}
/// Disable the 32kHz output.
pub fn disable_32khz_output(&mut self) -> Result<(), Error<E>> {
// avoid clearing alarm flags
let status = self.status & !BitFlags::EN32KHZ | BitFlags::ALARM2F | BitFlags::ALARM1F;
self.iface.write_register(Register::STATUS, status)?;
self.status = status;
Ok(())
let status = self.status & !BitFlags::EN32KHZ;
self.write_status_without_clearing_alarm(status)
}
/// Set the aging offset.
@ -102,4 +96,12 @@ where
self.control = control;
Ok(())
}
pub(crate) fn write_status_without_clearing_alarm(&mut self, status: u8) -> Result<(), Error<E>> {
// avoid clearing alarm flags
let new_status = status | BitFlags::ALARM2F | BitFlags::ALARM1F;
self.iface.write_register(Register::STATUS, new_status)?;
self.status = status;
Ok(())
}
}