From 3cd6bb82c1f5d982f9b6735673fad30762418f41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20Dupr=C3=A9=20Bertoni?=
 <louisdb@lespetitspedestres.org>
Date: Fri, 24 Jan 2025 12:56:59 +0200
Subject: [PATCH 1/2] Add optional support for defmt

---
 Cargo.toml           | 4 ++++
 src/ds323x/alarms.rs | 6 ++++++
 src/interface.rs     | 2 ++
 src/lib.rs           | 4 ++++
 4 files changed, 16 insertions(+)

diff --git a/Cargo.toml b/Cargo.toml
index 0eb5e95..8ef21b0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,9 +20,13 @@ include = [
 ]
 edition = "2018"
 
+[features]
+defmt = ["dep:defmt", "rtcc/defmt"]
+
 [dependencies]
 embedded-hal = "1.0.0"
 rtcc = "0.3"
+defmt = { version = "0.3", optional = true }
 
 [dev-dependencies]
 embedded-hal-mock = { version = "0.11.1", features = ["eh1"] }
diff --git a/src/ds323x/alarms.rs b/src/ds323x/alarms.rs
index c494f6e..69b2f51 100644
--- a/src/ds323x/alarms.rs
+++ b/src/ds323x/alarms.rs
@@ -15,6 +15,7 @@ use crate::{
 /// - Second, minute and hour: 0
 /// - Day: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub struct DayAlarm1 {
     /// Day of the month [1-31]
     pub day: u8,
@@ -34,6 +35,7 @@ pub struct DayAlarm1 {
 /// - Second, minute and hour: 0
 /// - Weekday: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub struct WeekdayAlarm1 {
     /// Weekday [1-7]
     pub weekday: u8,
@@ -47,6 +49,7 @@ pub struct WeekdayAlarm1 {
 
 /// Alarm1 trigger rate
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub enum Alarm1Matching {
     /// Alarm once per second.
     OncePerSecond,
@@ -68,6 +71,7 @@ pub enum Alarm1Matching {
 /// - Minute and hour: 0
 /// - Day: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub struct DayAlarm2 {
     /// Day of month [1-31]
     pub day: u8,
@@ -85,6 +89,7 @@ pub struct DayAlarm2 {
 /// - Minute and hour: 0
 /// - Weekday: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub struct WeekdayAlarm2 {
     /// Weekday [1-7]
     pub weekday: u8,
@@ -96,6 +101,7 @@ pub struct WeekdayAlarm2 {
 
 /// Alarm2 trigger rate
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub enum Alarm2Matching {
     /// Alarm once per minute. (00 seconds of every minute)
     OncePerMinute,
diff --git a/src/interface.rs b/src/interface.rs
index 34fb64e..6ff0c49 100644
--- a/src/interface.rs
+++ b/src/interface.rs
@@ -5,12 +5,14 @@ use embedded_hal::{i2c, spi};
 
 /// I2C interface
 #[derive(Debug, Default)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub struct I2cInterface<I2C> {
     pub(crate) i2c: I2C,
 }
 
 /// SPI interface
 #[derive(Debug, Default)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub struct SpiInterface<SPI> {
     pub(crate) spi: SPI,
 }
diff --git a/src/lib.rs b/src/lib.rs
index a44b401..5efa490 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -377,6 +377,7 @@ pub const SPI_MODE_3: Mode = MODE_3;
 
 /// All possible errors in this crate
 #[derive(Debug)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub enum Error<E> {
     /// I²C/SPI bus error
     Comm(E),
@@ -391,6 +392,7 @@ pub enum Error<E> {
 
 /// Square-wave output frequency
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub enum SqWFreq {
     /// 1 Hz (default)
     _1Hz,
@@ -406,6 +408,7 @@ pub enum SqWFreq {
 ///
 /// This is only available on the DS3232 and DS3234 devices.
 #[derive(Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub enum TempConvRate {
     /// Once every 64 seconds (default)
     _64s,
@@ -478,6 +481,7 @@ pub mod ic {
 
 /// DS3231, DS3232 and DS3234 RTC driver
 #[derive(Debug, Default)]
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 pub struct Ds323x<DI, IC> {
     iface: DI,
     control: u8,

From 57e0744c95d83c315ad02423084b69fb01e680df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20Dupr=C3=A9=20Bertoni?=
 <louisdb@lespetitspedestres.org>
Date: Fri, 7 Feb 2025 14:36:07 +0200
Subject: [PATCH 2/2] Rename defmt feature

---
 Cargo.toml           |  2 +-
 src/ds323x/alarms.rs | 12 ++++++------
 src/interface.rs     |  4 ++--
 src/lib.rs           |  8 ++++----
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 8ef21b0..516497a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,7 @@ include = [
 edition = "2018"
 
 [features]
-defmt = ["dep:defmt", "rtcc/defmt"]
+defmt-03 = ["dep:defmt", "rtcc/defmt-03"]
 
 [dependencies]
 embedded-hal = "1.0.0"
diff --git a/src/ds323x/alarms.rs b/src/ds323x/alarms.rs
index 69b2f51..61cafe9 100644
--- a/src/ds323x/alarms.rs
+++ b/src/ds323x/alarms.rs
@@ -15,7 +15,7 @@ use crate::{
 /// - Second, minute and hour: 0
 /// - Day: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub struct DayAlarm1 {
     /// Day of the month [1-31]
     pub day: u8,
@@ -35,7 +35,7 @@ pub struct DayAlarm1 {
 /// - Second, minute and hour: 0
 /// - Weekday: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub struct WeekdayAlarm1 {
     /// Weekday [1-7]
     pub weekday: u8,
@@ -49,7 +49,7 @@ pub struct WeekdayAlarm1 {
 
 /// Alarm1 trigger rate
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub enum Alarm1Matching {
     /// Alarm once per second.
     OncePerSecond,
@@ -71,7 +71,7 @@ pub enum Alarm1Matching {
 /// - Minute and hour: 0
 /// - Day: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub struct DayAlarm2 {
     /// Day of month [1-31]
     pub day: u8,
@@ -89,7 +89,7 @@ pub struct DayAlarm2 {
 /// - Minute and hour: 0
 /// - Weekday: 1
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub struct WeekdayAlarm2 {
     /// Weekday [1-7]
     pub weekday: u8,
@@ -101,7 +101,7 @@ pub struct WeekdayAlarm2 {
 
 /// Alarm2 trigger rate
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub enum Alarm2Matching {
     /// Alarm once per minute. (00 seconds of every minute)
     OncePerMinute,
diff --git a/src/interface.rs b/src/interface.rs
index 6ff0c49..8920136 100644
--- a/src/interface.rs
+++ b/src/interface.rs
@@ -5,14 +5,14 @@ use embedded_hal::{i2c, spi};
 
 /// I2C interface
 #[derive(Debug, Default)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub struct I2cInterface<I2C> {
     pub(crate) i2c: I2C,
 }
 
 /// SPI interface
 #[derive(Debug, Default)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub struct SpiInterface<SPI> {
     pub(crate) spi: SPI,
 }
diff --git a/src/lib.rs b/src/lib.rs
index 5efa490..9040f1c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -377,7 +377,7 @@ pub const SPI_MODE_3: Mode = MODE_3;
 
 /// All possible errors in this crate
 #[derive(Debug)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub enum Error<E> {
     /// I²C/SPI bus error
     Comm(E),
@@ -392,7 +392,7 @@ pub enum Error<E> {
 
 /// Square-wave output frequency
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub enum SqWFreq {
     /// 1 Hz (default)
     _1Hz,
@@ -408,7 +408,7 @@ pub enum SqWFreq {
 ///
 /// This is only available on the DS3232 and DS3234 devices.
 #[derive(Debug, Clone, Copy, PartialEq)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub enum TempConvRate {
     /// Once every 64 seconds (default)
     _64s,
@@ -481,7 +481,7 @@ pub mod ic {
 
 /// DS3231, DS3232 and DS3234 RTC driver
 #[derive(Debug, Default)]
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
 pub struct Ds323x<DI, IC> {
     iface: DI,
     control: u8,