From 9d236eb8c6cc67948820b4314d7791be61dbaf40 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Mon, 29 Oct 2018 18:19:12 +0100 Subject: [PATCH] Add function to check if the oscillator has been stopped. --- src/ds323x/status.rs | 7 +++++++ src/lib.rs | 1 + tests/common/mod.rs | 1 + tests/status.rs | 7 +++++-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ds323x/status.rs b/src/ds323x/status.rs index 4f9a73e..ba099dc 100644 --- a/src/ds323x/status.rs +++ b/src/ds323x/status.rs @@ -13,4 +13,11 @@ where let status = self.iface.read_register(Register::STATUS)?; Ok((status & BitFlags::BUSY) != 0) } + + /// Read whether the oscillator is stopped or has been stopped at + /// some point. + pub fn has_been_stopped(&mut self) -> Result> { + let status = self.iface.read_register(Register::STATUS)?; + Ok((status & BitFlags::OSC_STOP) != 0) + } } diff --git a/src/lib.rs b/src/lib.rs index a43ee01..70e186a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -296,6 +296,7 @@ impl BitFlags { const CENTURY : u8 = 0b1000_0000; const EOSC : u8 = 0b1000_0000; const BUSY : u8 = 0b0000_0100; + const OSC_STOP : u8 = 0b1000_0000; } const DEVICE_ADDRESS: u8 = 0b110_1000; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 9911e8e..3efd4da 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -26,6 +26,7 @@ pub struct BitFlags; impl BitFlags { pub const EOSC : u8 = 0b1000_0000; pub const BUSY : u8 = 0b0000_0100; + pub const OSC_STOP : u8 = 0b1000_0000; } pub struct DummyOutputPin; diff --git a/tests/status.rs b/tests/status.rs index 7652c50..16d86eb 100644 --- a/tests/status.rs +++ b/tests/status.rs @@ -8,5 +8,8 @@ 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_busy, is_busy, STATUS, true, 0xFF); -get_param_test!(is_not_busy, is_busy, STATUS, false, 0xFF & !BF::BUSY); \ No newline at end of file +get_param_test!(is_busy, is_busy, STATUS, true, 0xFF); +get_param_test!(is_not_busy, is_busy, STATUS, false, 0xFF & !BF::BUSY); + +get_param_test!(stopped, has_been_stopped, STATUS, true, 0xFF); +get_param_test!(not_stopped, has_been_stopped, STATUS, false, 0xFF & !BF::OSC_STOP); \ No newline at end of file