Skip to content

Commit 5e114a6

Browse files
committed
impl defmt::Format for Time and Date
1 parent 93973df commit 5e114a6

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
@@ -52,6 +52,18 @@ impl Time {
5252
}
5353
}
5454

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

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

0 commit comments

Comments
 (0)