aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--anyfmt/Cargo.toml10
-rw-r--r--anyfmt/src/lib.rs149
-rw-r--r--embassy-nrf/Cargo.toml18
-rw-r--r--embassy-nrf/src/gpiote.rs5
-rw-r--r--embassy-nrf/src/interrupt.rs3
-rw-r--r--embassy-nrf/src/uarte.rs3
-rw-r--r--embassy/Cargo.toml6
-rw-r--r--embassy/src/executor/executor.rs3
-rw-r--r--embassy/src/flash.rs5
-rw-r--r--embassy/src/io/error.rs3
-rw-r--r--embassy/src/rand.rs5
-rw-r--r--embassy/src/time/duration.rs3
-rw-r--r--embassy/src/time/instant.rs3
-rw-r--r--embassy/src/time/mod.rs4
-rw-r--r--embassy/src/util/drop_bomb.rs3
-rw-r--r--embassy/src/util/macros.rs34
-rw-r--r--embassy/src/util/mod.rs77
-rw-r--r--embassy/src/util/portal.rs7
-rw-r--r--embassy/src/util/signal.rs3
-rw-r--r--examples/Cargo.toml13
-rw-r--r--examples/src/bin/gpiote.rs22
-rw-r--r--examples/src/bin/multiprio.rs16
-rw-r--r--examples/src/bin/qspi.rs7
-rw-r--r--examples/src/bin/rtc_async.rs6
-rw-r--r--examples/src/bin/rtc_raw.rs2
-rw-r--r--examples/src/bin/uart.rs12
-rw-r--r--examples/src/example_common.rs51
-rwxr-xr-xtest-build.sh26
29 files changed, 267 insertions, 233 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 57377d4bd..7336a2870 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,6 +3,7 @@
3members = [ 3members = [
4 "embassy", 4 "embassy",
5 "embassy-nrf", 5 "embassy-nrf",
6 "anyfmt",
6 "examples", 7 "examples",
7] 8]
8 9
diff --git a/anyfmt/Cargo.toml b/anyfmt/Cargo.toml
new file mode 100644
index 000000000..3ee7c167b
--- /dev/null
+++ b/anyfmt/Cargo.toml
@@ -0,0 +1,10 @@
1[package]
2name = "anyfmt"
3version = "0.1.0"
4authors = ["Dario Nieuwenhuis <[email protected]>"]
5edition = "2018"
6
7
8[dependencies]
9defmt = { version = "0.1.0", optional = true }
10log = { version = "0.4.11", optional = true }
diff --git a/anyfmt/src/lib.rs b/anyfmt/src/lib.rs
new file mode 100644
index 000000000..3286cc27b
--- /dev/null
+++ b/anyfmt/src/lib.rs
@@ -0,0 +1,149 @@
1#![no_std]
2
3pub mod export {
4 #[cfg(feature = "defmt")]
5 pub use defmt;
6 #[cfg(feature = "log")]
7 pub use log;
8}
9
10#[cfg(feature = "log")]
11#[macro_export]
12macro_rules! log {
13 (trace, $($arg:expr),*) => { $crate::export::log::trace!($($arg),*); };
14 (debug, $($arg:expr),*) => { $crate::export::log::debug!($($arg),*); };
15 (info, $($arg:expr),*) => { $crate::export::log::info!($($arg),*); };
16 (warn, $($arg:expr),*) => { $crate::export::log::warn!($($arg),*); };
17 (error, $($arg:expr),*) => { $crate::export::log::error!($($arg),*); };
18}
19
20#[cfg(feature = "defmt")]
21#[macro_export]
22macro_rules! log {
23 (trace, $($arg:expr),*) => { $crate::export::defmt::trace!($($arg),*); };
24 (debug, $($arg:expr),*) => { $crate::export::defmt::debug!($($arg),*); };
25 (info, $($arg:expr),*) => { $crate::export::defmt::info!($($arg),*); };
26 (warn, $($arg:expr),*) => { $crate::export::defmt::warn!($($arg),*); };
27 (error, $($arg:expr),*) => { $crate::export::defmt::error!($($arg),*); };
28}
29
30#[cfg(not(any(feature = "log", feature = "defmt")))]
31#[macro_export]
32macro_rules! log {
33 ($level:ident, $($arg:expr),*) => {{}};
34}
35
36#[macro_export]
37macro_rules! trace {
38 ($($arg:expr),*) => (log!(trace, $($arg),*));
39}
40
41#[macro_export]
42macro_rules! debug {
43 ($($arg:expr),*) => ($crate::log!(debug, $($arg),*));
44}
45
46#[macro_export]
47macro_rules! info {
48 ($($arg:expr),*) => ($crate::log!(info, $($arg),*));
49}
50
51#[macro_export]
52macro_rules! warn {
53 ($($arg:expr),*) => ($crate::log!(warn, $($arg),*));
54}
55
56#[macro_export]
57macro_rules! error {
58 ($($arg:expr),*) => ($crate::log!(error, $($arg),*));
59}
60
61#[macro_export]
62macro_rules! expect {
63 ($arg:expr, $msg:expr) => {
64 match $crate::Try::into_result($arg) {
65 ::core::result::Result::Ok(t) => t,
66 ::core::result::Result::Err(e) => {
67 $crate::panic!("{:?}: {:?}", $crate::intern!($msg), e);
68 }
69 }
70 };
71}
72
73#[cfg(feature = "defmt")]
74#[macro_export]
75macro_rules! intern {
76 ($arg:expr) => {
77 $crate::export::defmt::intern!($arg)
78 };
79}
80
81#[cfg(not(feature = "defmt"))]
82#[macro_export]
83macro_rules! intern {
84 ($arg:expr) => {
85 $arg
86 };
87}
88
89#[macro_export]
90macro_rules! unwrap {
91 ($arg:expr) => {
92 expect!($arg, "Unwrap failed")
93 };
94}
95
96#[macro_export]
97macro_rules! panic {
98 () => {
99 $crate::panic!("panic")
100 };
101 ($($arg:expr),*) => {{
102 $crate::log!(error, $($arg),*);
103 ::core::panic!()
104 }};
105}
106
107#[macro_export]
108macro_rules! assert {
109 ($cond:expr) => {
110 $crate::assert!($cond, "assertion failed");
111 };
112 ($cond:expr, $($arg:expr),*) => {
113 {
114 if !$cond {
115 $crate::panic!($($arg),*);
116 }
117 }
118 };
119}
120
121#[derive(Debug, Copy, Clone, Eq, PartialEq)]
122#[cfg_attr(feature = "defmt", derive(defmt::Format))]
123pub struct NoneError;
124
125pub trait Try {
126 type Ok;
127 type Error;
128 fn into_result(self) -> Result<Self::Ok, Self::Error>;
129}
130
131impl<T> Try for Option<T> {
132 type Ok = T;
133 type Error = NoneError;
134
135 #[inline]
136 fn into_result(self) -> Result<T, NoneError> {
137 self.ok_or(NoneError)
138 }
139}
140
141impl<T, E> Try for Result<T, E> {
142 type Ok = T;
143 type Error = E;
144
145 #[inline]
146 fn into_result(self) -> Self {
147 self
148 }
149}
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml
index 0019cbfb9..6cf23aa79 100644
--- a/embassy-nrf/Cargo.toml
+++ b/embassy-nrf/Cargo.toml
@@ -5,12 +5,11 @@ authors = ["Dario Nieuwenhuis <[email protected]>"]
5edition = "2018" 5edition = "2018"
6 6
7[features] 7[features]
8defmt-default = [] 8defmt-trace = [ ]
9defmt-trace = [] 9defmt-debug = [ ]
10defmt-debug = [] 10defmt-info = [ ]
11defmt-info = [] 11defmt-warn = [ ]
12defmt-warn = [] 12defmt-error = [ ]
13defmt-error = []
14 13
1552810 = ["nrf52810-pac", "nrf52810-hal"] 1452810 = ["nrf52810-pac", "nrf52810-hal"]
1652811 = ["nrf52811-pac"] #, "nrf52811-hal"] 1552811 = ["nrf52811-pac"] #, "nrf52811-hal"]
@@ -21,14 +20,17 @@ defmt-error = []
21 20
22[dependencies] 21[dependencies]
23embassy = { version = "0.1.0", path = "../embassy" } 22embassy = { version = "0.1.0", path = "../embassy" }
23
24anyfmt = { version = "0.1.0", path = "../anyfmt" }
25defmt = { version = "0.1.0", optional = true }
26
24cortex-m-rt = "0.6.12" 27cortex-m-rt = "0.6.12"
25cortex-m = { version = "0.6.3" } 28cortex-m = { version = "0.6.3" }
26embedded-hal = { version = "0.2.4" } 29embedded-hal = { version = "0.2.4" }
27bare-metal = { version = "0.2.0", features = ["const-fn"] } 30bare-metal = { version = "0.2.0", features = ["const-fn"] }
28defmt = "0.1.0"
29 31
30nrf52810-pac = { version = "0.9.0", optional = true } 32nrf52810-pac = { version = "0.9.0", optional = true }
31nrf52811-pac = { version = "0.9.0", optional = true } 33nrf52811-pac = { version = "0.9.1", optional = true }
32nrf52832-pac = { version = "0.9.0", optional = true } 34nrf52832-pac = { version = "0.9.0", optional = true }
33nrf52833-pac = { version = "0.9.0", optional = true } 35nrf52833-pac = { version = "0.9.0", optional = true }
34nrf52840-pac = { version = "0.9.0", optional = true } 36nrf52840-pac = { version = "0.9.0", optional = true }
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 0b9a33b3a..c18db2626 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -1,6 +1,6 @@
1use anyfmt::*;
1use core::cell::Cell; 2use core::cell::Cell;
2use core::ptr; 3use core::ptr;
3use defmt::trace;
4use embassy::util::Signal; 4use embassy::util::Signal;
5 5
6use crate::hal::gpio::{Input, Level, Output, Pin, Port}; 6use crate::hal::gpio::{Input, Level, Output, Pin, Port};
@@ -34,7 +34,8 @@ pub enum TaskOutPolarity {
34 Toggle, 34 Toggle,
35} 35}
36 36
37#[derive(defmt::Format)] 37#[derive(Debug, Copy, Clone, Eq, PartialEq)]
38#[cfg_attr(feature = "defmt", derive(defmt::Format))]
38pub enum NewChannelError { 39pub enum NewChannelError {
39 NoFreeChannels, 40 NoFreeChannels,
40} 41}
diff --git a/embassy-nrf/src/interrupt.rs b/embassy-nrf/src/interrupt.rs
index 581adff74..8918b13ee 100644
--- a/embassy-nrf/src/interrupt.rs
+++ b/embassy-nrf/src/interrupt.rs
@@ -12,7 +12,8 @@ pub use crate::pac::Interrupt;
12pub use crate::pac::Interrupt::*; // needed for cortex-m-rt #[interrupt] 12pub use crate::pac::Interrupt::*; // needed for cortex-m-rt #[interrupt]
13pub use bare_metal::{CriticalSection, Mutex}; 13pub use bare_metal::{CriticalSection, Mutex};
14 14
15#[derive(defmt::Format, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 15#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
16#[cfg_attr(feature = "defmt", derive(defmt::Format))]
16#[repr(u8)] 17#[repr(u8)]
17pub enum Priority { 18pub enum Priority {
18 Level0 = 0, 19 Level0 = 0,
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 575405b57..13b06397d 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -28,7 +28,8 @@ pub use uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
28use embassy::io::{AsyncBufRead, AsyncWrite, Result}; 28use embassy::io::{AsyncBufRead, AsyncWrite, Result};
29use embassy::util::WakerStore; 29use embassy::util::WakerStore;
30 30
31use defmt::trace; 31use anyfmt::panic;
32use anyfmt::*;
32 33
33//use crate::trace; 34//use crate::trace;
34 35
diff --git a/embassy/Cargo.toml b/embassy/Cargo.toml
index 7e9ea91d8..6c9309763 100644
--- a/embassy/Cargo.toml
+++ b/embassy/Cargo.toml
@@ -6,7 +6,6 @@ edition = "2018"
6 6
7[features] 7[features]
8std = ["futures/std"] 8std = ["futures/std"]
9defmt-default = []
10defmt-trace = [] 9defmt-trace = []
11defmt-debug = [] 10defmt-debug = []
12defmt-info = [] 11defmt-info = []
@@ -14,9 +13,12 @@ defmt-warn = []
14defmt-error = [] 13defmt-error = []
15 14
16[dependencies] 15[dependencies]
17defmt = "0.1.0" 16anyfmt = { version = "0.1.0", path = "../anyfmt" }
17defmt = { version = "0.1.0", optional = true }
18
18cortex-m = "0.6.3" 19cortex-m = "0.6.3"
19futures = { version = "0.3.5", default-features = false } 20futures = { version = "0.3.5", default-features = false }
20pin-project = { version = "0.4.23", default-features = false } 21pin-project = { version = "0.4.23", default-features = false }
21futures-intrusive = { version = "0.3.1", default-features = false } 22futures-intrusive = { version = "0.3.1", default-features = false }
22embassy-macros = { version = "0.1.0", path = "../embassy-macros"} 23embassy-macros = { version = "0.1.0", path = "../embassy-macros"}
24
diff --git a/embassy/src/executor/executor.rs b/embassy/src/executor/executor.rs
index ff3a8517c..4d73cf9f0 100644
--- a/embassy/src/executor/executor.rs
+++ b/embassy/src/executor/executor.rs
@@ -63,7 +63,8 @@ pub struct Task<F: Future + 'static> {
63 future: UninitCell<F>, // Valid if STATE_RUNNING 63 future: UninitCell<F>, // Valid if STATE_RUNNING
64} 64}
65 65
66#[derive(Copy, Clone, Debug, defmt::Format)] 66#[derive(Copy, Clone, Debug)]
67#[cfg_attr(feature = "defmt", derive(defmt::Format))]
67pub enum SpawnError { 68pub enum SpawnError {
68 Busy, 69 Busy,
69} 70}
diff --git a/embassy/src/flash.rs b/embassy/src/flash.rs
index bf6d59804..ca9fb5952 100644
--- a/embassy/src/flash.rs
+++ b/embassy/src/flash.rs
@@ -1,7 +1,7 @@
1
2use core::future::Future; 1use core::future::Future;
3 2
4#[derive(defmt::Format, Copy, Clone, Debug, Eq, PartialEq)] 3#[derive(Copy, Clone, Debug, Eq, PartialEq)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub enum Error { 5pub enum Error {
6 Failed, 6 Failed,
7 AddressMisaligned, 7 AddressMisaligned,
@@ -48,4 +48,3 @@ pub trait Flash {
48 /// This is guaranteed to be a power of 2. 48 /// This is guaranteed to be a power of 2.
49 fn erase_size(&self) -> usize; 49 fn erase_size(&self) -> usize;
50} 50}
51
diff --git a/embassy/src/io/error.rs b/embassy/src/io/error.rs
index 8fa1d93ff..8bad0cdb1 100644
--- a/embassy/src/io/error.rs
+++ b/embassy/src/io/error.rs
@@ -2,7 +2,8 @@
2/// 2///
3/// This list is intended to grow over time and it is not recommended to 3/// This list is intended to grow over time and it is not recommended to
4/// exhaustively match against it. 4/// exhaustively match against it.
5#[derive(defmt::Format, Debug, Clone, Copy, PartialEq, Eq)] 5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6pub enum Error { 7pub enum Error {
7 /// An entity was not found, often a file. 8 /// An entity was not found, often a file.
8 NotFound, 9 NotFound,
diff --git a/embassy/src/rand.rs b/embassy/src/rand.rs
index bb6cd9d3d..dbabb6f2b 100644
--- a/embassy/src/rand.rs
+++ b/embassy/src/rand.rs
@@ -1,4 +1,5 @@
1use crate::util::Dewrap; 1use anyfmt::*;
2
2pub trait Rand { 3pub trait Rand {
3 fn rand(&self, buf: &mut [u8]); 4 fn rand(&self, buf: &mut [u8]);
4} 5}
@@ -10,5 +11,5 @@ pub unsafe fn set_rand(rand: &'static dyn Rand) {
10} 11}
11 12
12pub fn rand(buf: &mut [u8]) { 13pub fn rand(buf: &mut [u8]) {
13 unsafe { RAND.dexpect(defmt::intern!("No rand set")).rand(buf) } 14 unsafe { expect!(RAND, "No rand set").rand(buf) }
14} 15}
diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs
index 604a17502..8135961ea 100644
--- a/embassy/src/time/duration.rs
+++ b/embassy/src/time/duration.rs
@@ -3,7 +3,8 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
3 3
4use super::TICKS_PER_SECOND; 4use super::TICKS_PER_SECOND;
5 5
6#[derive(defmt::Format, Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] 6#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
7#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7pub struct Duration { 8pub struct Duration {
8 pub(crate) ticks: u64, 9 pub(crate) ticks: u64,
9} 10}
diff --git a/embassy/src/time/instant.rs b/embassy/src/time/instant.rs
index a7f268e1a..75098081f 100644
--- a/embassy/src/time/instant.rs
+++ b/embassy/src/time/instant.rs
@@ -5,7 +5,8 @@ use core::ops::{Add, AddAssign, Sub, SubAssign};
5use super::TICKS_PER_SECOND; 5use super::TICKS_PER_SECOND;
6use super::{now, Duration}; 6use super::{now, Duration};
7 7
8#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, defmt::Format)] 8#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9pub struct Instant { 10pub struct Instant {
10 ticks: u64, 11 ticks: u64,
11} 12}
diff --git a/embassy/src/time/mod.rs b/embassy/src/time/mod.rs
index da2e1c21d..a3792e3c8 100644
--- a/embassy/src/time/mod.rs
+++ b/embassy/src/time/mod.rs
@@ -8,7 +8,7 @@ pub use instant::Instant;
8pub use timer::Timer; 8pub use timer::Timer;
9pub use traits::*; 9pub use traits::*;
10 10
11use crate::util::Dewrap; 11use anyfmt::*;
12 12
13// TODO allow customizing, probably via Cargo features `tick-hz-32768` or something. 13// TODO allow customizing, probably via Cargo features `tick-hz-32768` or something.
14pub const TICKS_PER_SECOND: u64 = 32768; 14pub const TICKS_PER_SECOND: u64 = 32768;
@@ -20,5 +20,5 @@ pub unsafe fn set_clock(clock: &'static dyn Clock) {
20} 20}
21 21
22pub(crate) fn now() -> u64 { 22pub(crate) fn now() -> u64 {
23 unsafe { CLOCK.dexpect(defmt::intern!("No clock set")).now() } 23 unsafe { expect!(CLOCK, "No clock set").now() }
24} 24}
diff --git a/embassy/src/util/drop_bomb.rs b/embassy/src/util/drop_bomb.rs
index 2a995a826..0ef051cf4 100644
--- a/embassy/src/util/drop_bomb.rs
+++ b/embassy/src/util/drop_bomb.rs
@@ -1,3 +1,4 @@
1use anyfmt::panic;
1use core::mem; 2use core::mem;
2 3
3pub struct DropBomb { 4pub struct DropBomb {
@@ -16,6 +17,6 @@ impl DropBomb {
16 17
17impl Drop for DropBomb { 18impl Drop for DropBomb {
18 fn drop(&mut self) { 19 fn drop(&mut self) {
19 depanic!("boom") 20 panic!("boom")
20 } 21 }
21} 22}
diff --git a/embassy/src/util/macros.rs b/embassy/src/util/macros.rs
deleted file mode 100644
index 3773af698..000000000
--- a/embassy/src/util/macros.rs
+++ /dev/null
@@ -1,34 +0,0 @@
1#![macro_use]
2
3#[macro_export]
4macro_rules! depanic {
5 ($( $i:expr ),*) => {
6 {
7 defmt::error!($( $i ),*);
8 panic!();
9 }
10 }
11}
12
13#[macro_export]
14macro_rules! deassert {
15 ($cond:expr) => {
16 deassert!($cond, "assertion failed");
17 };
18 ($cond:expr, $msg:literal) => {
19 {
20 if !$cond {
21 defmt::error!($msg);
22 panic!();
23 }
24 }
25 };
26 ($cond:expr, $msg:literal, $( $i:expr ),*) => {
27 {
28 if !$cond {
29 defmt::error!($msg, $( $i ),*);
30 panic!();
31 }
32 }
33 };
34}
diff --git a/embassy/src/util/mod.rs b/embassy/src/util/mod.rs
index 9f44c08c9..94745b834 100644
--- a/embassy/src/util/mod.rs
+++ b/embassy/src/util/mod.rs
@@ -1,74 +1,11 @@
1#![macro_use] 1mod drop_bomb;
2 2mod forever;
3mod macros;
4
5mod signal;
6pub use signal::*;
7mod portal; 3mod portal;
8pub use portal::*; 4mod signal;
9mod waker_store; 5mod waker_store;
10pub use waker_store::*; 6
11mod drop_bomb;
12pub use drop_bomb::*; 7pub use drop_bomb::*;
13mod forever;
14pub use forever::*; 8pub use forever::*;
15 9pub use portal::*;
16use defmt::{debug, error, info, intern, trace, warn}; 10pub use signal::*;
17 11pub use waker_store::*;
18pub use macros::*;
19
20pub trait Dewrap<T> {
21 /// dewrap = defmt unwrap
22 fn dewrap(self) -> T;
23
24 /// dexpect = defmt expect
25 fn dexpect<M: defmt::Format>(self, msg: M) -> T;
26
27 fn dewarn<M: defmt::Format>(self, msg: M) -> Self;
28}
29
30impl<T> Dewrap<T> for Option<T> {
31 fn dewrap(self) -> T {
32 match self {
33 Some(t) => t,
34 None => depanic!("unwrap failed: enum is none"),
35 }
36 }
37
38 fn dexpect<M: defmt::Format>(self, msg: M) -> T {
39 match self {
40 Some(t) => t,
41 None => depanic!("unexpected None: {:?}", msg),
42 }
43 }
44
45 fn dewarn<M: defmt::Format>(self, msg: M) -> Self {
46 if self.is_none() {
47 warn!("{:?} is none", msg);
48 }
49 self
50 }
51}
52
53impl<T, E: defmt::Format> Dewrap<T> for Result<T, E> {
54 fn dewrap(self) -> T {
55 match self {
56 Ok(t) => t,
57 Err(e) => depanic!("unwrap failed: {:?}", e),
58 }
59 }
60
61 fn dexpect<M: defmt::Format>(self, msg: M) -> T {
62 match self {
63 Ok(t) => t,
64 Err(e) => depanic!("unexpected error: {:?}: {:?}", msg, e),
65 }
66 }
67
68 fn dewarn<M: defmt::Format>(self, msg: M) -> Self {
69 if let Err(e) = &self {
70 warn!("{:?} err: {:?}", msg, e);
71 }
72 self
73 }
74}
diff --git a/embassy/src/util/portal.rs b/embassy/src/util/portal.rs
index e01968c5f..8f5d812f4 100644
--- a/embassy/src/util/portal.rs
+++ b/embassy/src/util/portal.rs
@@ -1,3 +1,4 @@
1use anyfmt::panic;
1use core::cell::UnsafeCell; 2use core::cell::UnsafeCell;
2use core::future::Future; 3use core::future::Future;
3use core::mem; 4use core::mem;
@@ -27,7 +28,7 @@ impl<T> Portal<T> {
27 unsafe { 28 unsafe {
28 match *self.state.get() { 29 match *self.state.get() {
29 State::None => {} 30 State::None => {}
30 State::Running => depanic!("Portall::call() called reentrantly"), 31 State::Running => panic!("Portall::call() called reentrantly"),
31 State::Waiting(func) => (*func)(val), 32 State::Waiting(func) => (*func)(val),
32 } 33 }
33 } 34 }
@@ -58,7 +59,7 @@ impl<T> Portal<T> {
58 let state = &mut *self.state.get(); 59 let state = &mut *self.state.get();
59 match state { 60 match state {
60 State::None => {} 61 State::None => {}
61 _ => depanic!("Multiple tasks waiting on same portal"), 62 _ => panic!("Multiple tasks waiting on same portal"),
62 } 63 }
63 *state = State::Waiting(func_ptr); 64 *state = State::Waiting(func_ptr);
64 } 65 }
@@ -110,7 +111,7 @@ impl<T> Portal<T> {
110 let state = &mut *self.state.get(); 111 let state = &mut *self.state.get();
111 match *state { 112 match *state {
112 State::None => {} 113 State::None => {}
113 _ => depanic!("Multiple tasks waiting on same portal"), 114 _ => panic!("Multiple tasks waiting on same portal"),
114 } 115 }
115 *state = State::Waiting(func_ptr); 116 *state = State::Waiting(func_ptr);
116 } 117 }
diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs
index 32286a30e..783725247 100644
--- a/embassy/src/util/signal.rs
+++ b/embassy/src/util/signal.rs
@@ -1,3 +1,4 @@
1use anyfmt::panic;
1use core::cell::UnsafeCell; 2use core::cell::UnsafeCell;
2use core::future::Future; 3use core::future::Future;
3use core::mem; 4use core::mem;
@@ -58,7 +59,7 @@ impl<'a, T: Send> Future for WaitFuture<'a, T> {
58 Poll::Pending 59 Poll::Pending
59 } 60 }
60 State::Waiting(w) if w.will_wake(cx.waker()) => Poll::Pending, 61 State::Waiting(w) if w.will_wake(cx.waker()) => Poll::Pending,
61 State::Waiting(_) => depanic!("waker overflow"), 62 State::Waiting(_) => panic!("waker overflow"),
62 State::Signaled(_) => match mem::replace(state, State::None) { 63 State::Signaled(_) => match mem::replace(state, State::None) {
63 State::Signaled(res) => Poll::Ready(res), 64 State::Signaled(res) => Poll::Ready(res),
64 _ => unreachable!(), 65 _ => unreachable!(),
diff --git a/examples/Cargo.toml b/examples/Cargo.toml
index 8eb7a5ff7..719f73269 100644
--- a/examples/Cargo.toml
+++ b/examples/Cargo.toml
@@ -17,14 +17,17 @@ defmt-error = []
17 17
18 18
19[dependencies] 19[dependencies]
20embassy = { version = "0.1.0", path = "../embassy", features = ["defmt"] }
21embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt", "defmt-trace", "52840"] }
22anyfmt = { version = "0.1.0", path = "../anyfmt", features = ["defmt"] }
23
24defmt = "0.1.0"
25defmt-rtt = "0.1.0"
26
20cortex-m = { version = "0.6.3" } 27cortex-m = { version = "0.6.3" }
21cortex-m-rt = "0.6.12" 28cortex-m-rt = "0.6.12"
22defmt = "0.1.0"
23embedded-hal = { version = "0.2.4" } 29embedded-hal = { version = "0.2.4" }
24defmt-rtt = "0.1.0"
25panic-probe = "0.1.0" 30panic-probe = "0.1.0"
26nrf52840-hal = { version = "0.11.0" } 31nrf52840-hal = { version = "0.11.0" }
27embassy = { version = "0.1.0", path = "../embassy" }
28embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt-trace", "52840"] }
29futures = { version = "0.3.7", default-features = false, features = ["async-await"] } 32futures = { version = "0.3.7", default-features = false, features = ["async-await"] }
30cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"} \ No newline at end of file 33cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"}
diff --git a/examples/src/bin/gpiote.rs b/examples/src/bin/gpiote.rs
index 16b4f06d7..d8394155d 100644
--- a/examples/src/bin/gpiote.rs
+++ b/examples/src/bin/gpiote.rs
@@ -15,7 +15,7 @@ use embassy_nrf::gpiote;
15 15
16#[task] 16#[task]
17async fn run() { 17async fn run() {
18 let p = embassy_nrf::pac::Peripherals::take().dewrap(); 18 let p = unwrap!(embassy_nrf::pac::Peripherals::take());
19 let port0 = gpio::p0::Parts::new(p.P0); 19 let port0 = gpio::p0::Parts::new(p.P0);
20 20
21 let g = gpiote::Gpiote::new(p.GPIOTE); 21 let g = gpiote::Gpiote::new(p.GPIOTE);
@@ -24,9 +24,7 @@ async fn run() {
24 24
25 let pin1 = port0.p0_11.into_pullup_input().degrade(); 25 let pin1 = port0.p0_11.into_pullup_input().degrade();
26 let button1 = async { 26 let button1 = async {
27 let ch = g 27 let ch = unwrap!(g.new_input_channel(pin1, gpiote::EventPolarity::HiToLo));
28 .new_input_channel(pin1, gpiote::EventPolarity::HiToLo)
29 .dewrap();
30 28
31 loop { 29 loop {
32 ch.wait().await; 30 ch.wait().await;
@@ -36,9 +34,7 @@ async fn run() {
36 34
37 let pin2 = port0.p0_12.into_pullup_input().degrade(); 35 let pin2 = port0.p0_12.into_pullup_input().degrade();
38 let button2 = async { 36 let button2 = async {
39 let ch = g 37 let ch = unwrap!(g.new_input_channel(pin2, gpiote::EventPolarity::LoToHi));
40 .new_input_channel(pin2, gpiote::EventPolarity::LoToHi)
41 .dewrap();
42 38
43 loop { 39 loop {
44 ch.wait().await; 40 ch.wait().await;
@@ -48,9 +44,7 @@ async fn run() {
48 44
49 let pin3 = port0.p0_24.into_pullup_input().degrade(); 45 let pin3 = port0.p0_24.into_pullup_input().degrade();
50 let button3 = async { 46 let button3 = async {
51 let ch = g 47 let ch = unwrap!(g.new_input_channel(pin3, gpiote::EventPolarity::Toggle));
52 .new_input_channel(pin3, gpiote::EventPolarity::Toggle)
53 .dewrap();
54 48
55 loop { 49 loop {
56 ch.wait().await; 50 ch.wait().await;
@@ -60,9 +54,7 @@ async fn run() {
60 54
61 let pin4 = port0.p0_25.into_pullup_input().degrade(); 55 let pin4 = port0.p0_25.into_pullup_input().degrade();
62 let button4 = async { 56 let button4 = async {
63 let ch = g 57 let ch = unwrap!(g.new_input_channel(pin4, gpiote::EventPolarity::Toggle));
64 .new_input_channel(pin4, gpiote::EventPolarity::Toggle)
65 .dewrap();
66 58
67 loop { 59 loop {
68 ch.wait().await; 60 ch.wait().await;
@@ -79,8 +71,8 @@ static EXECUTOR: Forever<Executor> = Forever::new();
79fn main() -> ! { 71fn main() -> ! {
80 info!("Hello World!"); 72 info!("Hello World!");
81 73
82 let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); 74 let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
83 executor.spawn(run()).dewrap(); 75 unwrap!(executor.spawn(run()));
84 76
85 loop { 77 loop {
86 executor.run(); 78 executor.run();
diff --git a/examples/src/bin/multiprio.rs b/examples/src/bin/multiprio.rs
index dbca491e0..e73747ac6 100644
--- a/examples/src/bin/multiprio.rs
+++ b/examples/src/bin/multiprio.rs
@@ -120,7 +120,7 @@ static EXECUTOR_HIGH: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::n
120fn main() -> ! { 120fn main() -> ! {
121 info!("Hello World!"); 121 info!("Hello World!");
122 122
123 let p = embassy_nrf::pac::Peripherals::take().dewrap(); 123 let p = unwrap!(embassy_nrf::pac::Peripherals::take());
124 124
125 clocks::Clocks::new(p.CLOCK) 125 clocks::Clocks::new(p.CLOCK)
126 .enable_ext_hfosc() 126 .enable_ext_hfosc()
@@ -132,17 +132,21 @@ fn main() -> ! {
132 unsafe { embassy::time::set_clock(rtc) }; 132 unsafe { embassy::time::set_clock(rtc) };
133 133
134 let executor_low = EXECUTOR_LOW.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev)); 134 let executor_low = EXECUTOR_LOW.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev));
135 let executor_med = EXECUTOR_MED.put(TimerExecutor::new(rtc.alarm1(), cortex_m::asm::sev)); 135 let executor_med = EXECUTOR_MED.put(TimerExecutor::new(rtc.alarm1(), || {
136 let executor_high = EXECUTOR_HIGH.put(TimerExecutor::new(rtc.alarm2(), cortex_m::asm::sev)); 136 interrupt::pend(interrupt::SWI0_EGU0)
137 }));
138 let executor_high = EXECUTOR_HIGH.put(TimerExecutor::new(rtc.alarm2(), || {
139 interrupt::pend(interrupt::SWI1_EGU1)
140 }));
137 141
138 interrupt::set_priority(interrupt::SWI0_EGU0, interrupt::Priority::Level7); 142 interrupt::set_priority(interrupt::SWI0_EGU0, interrupt::Priority::Level7);
139 interrupt::set_priority(interrupt::SWI1_EGU1, interrupt::Priority::Level6); 143 interrupt::set_priority(interrupt::SWI1_EGU1, interrupt::Priority::Level6);
140 interrupt::enable(interrupt::SWI0_EGU0); 144 interrupt::enable(interrupt::SWI0_EGU0);
141 interrupt::enable(interrupt::SWI1_EGU1); 145 interrupt::enable(interrupt::SWI1_EGU1);
142 146
143 executor_low.spawn(run_low()).dewrap(); 147 unwrap!(executor_low.spawn(run_low()));
144 executor_med.spawn(run_med()).dewrap(); 148 unwrap!(executor_med.spawn(run_med()));
145 executor_high.spawn(run_high()).dewrap(); 149 unwrap!(executor_high.spawn(run_high()));
146 150
147 loop { 151 loop {
148 executor_low.run(); 152 executor_low.run();
diff --git a/examples/src/bin/qspi.rs b/examples/src/bin/qspi.rs
index caabac8ba..a7f668ca7 100644
--- a/examples/src/bin/qspi.rs
+++ b/examples/src/bin/qspi.rs
@@ -6,6 +6,7 @@
6mod example_common; 6mod example_common;
7use example_common::*; 7use example_common::*;
8 8
9use anyfmt::panic;
9use cortex_m_rt::entry; 10use cortex_m_rt::entry;
10use nrf52840_hal::gpio; 11use nrf52840_hal::gpio;
11 12
@@ -23,7 +24,7 @@ struct AlignedBuf([u8; 4096]);
23 24
24#[task] 25#[task]
25async fn run() { 26async fn run() {
26 let p = embassy_nrf::pac::Peripherals::take().dewrap(); 27 let p = unwrap!(embassy_nrf::pac::Peripherals::take());
27 28
28 let port0 = gpio::p0::Parts::new(p.P0); 29 let port0 = gpio::p0::Parts::new(p.P0);
29 30
@@ -121,8 +122,8 @@ static EXECUTOR: Forever<Executor> = Forever::new();
121fn main() -> ! { 122fn main() -> ! {
122 info!("Hello World!"); 123 info!("Hello World!");
123 124
124 let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); 125 let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
125 executor.spawn(run()).dewrap(); 126 unwrap!(executor.spawn(run()));
126 127
127 loop { 128 loop {
128 executor.run(); 129 executor.run();
diff --git a/examples/src/bin/rtc_async.rs b/examples/src/bin/rtc_async.rs
index 5126a2cc8..b4ee736b7 100644
--- a/examples/src/bin/rtc_async.rs
+++ b/examples/src/bin/rtc_async.rs
@@ -39,7 +39,7 @@ static EXECUTOR: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new();
39fn main() -> ! { 39fn main() -> ! {
40 info!("Hello World!"); 40 info!("Hello World!");
41 41
42 let p = embassy_nrf::pac::Peripherals::take().dewrap(); 42 let p = unwrap!(embassy_nrf::pac::Peripherals::take());
43 43
44 clocks::Clocks::new(p.CLOCK) 44 clocks::Clocks::new(p.CLOCK)
45 .enable_ext_hfosc() 45 .enable_ext_hfosc()
@@ -53,8 +53,8 @@ fn main() -> ! {
53 53
54 let executor = EXECUTOR.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev)); 54 let executor = EXECUTOR.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev));
55 55
56 executor.spawn(run1()).dewrap(); 56 unwrap!(executor.spawn(run1()));
57 executor.spawn(run2()).dewrap(); 57 unwrap!(executor.spawn(run2()));
58 58
59 loop { 59 loop {
60 executor.run(); 60 executor.run();
diff --git a/examples/src/bin/rtc_raw.rs b/examples/src/bin/rtc_raw.rs
index 4453ecae1..ad5fab246 100644
--- a/examples/src/bin/rtc_raw.rs
+++ b/examples/src/bin/rtc_raw.rs
@@ -18,7 +18,7 @@ static mut RTC: MaybeUninit<rtc::RTC<embassy_nrf::pac::RTC1>> = MaybeUninit::uni
18fn main() -> ! { 18fn main() -> ! {
19 info!("Hello World!"); 19 info!("Hello World!");
20 20
21 let p = embassy_nrf::pac::Peripherals::take().dewrap(); 21 let p = unwrap!(embassy_nrf::pac::Peripherals::take());
22 22
23 clocks::Clocks::new(p.CLOCK) 23 clocks::Clocks::new(p.CLOCK)
24 .enable_ext_hfosc() 24 .enable_ext_hfosc()
diff --git a/examples/src/bin/uart.rs b/examples/src/bin/uart.rs
index eeaf5fee6..553bbb356 100644
--- a/examples/src/bin/uart.rs
+++ b/examples/src/bin/uart.rs
@@ -17,7 +17,7 @@ use embassy_nrf::uarte;
17 17
18#[task] 18#[task]
19async fn run() { 19async fn run() {
20 let p = embassy_nrf::pac::Peripherals::take().dewrap(); 20 let p = unwrap!(embassy_nrf::pac::Peripherals::take());
21 21
22 let port0 = gpio::p0::Parts::new(p.P0); 22 let port0 = gpio::p0::Parts::new(p.P0);
23 23
@@ -41,14 +41,14 @@ async fn run() {
41 41
42 info!("uarte initialized!"); 42 info!("uarte initialized!");
43 43
44 u.write_all(b"Hello!\r\n").await.dewrap(); 44 unwrap!(u.write_all(b"Hello!\r\n").await);
45 info!("wrote hello in uart!"); 45 info!("wrote hello in uart!");
46 46
47 // Simple demo, reading 8-char chunks and echoing them back reversed. 47 // Simple demo, reading 8-char chunks and echoing them back reversed.
48 loop { 48 loop {
49 info!("reading..."); 49 info!("reading...");
50 let mut buf = [0u8; 8]; 50 let mut buf = [0u8; 8];
51 u.read_exact(&mut buf).await.dewrap(); 51 unwrap!(u.read_exact(&mut buf).await);
52 info!("read done, got {:[u8]}", buf); 52 info!("read done, got {:[u8]}", buf);
53 53
54 // Reverse buf 54 // Reverse buf
@@ -59,7 +59,7 @@ async fn run() {
59 } 59 }
60 60
61 info!("writing..."); 61 info!("writing...");
62 u.write_all(&buf).await.dewrap(); 62 unwrap!(u.write_all(&buf).await);
63 info!("write done"); 63 info!("write done");
64 } 64 }
65} 65}
@@ -70,8 +70,8 @@ static EXECUTOR: Forever<Executor> = Forever::new();
70fn main() -> ! { 70fn main() -> ! {
71 info!("Hello World!"); 71 info!("Hello World!");
72 72
73 let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); 73 let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
74 executor.spawn(run()).dewrap(); 74 unwrap!(executor.spawn(run()));
75 75
76 loop { 76 loop {
77 executor.run(); 77 executor.run();
diff --git a/examples/src/example_common.rs b/examples/src/example_common.rs
index 65bfe6bb1..1a12fa69a 100644
--- a/examples/src/example_common.rs
+++ b/examples/src/example_common.rs
@@ -4,7 +4,7 @@ use defmt_rtt as _; // global logger
4use nrf52840_hal as _; 4use nrf52840_hal as _;
5use panic_probe as _; 5use panic_probe as _;
6 6
7pub use defmt::{info, intern}; 7pub use anyfmt::*;
8 8
9use core::sync::atomic::{AtomicUsize, Ordering}; 9use core::sync::atomic::{AtomicUsize, Ordering};
10 10
@@ -16,52 +16,3 @@ fn timestamp() -> u64 {
16 COUNT.store(n + 1, Ordering::Relaxed); 16 COUNT.store(n + 1, Ordering::Relaxed);
17 n as u64 17 n as u64
18} 18}
19
20macro_rules! depanic {
21 ($( $i:expr ),*) => {
22 {
23 defmt::error!($( $i ),*);
24 panic!();
25 }
26 }
27}
28
29pub trait Dewrap<T> {
30 /// dewrap = defmt unwrap
31 fn dewrap(self) -> T;
32
33 /// dexpect = defmt expect
34 fn dexpect<M: defmt::Format>(self, msg: M) -> T;
35}
36
37impl<T> Dewrap<T> for Option<T> {
38 fn dewrap(self) -> T {
39 match self {
40 Some(t) => t,
41 None => depanic!("Dewrap failed: enum is none"),
42 }
43 }
44
45 fn dexpect<M: defmt::Format>(self, msg: M) -> T {
46 match self {
47 Some(t) => t,
48 None => depanic!("Unexpected None: {:?}", msg),
49 }
50 }
51}
52
53impl<T, E: defmt::Format> Dewrap<T> for Result<T, E> {
54 fn dewrap(self) -> T {
55 match self {
56 Ok(t) => t,
57 Err(e) => depanic!("Dewrap failed: {:?}", e),
58 }
59 }
60
61 fn dexpect<M: defmt::Format>(self, msg: M) -> T {
62 match self {
63 Ok(t) => t,
64 Err(e) => depanic!("Unexpected error: {:?}: {:?}", msg, e),
65 }
66 }
67}
diff --git a/test-build.sh b/test-build.sh
index 8c93484d2..0b905e2cc 100755
--- a/test-build.sh
+++ b/test-build.sh
@@ -2,13 +2,19 @@
2 2
3set -euxo pipefail 3set -euxo pipefail
4 4
5cargo build --target thumbv7em-none-eabihf -p embassy-examples --bins 5# examples
6cargo build --target thumbv7em-none-eabihf -p embassy 6(cd examples; cargo build --target thumbv7em-none-eabihf --bins)
7 7
8# Build with all feature combinations 8# embassy
9cd embassy-nrf 9(cd embassy; cargo build --target thumbv7em-none-eabihf)
10cargo build --target thumbv7em-none-eabihf -p embassy-nrf --features 52810 10(cd embassy; cargo build --target thumbv7em-none-eabihf --features defmt,anyfmt/defmt)
11#cargo build --target thumbv7em-none-eabihf -p embassy-nrf --features 52811 # nrf52811-hal doesn't exist yet 11(cd embassy; cargo build --target thumbv7em-none-eabihf --features anyfmt/log)
12cargo build --target thumbv7em-none-eabihf -p embassy-nrf --features 52832 12
13cargo build --target thumbv7em-none-eabihf -p embassy-nrf --features 52833 13# embassy-nrf
14cargo build --target thumbv7em-none-eabihf -p embassy-nrf --features 52840 14(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52810)
15#(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52811) # nrf52811-hal doesn't exist yet
16(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52832)
17(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52833)
18(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840)
19
20(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840,defmt,embassy/defmt,anyfmt/defmt)