aboutsummaryrefslogtreecommitdiff
path: root/embassy-extras/src
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-extras/src')
-rw-r--r--embassy-extras/src/fmt.rs201
-rw-r--r--embassy-extras/src/ring_buffer.rs2
2 files changed, 156 insertions, 47 deletions
diff --git a/embassy-extras/src/fmt.rs b/embassy-extras/src/fmt.rs
index 160642ccd..066970813 100644
--- a/embassy-extras/src/fmt.rs
+++ b/embassy-extras/src/fmt.rs
@@ -1,67 +1,178 @@
1#![macro_use] 1#![macro_use]
2#![allow(clippy::module_inception)] 2#![allow(unused_macros)]
3#![allow(unused)]
4 3
5#[cfg(all(feature = "defmt", feature = "log"))] 4#[cfg(all(feature = "defmt", feature = "log"))]
6compile_error!("You may not enable both `defmt` and `log` features."); 5compile_error!("You may not enable both `defmt` and `log` features.");
7 6
8pub use fmt::*; 7macro_rules! assert {
8 ($($x:tt)*) => {
9 {
10 #[cfg(not(feature = "defmt"))]
11 ::core::assert!($($x)*);
12 #[cfg(feature = "defmt")]
13 ::defmt::assert!($($x)*);
14 }
15 };
16}
9 17
10#[cfg(feature = "defmt")] 18macro_rules! assert_eq {
11mod fmt { 19 ($($x:tt)*) => {
12 pub use defmt::{ 20 {
13 assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, 21 #[cfg(not(feature = "defmt"))]
14 info, panic, todo, trace, unreachable, unwrap, warn, 22 ::core::assert_eq!($($x)*);
23 #[cfg(feature = "defmt")]
24 ::defmt::assert_eq!($($x)*);
25 }
15 }; 26 };
16} 27}
17 28
18#[cfg(feature = "log")] 29macro_rules! assert_ne {
19mod fmt { 30 ($($x:tt)*) => {
20 pub use core::{ 31 {
21 assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, 32 #[cfg(not(feature = "defmt"))]
22 unreachable, 33 ::core::assert_ne!($($x)*);
34 #[cfg(feature = "defmt")]
35 ::defmt::assert_ne!($($x)*);
36 }
23 }; 37 };
24 pub use log::{debug, error, info, trace, warn};
25} 38}
26 39
27#[cfg(not(any(feature = "defmt", feature = "log")))] 40macro_rules! debug_assert {
28mod fmt { 41 ($($x:tt)*) => {
29 #![macro_use] 42 {
43 #[cfg(not(feature = "defmt"))]
44 ::core::debug_assert!($($x)*);
45 #[cfg(feature = "defmt")]
46 ::defmt::debug_assert!($($x)*);
47 }
48 };
49}
30 50
31 pub use core::{ 51macro_rules! debug_assert_eq {
32 assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, 52 ($($x:tt)*) => {
33 unreachable, 53 {
54 #[cfg(not(feature = "defmt"))]
55 ::core::debug_assert_eq!($($x)*);
56 #[cfg(feature = "defmt")]
57 ::defmt::debug_assert_eq!($($x)*);
58 }
34 }; 59 };
60}
35 61
36 macro_rules! trace { 62macro_rules! debug_assert_ne {
37 ($($msg:expr),+ $(,)?) => { 63 ($($x:tt)*) => {
38 () 64 {
39 }; 65 #[cfg(not(feature = "defmt"))]
40 } 66 ::core::debug_assert_ne!($($x)*);
67 #[cfg(feature = "defmt")]
68 ::defmt::debug_assert_ne!($($x)*);
69 }
70 };
71}
41 72
42 macro_rules! debug { 73macro_rules! todo {
43 ($($msg:expr),+ $(,)?) => { 74 ($($x:tt)*) => {
44 () 75 {
45 }; 76 #[cfg(not(feature = "defmt"))]
46 } 77 ::core::todo!($($x)*);
78 #[cfg(feature = "defmt")]
79 ::defmt::todo!($($x)*);
80 }
81 };
82}
47 83
48 macro_rules! info { 84macro_rules! unreachable {
49 ($($msg:expr),+ $(,)?) => { 85 ($($x:tt)*) => {
50 () 86 {
51 }; 87 #[cfg(not(feature = "defmt"))]
52 } 88 ::core::unreachable!($($x)*);
89 #[cfg(feature = "defmt")]
90 ::defmt::unreachable!($($x)*);
91 }
92 };
93}
53 94
54 macro_rules! warn { 95macro_rules! panic {
55 ($($msg:expr),+ $(,)?) => { 96 ($($x:tt)*) => {
56 () 97 {
57 }; 98 #[cfg(not(feature = "defmt"))]
58 } 99 ::core::panic!($($x)*);
100 #[cfg(feature = "defmt")]
101 ::defmt::panic!($($x)*);
102 }
103 };
104}
59 105
60 macro_rules! error { 106macro_rules! trace {
61 ($($msg:expr),+ $(,)?) => { 107 ($s:literal $(, $x:expr)* $(,)?) => {
62 () 108 {
63 }; 109 #[cfg(feature = "log")]
64 } 110 ::log::trace!($s $(, $x)*);
111 #[cfg(feature = "defmt")]
112 ::defmt::trace!($s $(, $x)*);
113 #[cfg(not(any(feature = "log", feature="defmt")))]
114 let _ = ($( & $x ),*);
115 }
116 };
117}
118
119macro_rules! debug {
120 ($s:literal $(, $x:expr)* $(,)?) => {
121 {
122 #[cfg(feature = "log")]
123 ::log::debug!($s $(, $x)*);
124 #[cfg(feature = "defmt")]
125 ::defmt::debug!($s $(, $x)*);
126 #[cfg(not(any(feature = "log", feature="defmt")))]
127 let _ = ($( & $x ),*);
128 }
129 };
130}
131
132macro_rules! info {
133 ($s:literal $(, $x:expr)* $(,)?) => {
134 {
135 #[cfg(feature = "log")]
136 ::log::info!($s $(, $x)*);
137 #[cfg(feature = "defmt")]
138 ::defmt::info!($s $(, $x)*);
139 #[cfg(not(any(feature = "log", feature="defmt")))]
140 let _ = ($( & $x ),*);
141 }
142 };
143}
144
145macro_rules! warn {
146 ($s:literal $(, $x:expr)* $(,)?) => {
147 {
148 #[cfg(feature = "log")]
149 ::log::warn!($s $(, $x)*);
150 #[cfg(feature = "defmt")]
151 ::defmt::warn!($s $(, $x)*);
152 #[cfg(not(any(feature = "log", feature="defmt")))]
153 let _ = ($( & $x ),*);
154 }
155 };
156}
157
158macro_rules! error {
159 ($s:literal $(, $x:expr)* $(,)?) => {
160 {
161 #[cfg(feature = "log")]
162 ::log::error!($s $(, $x)*);
163 #[cfg(feature = "defmt")]
164 ::defmt::error!($s $(, $x)*);
165 #[cfg(not(any(feature = "log", feature="defmt")))]
166 let _ = ($( & $x ),*);
167 }
168 };
169}
170
171#[cfg(feature = "defmt")]
172macro_rules! unwrap {
173 ($($x:tt)*) => {
174 ::defmt::unwrap!($($x)*)
175 };
65} 176}
66 177
67#[cfg(not(feature = "defmt"))] 178#[cfg(not(feature = "defmt"))]
diff --git a/embassy-extras/src/ring_buffer.rs b/embassy-extras/src/ring_buffer.rs
index dafdd958a..18795787f 100644
--- a/embassy-extras/src/ring_buffer.rs
+++ b/embassy-extras/src/ring_buffer.rs
@@ -1,5 +1,3 @@
1use crate::fmt::assert;
2
3pub struct RingBuffer<'a> { 1pub struct RingBuffer<'a> {
4 buf: &'a mut [u8], 2 buf: &'a mut [u8],
5 start: usize, 3 start: usize,