Skip to content

Commit 6a58b58

Browse files
committed
impl defmt::Format for Time and Date
1 parent fcf93f3 commit 6a58b58

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/time.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ impl Time {
5050
}
5151
}
5252

53+
#[cfg(feature = "defmt")]
54+
impl defmt::Format for Time {
55+
fn format(&self, f: defmt::Formatter) {
56+
// format the bitfields of the register as struct fields
57+
defmt::write!(
58+
f,
59+
"{:02}:{:02}:{:02}",
60+
self.hours, self.minutes, self.seconds
61+
)
62+
}
63+
}
64+
5365
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5466
pub struct Date {
5567
pub day: u32,
@@ -67,6 +79,18 @@ impl Date {
6779
}
6880
}
6981

82+
#[cfg(feature = "defmt")]
83+
impl defmt::Format for Date {
84+
fn format(&self, f: defmt::Formatter) {
85+
// format the bitfields of the register as struct fields
86+
defmt::write!(
87+
f,
88+
"{:04}-{:02}-{:02}",
89+
self.year, self.month, self.day
90+
)
91+
}
92+
}
93+
7094
pub trait U32Ext {
7195
/// Wrap in `Bps`
7296
fn bps(self) -> Bps;

0 commit comments

Comments
 (0)