diff options
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/structs.rs b/src/structs.rs index 6d5d31b06..f54ec7fcf 100644 --- a/src/structs.rs +++ b/src/structs.rs | |||
| @@ -115,7 +115,6 @@ impl SdpcmHeader { | |||
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | #[derive(Debug, Clone, Copy)] | 117 | #[derive(Debug, Clone, Copy)] |
| 118 | // #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 119 | #[repr(C, packed(2))] | 118 | #[repr(C, packed(2))] |
| 120 | pub struct CdcHeader { | 119 | pub struct CdcHeader { |
| 121 | pub cmd: u32, | 120 | pub cmd: u32, |
| @@ -126,6 +125,25 @@ pub struct CdcHeader { | |||
| 126 | } | 125 | } |
| 127 | impl_bytes!(CdcHeader); | 126 | impl_bytes!(CdcHeader); |
| 128 | 127 | ||
| 128 | #[cfg(feature = "defmt")] | ||
| 129 | impl defmt::Format for CdcHeader { | ||
| 130 | fn format(&self, fmt: defmt::Formatter) { | ||
| 131 | fn copy<T: Copy>(t: T) -> T { | ||
| 132 | t | ||
| 133 | } | ||
| 134 | |||
| 135 | defmt::write!( | ||
| 136 | fmt, | ||
| 137 | "CdcHeader{{cmd: {=u32:08x}, len: {=u32:08x}, flags: {=u16:04x}, id: {=u16:04x}, status: {=u32:08x}}}", | ||
| 138 | copy(self.cmd), | ||
| 139 | copy(self.len), | ||
| 140 | copy(self.flags), | ||
| 141 | copy(self.id), | ||
| 142 | copy(self.status), | ||
| 143 | ) | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 129 | impl CdcHeader { | 147 | impl CdcHeader { |
| 130 | pub fn parse(packet: &mut [u8]) -> Option<(&mut Self, &mut [u8])> { | 148 | pub fn parse(packet: &mut [u8]) -> Option<(&mut Self, &mut [u8])> { |
| 131 | if packet.len() < Self::SIZE { | 149 | if packet.len() < Self::SIZE { |
