From 2304e08d1f252cbdf39c1a5b813a0ed8e630320c Mon Sep 17 00:00:00 2001
From: Diego Barrios Romero <eldruin@gmail.com>
Date: Sat, 3 Nov 2018 07:53:01 +0100
Subject: [PATCH] Change: clear_has_been_stopped_flag always clears without
 checking first

---
 CHANGELOG.md           | 3 +++
 src/ds323x/status.rs   | 4 +++-
 tests/configuration.rs | 5 ++++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a24aa3a..3a3062a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ...
 
+### Changed
+- [breaking-change] `clear_has_been_stopped_flag()` always sets the value of the status register.
+
 ## 0.1.0 - 2018-10-31
 
 This is the initial release to crates.io. All changes will be documented in
diff --git a/src/ds323x/status.rs b/src/ds323x/status.rs
index b1e9018..f6b0c61 100644
--- a/src/ds323x/status.rs
+++ b/src/ds323x/status.rs
@@ -35,9 +35,11 @@ where
     /// Clear flag signalling whether the oscillator is stopped or has been
     /// stopped at some point.
     ///
-    /// (Does not alter the device register if already cleared).
     /// See also: [`has_been_stopped()`](#method.has_been_stopped)
     pub fn clear_has_been_stopped_flag(&mut self) -> Result<(), Error<E>> {
+        let status = self.status & !BitFlags::OSC_STOP;
+        self.write_status_without_clearing_alarm(status)
+    }
         let status = self.iface.read_register(Register::STATUS)?;
         if (status & BitFlags::OSC_STOP) != 0 {
             self.iface.write_register(Register::STATUS, status & !BitFlags::OSC_STOP)?;
diff --git a/tests/configuration.rs b/tests/configuration.rs
index e9f6a88..ca7fea5 100644
--- a/tests/configuration.rs
+++ b/tests/configuration.rs
@@ -72,7 +72,10 @@ call_method_status_test!(en_32khz_out,  enable_32khz_output,
 call_method_status_test!(dis_32khz_out, disable_32khz_output,
     DS3231_POR_STATUS & !BF::EN32KHZ | BF::ALARM2F | BF::ALARM1F,
     DS323X_POR_STATUS & !BF::EN32KHZ | BF::ALARM2F | BF::ALARM1F);
-change_if_necessary_test!(clr_stop, clear_has_been_stopped_flag, STATUS, 0xFF & !BF::OSC_STOP, 0xFF);
+call_method_status_test!(clr_stop, clear_has_been_stopped_flag,
+    DS3231_POR_STATUS & !BF::OSC_STOP | BF::ALARM2F | BF::ALARM1F,
+    DS323X_POR_STATUS & !BF::OSC_STOP | BF::ALARM2F | BF::ALARM1F);
+
 change_if_necessary_test!(conv_temp, convert_temperature, CONTROL, CONTROL_POR_VALUE | BF::TEMP_CONV, CONTROL_POR_VALUE & !BF::TEMP_CONV);
 
 set_param_test!(set_aging_offset_min, set_aging_offset, AGING_OFFSET, -128, 0b1000_0000);