aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-08-22 01:17:11 +0200
committerGitHub <[email protected]>2021-08-22 01:17:11 +0200
commitfde24dba3c8433884123a0c7c07afa72d65bc17f (patch)
treebc7dc39367566dd32dab09cb2c537eab707c94fd
parent1e1cd0506aa655456d7cbf7d6915b46abf7829e5 (diff)
parent7ca745a5c0bf8cdee578ee1108e78b73b7161f4e (diff)
Merge pull request #369 from derekdreery/defmt_mpsc
Add defmt support for mpsc errors.
-rw-r--r--embassy/src/util/mpsc.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/embassy/src/util/mpsc.rs b/embassy/src/util/mpsc.rs
index bad1058a3..4257ecd40 100644
--- a/embassy/src/util/mpsc.rs
+++ b/embassy/src/util/mpsc.rs
@@ -386,6 +386,7 @@ where
386/// 386///
387/// [`try_recv`]: super::Receiver::try_recv 387/// [`try_recv`]: super::Receiver::try_recv
388#[derive(PartialEq, Eq, Clone, Copy, Debug)] 388#[derive(PartialEq, Eq, Clone, Copy, Debug)]
389#[cfg_attr(feature = "defmt", derive(defmt::Format))]
389pub enum TryRecvError { 390pub enum TryRecvError {
390 /// A message could not be received because the channel is empty. 391 /// A message could not be received because the channel is empty.
391 Empty, 392 Empty,
@@ -404,6 +405,13 @@ impl<T> fmt::Display for SendError<T> {
404 } 405 }
405} 406}
406 407
408#[cfg(feature = "defmt")]
409impl<T> defmt::Format for SendError<T> {
410 fn format(&self, fmt: defmt::Formatter<'_>) {
411 defmt::write!(fmt, "channel closed")
412 }
413}
414
407/// This enumeration is the list of the possible error outcomes for the 415/// This enumeration is the list of the possible error outcomes for the
408/// [try_send](super::Sender::try_send) method. 416/// [try_send](super::Sender::try_send) method.
409#[derive(Debug)] 417#[derive(Debug)]
@@ -430,6 +438,16 @@ impl<T> fmt::Display for TrySendError<T> {
430 } 438 }
431} 439}
432 440
441#[cfg(feature = "defmt")]
442impl<T> defmt::Format for TrySendError<T> {
443 fn format(&self, fmt: defmt::Formatter<'_>) {
444 match self {
445 TrySendError::Full(..) => defmt::write!(fmt, "no available capacity"),
446 TrySendError::Closed(..) => defmt::write!(fmt, "channel closed"),
447 }
448 }
449}
450
433struct ChannelState<T, const N: usize> { 451struct ChannelState<T, const N: usize> {
434 buf: [MaybeUninit<UnsafeCell<T>>; N], 452 buf: [MaybeUninit<UnsafeCell<T>>; N],
435 read_pos: usize, 453 read_pos: usize,