diff --git a/src/structs.rs b/src/structs.rs index 6d5d31b0..f54ec7fc 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -115,7 +115,6 @@ impl SdpcmHeader { } #[derive(Debug, Clone, Copy)] -// #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(C, packed(2))] pub struct CdcHeader { pub cmd: u32, @@ -126,6 +125,25 @@ pub struct CdcHeader { } impl_bytes!(CdcHeader); +#[cfg(feature = "defmt")] +impl defmt::Format for CdcHeader { + fn format(&self, fmt: defmt::Formatter) { + fn copy(t: T) -> T { + t + } + + defmt::write!( + fmt, + "CdcHeader{{cmd: {=u32:08x}, len: {=u32:08x}, flags: {=u16:04x}, id: {=u16:04x}, status: {=u32:08x}}}", + copy(self.cmd), + copy(self.len), + copy(self.flags), + copy(self.id), + copy(self.status), + ) + } +} + impl CdcHeader { pub fn parse(packet: &mut [u8]) -> Option<(&mut Self, &mut [u8])> { if packet.len() < Self::SIZE {