mirror of https://github.com/eldruin/ds323x-rs
Extract function to write the status register
parent
73ca2703c9
commit
8bea870813
|
@ -34,20 +34,14 @@ where
|
||||||
|
|
||||||
/// Enable the 32kHz output.
|
/// Enable the 32kHz output.
|
||||||
pub fn enable_32khz_output(&mut self) -> Result<(), Error<E>> {
|
pub fn enable_32khz_output(&mut self) -> Result<(), Error<E>> {
|
||||||
// avoid clearing alarm flags
|
let status = self.status | BitFlags::EN32KHZ;
|
||||||
let status = self.status | BitFlags::EN32KHZ | BitFlags::ALARM2F | BitFlags::ALARM1F;
|
self.write_status_without_clearing_alarm(status)
|
||||||
self.iface.write_register(Register::STATUS, status)?;
|
|
||||||
self.status = status;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable the 32kHz output.
|
/// Disable the 32kHz output.
|
||||||
pub fn disable_32khz_output(&mut self) -> Result<(), Error<E>> {
|
pub fn disable_32khz_output(&mut self) -> Result<(), Error<E>> {
|
||||||
// avoid clearing alarm flags
|
let status = self.status & !BitFlags::EN32KHZ;
|
||||||
let status = self.status & !BitFlags::EN32KHZ | BitFlags::ALARM2F | BitFlags::ALARM1F;
|
self.write_status_without_clearing_alarm(status)
|
||||||
self.iface.write_register(Register::STATUS, status)?;
|
|
||||||
self.status = status;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the aging offset.
|
/// Set the aging offset.
|
||||||
|
@ -102,4 +96,12 @@ where
|
||||||
self.control = control;
|
self.control = control;
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue