aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nxp/Cargo.toml2
-rw-r--r--embassy-nxp/src/fmt.rs284
-rw-r--r--embassy-nxp/src/gpio/lpc55.rs1
-rw-r--r--embassy-nxp/src/lib.rs1
-rw-r--r--embassy-nxp/src/pint.rs2
-rw-r--r--examples/lpc55s69/Cargo.toml2
6 files changed, 290 insertions, 2 deletions
diff --git a/embassy-nxp/Cargo.toml b/embassy-nxp/Cargo.toml
index 01f57c4e2..56d00bfb2 100644
--- a/embassy-nxp/Cargo.toml
+++ b/embassy-nxp/Cargo.toml
@@ -10,6 +10,7 @@ critical-section = "1.1.2"
10embassy-hal-internal = { version = "0.3.0", path = "../embassy-hal-internal", features = ["cortex-m", "prio-bits-2"] } 10embassy-hal-internal = { version = "0.3.0", path = "../embassy-hal-internal", features = ["cortex-m", "prio-bits-2"] }
11embassy-sync = { version = "0.7.0", path = "../embassy-sync" } 11embassy-sync = { version = "0.7.0", path = "../embassy-sync" }
12defmt = { version = "1", optional = true } 12defmt = { version = "1", optional = true }
13log = { version = "0.4.27", optional = true }
13 14
14## Chip dependencies 15## Chip dependencies
15lpc55-pac = { version = "0.5.0", optional = true } 16lpc55-pac = { version = "0.5.0", optional = true }
@@ -21,7 +22,6 @@ rt = ["lpc55-pac?/rt"]
21 22
22## Enable [defmt support](https://docs.rs/defmt) and enables `defmt` debug-log messages and formatting in embassy drivers. 23## Enable [defmt support](https://docs.rs/defmt) and enables `defmt` debug-log messages and formatting in embassy drivers.
23defmt = ["dep:defmt", "embassy-hal-internal/defmt", "embassy-sync/defmt"] 24defmt = ["dep:defmt", "embassy-hal-internal/defmt", "embassy-sync/defmt"]
24
25## Reexport the PAC for the currently enabled chip at `embassy_nxp::pac` (unstable) 25## Reexport the PAC for the currently enabled chip at `embassy_nxp::pac` (unstable)
26unstable-pac = [] 26unstable-pac = []
27# This is unstable because semver-minor (non-breaking) releases of embassy-nrf may major-bump (breaking) the PAC version. 27# This is unstable because semver-minor (non-breaking) releases of embassy-nrf may major-bump (breaking) the PAC version.
diff --git a/embassy-nxp/src/fmt.rs b/embassy-nxp/src/fmt.rs
new file mode 100644
index 000000000..27d41ace6
--- /dev/null
+++ b/embassy-nxp/src/fmt.rs
@@ -0,0 +1,284 @@
1//! Copied from embassy-rp
2
3#![macro_use]
4#![allow(unused)]
5
6use core::fmt::{Debug, Display, LowerHex};
7
8#[cfg(all(feature = "defmt", feature = "log"))]
9compile_error!("You may not enable both `defmt` and `log` features.");
10
11#[collapse_debuginfo(yes)]
12macro_rules! assert {
13 ($($x:tt)*) => {
14 {
15 #[cfg(not(feature = "defmt"))]
16 ::core::assert!($($x)*);
17 #[cfg(feature = "defmt")]
18 ::defmt::assert!($($x)*);
19 }
20 };
21}
22
23#[collapse_debuginfo(yes)]
24macro_rules! assert_eq {
25 ($($x:tt)*) => {
26 {
27 #[cfg(not(feature = "defmt"))]
28 ::core::assert_eq!($($x)*);
29 #[cfg(feature = "defmt")]
30 ::defmt::assert_eq!($($x)*);
31 }
32 };
33}
34
35#[collapse_debuginfo(yes)]
36macro_rules! assert_ne {
37 ($($x:tt)*) => {
38 {
39 #[cfg(not(feature = "defmt"))]
40 ::core::assert_ne!($($x)*);
41 #[cfg(feature = "defmt")]
42 ::defmt::assert_ne!($($x)*);
43 }
44 };
45}
46
47#[collapse_debuginfo(yes)]
48macro_rules! debug_assert {
49 ($($x:tt)*) => {
50 {
51 #[cfg(not(feature = "defmt"))]
52 ::core::debug_assert!($($x)*);
53 #[cfg(feature = "defmt")]
54 ::defmt::debug_assert!($($x)*);
55 }
56 };
57}
58
59#[collapse_debuginfo(yes)]
60macro_rules! debug_assert_eq {
61 ($($x:tt)*) => {
62 {
63 #[cfg(not(feature = "defmt"))]
64 ::core::debug_assert_eq!($($x)*);
65 #[cfg(feature = "defmt")]
66 ::defmt::debug_assert_eq!($($x)*);
67 }
68 };
69}
70
71#[collapse_debuginfo(yes)]
72macro_rules! debug_assert_ne {
73 ($($x:tt)*) => {
74 {
75 #[cfg(not(feature = "defmt"))]
76 ::core::debug_assert_ne!($($x)*);
77 #[cfg(feature = "defmt")]
78 ::defmt::debug_assert_ne!($($x)*);
79 }
80 };
81}
82
83#[collapse_debuginfo(yes)]
84macro_rules! todo {
85 ($($x:tt)*) => {
86 {
87 #[cfg(not(feature = "defmt"))]
88 ::core::todo!($($x)*);
89 #[cfg(feature = "defmt")]
90 ::defmt::todo!($($x)*);
91 }
92 };
93}
94
95#[collapse_debuginfo(yes)]
96macro_rules! unreachable {
97 ($($x:tt)*) => {
98 {
99 #[cfg(not(feature = "defmt"))]
100 ::core::unreachable!($($x)*);
101 #[cfg(feature = "defmt")]
102 ::defmt::unreachable!($($x)*);
103 }
104 };
105}
106
107#[collapse_debuginfo(yes)]
108macro_rules! unimplemented {
109 ($($x:tt)*) => {
110 {
111 #[cfg(not(feature = "defmt"))]
112 ::core::unimplemented!($($x)*);
113 #[cfg(feature = "defmt")]
114 ::defmt::unimplemented!($($x)*);
115 }
116 };
117}
118
119#[collapse_debuginfo(yes)]
120macro_rules! panic {
121 ($($x:tt)*) => {
122 {
123 #[cfg(not(feature = "defmt"))]
124 ::core::panic!($($x)*);
125 #[cfg(feature = "defmt")]
126 ::defmt::panic!($($x)*);
127 }
128 };
129}
130
131#[collapse_debuginfo(yes)]
132macro_rules! trace {
133 ($s:literal $(, $x:expr)* $(,)?) => {
134 {
135 #[cfg(feature = "log")]
136 ::log::trace!($s $(, $x)*);
137 #[cfg(feature = "defmt")]
138 ::defmt::trace!($s $(, $x)*);
139 #[cfg(not(any(feature = "log", feature="defmt")))]
140 let _ = ($( & $x ),*);
141 }
142 };
143}
144
145#[collapse_debuginfo(yes)]
146macro_rules! debug {
147 ($s:literal $(, $x:expr)* $(,)?) => {
148 {
149 #[cfg(feature = "log")]
150 ::log::debug!($s $(, $x)*);
151 #[cfg(feature = "defmt")]
152 ::defmt::debug!($s $(, $x)*);
153 #[cfg(not(any(feature = "log", feature="defmt")))]
154 let _ = ($( & $x ),*);
155 }
156 };
157}
158
159#[collapse_debuginfo(yes)]
160macro_rules! info {
161 ($s:literal $(, $x:expr)* $(,)?) => {
162 {
163 #[cfg(feature = "log")]
164 ::log::info!($s $(, $x)*);
165 #[cfg(feature = "defmt")]
166 ::defmt::info!($s $(, $x)*);
167 #[cfg(not(any(feature = "log", feature="defmt")))]
168 let _ = ($( & $x ),*);
169 }
170 };
171}
172
173#[collapse_debuginfo(yes)]
174macro_rules! warn {
175 ($s:literal $(, $x:expr)* $(,)?) => {
176 {
177 #[cfg(feature = "log")]
178 ::log::warn!($s $(, $x)*);
179 #[cfg(feature = "defmt")]
180 ::defmt::warn!($s $(, $x)*);
181 #[cfg(not(any(feature = "log", feature="defmt")))]
182 let _ = ($( & $x ),*);
183 }
184 };
185}
186
187#[collapse_debuginfo(yes)]
188macro_rules! error {
189 ($s:literal $(, $x:expr)* $(,)?) => {
190 {
191 #[cfg(feature = "log")]
192 ::log::error!($s $(, $x)*);
193 #[cfg(feature = "defmt")]
194 ::defmt::error!($s $(, $x)*);
195 #[cfg(not(any(feature = "log", feature="defmt")))]
196 let _ = ($( & $x ),*);
197 }
198 };
199}
200
201#[cfg(feature = "defmt")]
202#[collapse_debuginfo(yes)]
203macro_rules! unwrap {
204 ($($x:tt)*) => {
205 ::defmt::unwrap!($($x)*)
206 };
207}
208
209#[cfg(not(feature = "defmt"))]
210#[collapse_debuginfo(yes)]
211macro_rules! unwrap {
212 ($arg:expr) => {
213 match $crate::fmt::Try::into_result($arg) {
214 ::core::result::Result::Ok(t) => t,
215 ::core::result::Result::Err(e) => {
216 ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
217 }
218 }
219 };
220 ($arg:expr, $($msg:expr),+ $(,)? ) => {
221 match $crate::fmt::Try::into_result($arg) {
222 ::core::result::Result::Ok(t) => t,
223 ::core::result::Result::Err(e) => {
224 ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
225 }
226 }
227 }
228}
229
230#[derive(Debug, Copy, Clone, Eq, PartialEq)]
231pub struct NoneError;
232
233pub trait Try {
234 type Ok;
235 type Error;
236 fn into_result(self) -> Result<Self::Ok, Self::Error>;
237}
238
239impl<T> Try for Option<T> {
240 type Ok = T;
241 type Error = NoneError;
242
243 #[inline]
244 fn into_result(self) -> Result<T, NoneError> {
245 self.ok_or(NoneError)
246 }
247}
248
249impl<T, E> Try for Result<T, E> {
250 type Ok = T;
251 type Error = E;
252
253 #[inline]
254 fn into_result(self) -> Self {
255 self
256 }
257}
258
259pub(crate) struct Bytes<'a>(pub &'a [u8]);
260
261impl<'a> Debug for Bytes<'a> {
262 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
263 write!(f, "{:#02x?}", self.0)
264 }
265}
266
267impl<'a> Display for Bytes<'a> {
268 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
269 write!(f, "{:#02x?}", self.0)
270 }
271}
272
273impl<'a> LowerHex for Bytes<'a> {
274 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
275 write!(f, "{:#02x?}", self.0)
276 }
277}
278
279#[cfg(feature = "defmt")]
280impl<'a> defmt::Format for Bytes<'a> {
281 fn format(&self, fmt: defmt::Formatter) {
282 defmt::write!(fmt, "{:02x}", self.0)
283 }
284}
diff --git a/embassy-nxp/src/gpio/lpc55.rs b/embassy-nxp/src/gpio/lpc55.rs
index 94cd8b7f8..8f407bb3a 100644
--- a/embassy-nxp/src/gpio/lpc55.rs
+++ b/embassy-nxp/src/gpio/lpc55.rs
@@ -7,6 +7,7 @@ pub(crate) fn init() {
7 syscon_reg() 7 syscon_reg()
8 .ahbclkctrl0 8 .ahbclkctrl0
9 .modify(|_, w| w.gpio0().enable().gpio1().enable().mux().enable().iocon().enable()); 9 .modify(|_, w| w.gpio0().enable().gpio1().enable().mux().enable().iocon().enable());
10 info!("GPIO initialized");
10} 11}
11 12
12/// The GPIO pin level for pins set on "Digital" mode. 13/// The GPIO pin level for pins set on "Digital" mode.
diff --git a/embassy-nxp/src/lib.rs b/embassy-nxp/src/lib.rs
index 433aca9e0..1abaca708 100644
--- a/embassy-nxp/src/lib.rs
+++ b/embassy-nxp/src/lib.rs
@@ -1,5 +1,6 @@
1#![no_std] 1#![no_std]
2 2
3pub mod fmt;
3pub mod gpio; 4pub mod gpio;
4#[cfg(feature = "lpc55")] 5#[cfg(feature = "lpc55")]
5pub mod pint; 6pub mod pint;
diff --git a/embassy-nxp/src/pint.rs b/embassy-nxp/src/pint.rs
index dc117e7e3..ff414b4e6 100644
--- a/embassy-nxp/src/pint.rs
+++ b/embassy-nxp/src/pint.rs
@@ -101,6 +101,8 @@ pub(crate) fn init() {
101 crate::pac::NVIC::unmask(crate::pac::Interrupt::PIN_INT6); 101 crate::pac::NVIC::unmask(crate::pac::Interrupt::PIN_INT6);
102 crate::pac::NVIC::unmask(crate::pac::Interrupt::PIN_INT7); 102 crate::pac::NVIC::unmask(crate::pac::Interrupt::PIN_INT7);
103 }; 103 };
104
105 info!("Pin interrupts initialized");
104} 106}
105 107
106#[must_use = "futures do nothing unless you `.await` or poll them"] 108#[must_use = "futures do nothing unless you `.await` or poll them"]
diff --git a/examples/lpc55s69/Cargo.toml b/examples/lpc55s69/Cargo.toml
index 6ec6e51a8..1724a22d4 100644
--- a/examples/lpc55s69/Cargo.toml
+++ b/examples/lpc55s69/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7 7
8[dependencies] 8[dependencies]
9embassy-nxp = { version = "0.1.0", path = "../../embassy-nxp", features = ["lpc55", "rt"] } 9embassy-nxp = { version = "0.1.0", path = "../../embassy-nxp", features = ["lpc55", "rt", "defmt"] }
10embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] } 10embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
11embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] } 11embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] } 12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }