diff --git a/embassy/src/util/mpsc.rs b/embassy/src/util/mpsc.rs index bad1058a..b9a95d6a 100644 --- a/embassy/src/util/mpsc.rs +++ b/embassy/src/util/mpsc.rs @@ -386,6 +386,7 @@ where /// /// [`try_recv`]: super::Receiver::try_recv #[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum TryRecvError { /// A message could not be received because the channel is empty. Empty, @@ -404,6 +405,14 @@ impl fmt::Display for SendError { } } +#[cfg(feature = "defmt")] +impl defmt::Format for SendError { + fn format(&self, fmt: defmt::Formatter<'_>) { + defmt::write!(fmt, "channel closed") + } +} + + /// This enumeration is the list of the possible error outcomes for the /// [try_send](super::Sender::try_send) method. #[derive(Debug)] @@ -430,6 +439,20 @@ impl fmt::Display for TrySendError { } } +#[cfg(feature = "defmt")] +impl defmt::Format for TrySendError { + fn format(&self, fmt: defmt::Formatter<'_>) { + defmt::write!( + fmt, + "{}", + match self { + TrySendError::Full(..) => "no available capacity", + TrySendError::Closed(..) => "channel closed", + } + ) + } +} + struct ChannelState { buf: [MaybeUninit>; N], read_pos: usize,