From 2aba6332e7bdb0e6c7201ada2d90f301cbbec306 Mon Sep 17 00:00:00 2001
From: Diego Barrios Romero <eldruin@gmail.com>
Date: Wed, 31 Oct 2018 06:52:28 +0100
Subject: [PATCH] Add function to read whether the oscillator is running

---
 src/ds323x/status.rs | 6 ++++++
 tests/status.rs      | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/src/ds323x/status.rs b/src/ds323x/status.rs
index d4da0f4..d03d078 100644
--- a/src/ds323x/status.rs
+++ b/src/ds323x/status.rs
@@ -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)?;
diff --git a/tests/status.rs b/tests/status.rs
index 879bf27..22747bf 100644
--- a/tests/status.rs
+++ b/tests/status.rs
@@ -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);