diff options
| -rw-r--r-- | Cargo.toml | 7 | ||||
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | anyfmt/Cargo.toml | 10 | ||||
| -rw-r--r-- | anyfmt/src/lib.rs | 149 | ||||
| -rw-r--r-- | embassy-nrf/Cargo.toml | 19 | ||||
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 5 | ||||
| -rw-r--r-- | embassy-nrf/src/interrupt.rs | 5 | ||||
| -rw-r--r-- | embassy-nrf/src/qspi.rs | 47 | ||||
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 2 | ||||
| -rw-r--r-- | embassy/Cargo.toml | 7 | ||||
| -rw-r--r-- | embassy/src/executor/executor.rs | 3 | ||||
| -rw-r--r-- | embassy/src/flash.rs | 3 | ||||
| -rw-r--r-- | embassy/src/io/error.rs | 3 | ||||
| -rw-r--r-- | embassy/src/rand.rs | 4 | ||||
| -rw-r--r-- | embassy/src/time/duration.rs | 3 | ||||
| -rw-r--r-- | embassy/src/time/instant.rs | 3 | ||||
| -rw-r--r-- | embassy/src/time/mod.rs | 4 | ||||
| -rw-r--r-- | embassy/src/util/drop_bomb.rs | 2 | ||||
| -rw-r--r-- | embassy/src/util/portal.rs | 2 | ||||
| -rw-r--r-- | embassy/src/util/signal.rs | 2 | ||||
| -rw-r--r-- | examples/Cargo.toml | 11 | ||||
| -rw-r--r-- | examples/src/bin/qspi.rs | 3 | ||||
| -rw-r--r-- | examples/src/example_common.rs | 2 | ||||
| -rwxr-xr-x | test-build.sh | 6 |
24 files changed, 79 insertions, 231 deletions
diff --git a/Cargo.toml b/Cargo.toml index 7336a2870..3ad62f18d 100644 --- a/Cargo.toml +++ b/Cargo.toml | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | members = [ | 3 | members = [ |
| 4 | "embassy", | 4 | "embassy", |
| 5 | "embassy-nrf", | 5 | "embassy-nrf", |
| 6 | "anyfmt", | 6 | "embassy-macros", |
| 7 | "examples", | 7 | "examples", |
| 8 | ] | 8 | ] |
| 9 | 9 | ||
| @@ -11,11 +11,6 @@ exclude = [ | |||
| 11 | "third_party" | 11 | "third_party" |
| 12 | ] | 12 | ] |
| 13 | 13 | ||
| 14 | [patch.crates-io] | ||
| 15 | panic-probe = { git = "https://github.com/knurling-rs/probe-run", branch="main" } | ||
| 16 | defmt-rtt = { git = "https://github.com/knurling-rs/defmt", branch="main" } | ||
| 17 | defmt = { git = "https://github.com/knurling-rs/defmt", branch="main" } | ||
| 18 | |||
| 19 | [profile.dev] | 14 | [profile.dev] |
| 20 | codegen-units = 1 | 15 | codegen-units = 1 |
| 21 | debug = 2 | 16 | debug = 2 |
| @@ -52,14 +52,6 @@ cargo install --git https://github.com/knurling-rs/probe-run --branch main --fea | |||
| 52 | cargo run --bin rtc_async | 52 | cargo run --bin rtc_async |
| 53 | ``` | 53 | ``` |
| 54 | 54 | ||
| 55 | ## Using on your project | ||
| 56 | |||
| 57 | `embassy` requires git version of a few dependencies. | ||
| 58 | |||
| 59 | When using `embassy` in your own project, make sure you copy over the `[patch.crates-io]` section from root `Cargo.toml`. | ||
| 60 | |||
| 61 | This will no longer needed after the first crates.io release. | ||
| 62 | |||
| 63 | ## Minimum supported Rust version (MSRV) | 55 | ## Minimum supported Rust version (MSRV) |
| 64 | 56 | ||
| 65 | `rustc 1.48.0-nightly (1fd5b9d51 2020-09-20)` | 57 | `rustc 1.48.0-nightly (1fd5b9d51 2020-09-20)` |
diff --git a/anyfmt/Cargo.toml b/anyfmt/Cargo.toml deleted file mode 100644 index 3ee7c167b..000000000 --- a/anyfmt/Cargo.toml +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | [package] | ||
| 2 | name = "anyfmt" | ||
| 3 | version = "0.1.0" | ||
| 4 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 5 | edition = "2018" | ||
| 6 | |||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | defmt = { version = "0.1.0", optional = true } | ||
| 10 | log = { version = "0.4.11", optional = true } | ||
diff --git a/anyfmt/src/lib.rs b/anyfmt/src/lib.rs deleted file mode 100644 index 3286cc27b..000000000 --- a/anyfmt/src/lib.rs +++ /dev/null | |||
| @@ -1,149 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | |||
| 3 | pub 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] | ||
| 12 | macro_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] | ||
| 22 | macro_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] | ||
| 32 | macro_rules! log { | ||
| 33 | ($level:ident, $($arg:expr),*) => {{}}; | ||
| 34 | } | ||
| 35 | |||
| 36 | #[macro_export] | ||
| 37 | macro_rules! trace { | ||
| 38 | ($($arg:expr),*) => (log!(trace, $($arg),*)); | ||
| 39 | } | ||
| 40 | |||
| 41 | #[macro_export] | ||
| 42 | macro_rules! debug { | ||
| 43 | ($($arg:expr),*) => ($crate::log!(debug, $($arg),*)); | ||
| 44 | } | ||
| 45 | |||
| 46 | #[macro_export] | ||
| 47 | macro_rules! info { | ||
| 48 | ($($arg:expr),*) => ($crate::log!(info, $($arg),*)); | ||
| 49 | } | ||
| 50 | |||
| 51 | #[macro_export] | ||
| 52 | macro_rules! warn { | ||
| 53 | ($($arg:expr),*) => ($crate::log!(warn, $($arg),*)); | ||
| 54 | } | ||
| 55 | |||
| 56 | #[macro_export] | ||
| 57 | macro_rules! error { | ||
| 58 | ($($arg:expr),*) => ($crate::log!(error, $($arg),*)); | ||
| 59 | } | ||
| 60 | |||
| 61 | #[macro_export] | ||
| 62 | macro_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] | ||
| 75 | macro_rules! intern { | ||
| 76 | ($arg:expr) => { | ||
| 77 | $crate::export::defmt::intern!($arg) | ||
| 78 | }; | ||
| 79 | } | ||
| 80 | |||
| 81 | #[cfg(not(feature = "defmt"))] | ||
| 82 | #[macro_export] | ||
| 83 | macro_rules! intern { | ||
| 84 | ($arg:expr) => { | ||
| 85 | $arg | ||
| 86 | }; | ||
| 87 | } | ||
| 88 | |||
| 89 | #[macro_export] | ||
| 90 | macro_rules! unwrap { | ||
| 91 | ($arg:expr) => { | ||
| 92 | expect!($arg, "Unwrap failed") | ||
| 93 | }; | ||
| 94 | } | ||
| 95 | |||
| 96 | #[macro_export] | ||
| 97 | macro_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] | ||
| 108 | macro_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))] | ||
| 123 | pub struct NoneError; | ||
| 124 | |||
| 125 | pub trait Try { | ||
| 126 | type Ok; | ||
| 127 | type Error; | ||
| 128 | fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
| 129 | } | ||
| 130 | |||
| 131 | impl<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 | |||
| 141 | impl<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 6cf23aa79..d1538908d 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -21,13 +21,10 @@ defmt-error = [ ] | |||
| 21 | [dependencies] | 21 | [dependencies] |
| 22 | embassy = { version = "0.1.0", path = "../embassy" } | 22 | embassy = { version = "0.1.0", path = "../embassy" } |
| 23 | 23 | ||
| 24 | anyfmt = { version = "0.1.0", path = "../anyfmt" } | 24 | defmt = { version = "0.1.2" } |
| 25 | defmt = { version = "0.1.0", optional = true } | 25 | cortex-m-rt = "0.6.13" |
| 26 | 26 | cortex-m = { version = "0.6.4" } | |
| 27 | cortex-m-rt = "0.6.12" | ||
| 28 | cortex-m = { version = "0.6.3" } | ||
| 29 | embedded-hal = { version = "0.2.4" } | 27 | embedded-hal = { version = "0.2.4" } |
| 30 | bare-metal = { version = "0.2.0", features = ["const-fn"] } | ||
| 31 | 28 | ||
| 32 | nrf52810-pac = { version = "0.9.0", optional = true } | 29 | nrf52810-pac = { version = "0.9.0", optional = true } |
| 33 | nrf52811-pac = { version = "0.9.1", optional = true } | 30 | nrf52811-pac = { version = "0.9.1", optional = true } |
| @@ -35,8 +32,8 @@ nrf52832-pac = { version = "0.9.0", optional = true } | |||
| 35 | nrf52833-pac = { version = "0.9.0", optional = true } | 32 | nrf52833-pac = { version = "0.9.0", optional = true } |
| 36 | nrf52840-pac = { version = "0.9.0", optional = true } | 33 | nrf52840-pac = { version = "0.9.0", optional = true } |
| 37 | 34 | ||
| 38 | nrf52810-hal = { version = "0.11.0", optional = true } | 35 | nrf52810-hal = { version = "0.12.0", optional = true } |
| 39 | #nrf52811-hal = { version = "0.11.0", optional = true } # doesn't exist yet | 36 | #nrf52811-hal = { version = "0.12.0", optional = true } # doesn't exist yet |
| 40 | nrf52832-hal = { version = "0.11.0", optional = true } | 37 | nrf52832-hal = { version = "0.12.0", optional = true } |
| 41 | nrf52833-hal = { version = "0.11.0", optional = true } | 38 | nrf52833-hal = { version = "0.12.0", optional = true } |
| 42 | nrf52840-hal = { version = "0.11.0", optional = true } | 39 | nrf52840-hal = { version = "0.12.0", optional = true } |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 9626d3299..bb15cca66 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use anyfmt::{panic, *}; | ||
| 2 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 3 | use core::future::Future; | 2 | use core::future::Future; |
| 4 | use core::ptr; | 3 | use core::ptr; |
| 5 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 5 | use defmt::{panic, *}; | ||
| 6 | use embassy::util::Signal; | 6 | use embassy::util::Signal; |
| 7 | 7 | ||
| 8 | use crate::hal::gpio::{Input, Level, Output, Pin, Port}; | 8 | use crate::hal::gpio::{Input, Level, Output, Pin, Port}; |
| @@ -51,8 +51,7 @@ pub enum OutputChannelPolarity { | |||
| 51 | Toggle, | 51 | Toggle, |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 54 | #[derive(Debug, Copy, Clone, Eq, PartialEq, defmt::Format)] |
| 55 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 56 | pub enum NewChannelError { | 55 | pub enum NewChannelError { |
| 57 | NoFreeChannels, | 56 | NoFreeChannels, |
| 58 | } | 57 | } |
diff --git a/embassy-nrf/src/interrupt.rs b/embassy-nrf/src/interrupt.rs index 8918b13ee..384426ea2 100644 --- a/embassy-nrf/src/interrupt.rs +++ b/embassy-nrf/src/interrupt.rs | |||
| @@ -10,10 +10,9 @@ use crate::pac::{NVIC, NVIC_PRIO_BITS}; | |||
| 10 | // Re-exports | 10 | // Re-exports |
| 11 | pub use crate::pac::Interrupt; | 11 | pub use crate::pac::Interrupt; |
| 12 | pub use crate::pac::Interrupt::*; // needed for cortex-m-rt #[interrupt] | 12 | pub use crate::pac::Interrupt::*; // needed for cortex-m-rt #[interrupt] |
| 13 | pub use bare_metal::{CriticalSection, Mutex}; | 13 | pub use cortex_m::interrupt::{CriticalSection, Mutex}; |
| 14 | 14 | ||
| 15 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | 15 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, defmt::Format)] |
| 16 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 17 | #[repr(u8)] | 16 | #[repr(u8)] |
| 18 | pub enum Priority { | 17 | pub enum Priority { |
| 19 | Level0 = 0, | 18 | Level0 = 0, |
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 367a1d2d3..75cbe7ddc 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use defmt::{assert, assert_eq, panic, *}; | ||
| 2 | 3 | ||
| 3 | use crate::hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull}; | 4 | use crate::hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull}; |
| 4 | use crate::pac::{Interrupt, QSPI}; | 5 | use crate::pac::{Interrupt, QSPI}; |
| @@ -32,12 +33,18 @@ pub struct Pins { | |||
| 32 | pub io3: Option<GpioPin<Output<PushPull>>>, | 33 | pub io3: Option<GpioPin<Output<PushPull>>>, |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 36 | pub struct DeepPowerDownConfig { | ||
| 37 | pub enter_time: u16, | ||
| 38 | pub exit_time: u16, | ||
| 39 | } | ||
| 40 | |||
| 35 | pub struct Config { | 41 | pub struct Config { |
| 36 | pub pins: Pins, | 42 | pub pins: Pins, |
| 37 | pub xip_offset: u32, | 43 | pub xip_offset: u32, |
| 38 | pub read_opcode: ReadOpcode, | 44 | pub read_opcode: ReadOpcode, |
| 39 | pub write_opcode: WriteOpcode, | 45 | pub write_opcode: WriteOpcode, |
| 40 | pub write_page_size: WritePageSize, | 46 | pub write_page_size: WritePageSize, |
| 47 | pub deep_power_down: Option<DeepPowerDownConfig>, | ||
| 41 | } | 48 | } |
| 42 | 49 | ||
| 43 | pub struct Qspi { | 50 | pub struct Qspi { |
| @@ -96,15 +103,27 @@ impl Qspi { | |||
| 96 | } | 103 | } |
| 97 | }); | 104 | }); |
| 98 | 105 | ||
| 99 | qspi.ifconfig0.write(|w| { | 106 | qspi.ifconfig0.write(|mut w| { |
| 100 | let w = w.addrmode().variant(AddressMode::_24BIT); | 107 | w = w.addrmode().variant(AddressMode::_24BIT); |
| 101 | let w = w.dpmenable().disable(); | 108 | if config.deep_power_down.is_some() { |
| 102 | let w = w.ppsize().variant(config.write_page_size); | 109 | w = w.dpmenable().enable(); |
| 103 | let w = w.readoc().variant(config.read_opcode); | 110 | } else { |
| 104 | let w = w.writeoc().variant(config.write_opcode); | 111 | w = w.dpmenable().disable(); |
| 112 | } | ||
| 113 | w = w.ppsize().variant(config.write_page_size); | ||
| 114 | w = w.readoc().variant(config.read_opcode); | ||
| 115 | w = w.writeoc().variant(config.write_opcode); | ||
| 105 | w | 116 | w |
| 106 | }); | 117 | }); |
| 107 | 118 | ||
| 119 | if let Some(dpd) = &config.deep_power_down { | ||
| 120 | qspi.dpmdur.write(|mut w| unsafe { | ||
| 121 | w = w.enter().bits(dpd.enter_time); | ||
| 122 | w = w.exit().bits(dpd.exit_time); | ||
| 123 | w | ||
| 124 | }) | ||
| 125 | } | ||
| 126 | |||
| 108 | qspi.ifconfig1.write(|w| { | 127 | qspi.ifconfig1.write(|w| { |
| 109 | let w = unsafe { w.sckdelay().bits(80) }; | 128 | let w = unsafe { w.sckdelay().bits(80) }; |
| 110 | let w = w.dpmen().exit(); | 129 | let w = w.dpmen().exit(); |
| @@ -125,13 +144,28 @@ impl Qspi { | |||
| 125 | qspi.events_ready.reset(); | 144 | qspi.events_ready.reset(); |
| 126 | 145 | ||
| 127 | // Enable READY interrupt | 146 | // Enable READY interrupt |
| 147 | SIGNAL.reset(); | ||
| 128 | qspi.intenset.write(|w| w.ready().set()); | 148 | qspi.intenset.write(|w| w.ready().set()); |
| 129 | interrupt::set_priority(Interrupt::QSPI, interrupt::Priority::Level7); | 149 | interrupt::set_priority(Interrupt::QSPI, interrupt::Priority::Level7); |
| 150 | interrupt::unpend(Interrupt::QSPI); | ||
| 130 | interrupt::enable(Interrupt::QSPI); | 151 | interrupt::enable(Interrupt::QSPI); |
| 131 | 152 | ||
| 132 | Self { inner: qspi } | 153 | Self { inner: qspi } |
| 133 | } | 154 | } |
| 134 | 155 | ||
| 156 | pub fn sleep(&mut self) { | ||
| 157 | info!("flash: sleeping"); | ||
| 158 | info!("flash: state = {:?}", self.inner.status.read().bits()); | ||
| 159 | self.inner.ifconfig1.modify(|r, w| w.dpmen().enter()); | ||
| 160 | info!("flash: state = {:?}", self.inner.status.read().bits()); | ||
| 161 | cortex_m::asm::delay(1000000); | ||
| 162 | info!("flash: state = {:?}", self.inner.status.read().bits()); | ||
| 163 | |||
| 164 | self.inner | ||
| 165 | .tasks_deactivate | ||
| 166 | .write(|w| w.tasks_deactivate().set_bit()); | ||
| 167 | } | ||
| 168 | |||
| 135 | pub fn custom_instruction<'a>( | 169 | pub fn custom_instruction<'a>( |
| 136 | &'a mut self, | 170 | &'a mut self, |
| 137 | opcode: u8, | 171 | opcode: u8, |
| @@ -318,6 +352,7 @@ unsafe fn QSPI() { | |||
| 318 | let p = crate::pac::Peripherals::steal().QSPI; | 352 | let p = crate::pac::Peripherals::steal().QSPI; |
| 319 | if p.events_ready.read().events_ready().bit_is_set() { | 353 | if p.events_ready.read().events_ready().bit_is_set() { |
| 320 | p.events_ready.reset(); | 354 | p.events_ready.reset(); |
| 355 | info!("qspi ready"); | ||
| 321 | SIGNAL.signal(()); | 356 | SIGNAL.signal(()); |
| 322 | } | 357 | } |
| 323 | } | 358 | } |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 530895073..0f2030c98 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -28,7 +28,7 @@ pub use uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | |||
| 28 | use embassy::io::{AsyncBufRead, AsyncWrite, Result}; | 28 | use embassy::io::{AsyncBufRead, AsyncWrite, Result}; |
| 29 | use embassy::util::WakerStore; | 29 | use embassy::util::WakerStore; |
| 30 | 30 | ||
| 31 | use anyfmt::{assert, panic, *}; | 31 | use defmt::{assert, panic, todo, *}; |
| 32 | 32 | ||
| 33 | //use crate::trace; | 33 | //use crate::trace; |
| 34 | 34 | ||
diff --git a/embassy/Cargo.toml b/embassy/Cargo.toml index 6c9309763..832b06fd7 100644 --- a/embassy/Cargo.toml +++ b/embassy/Cargo.toml | |||
| @@ -13,12 +13,11 @@ defmt-warn = [] | |||
| 13 | defmt-error = [] | 13 | defmt-error = [] |
| 14 | 14 | ||
| 15 | [dependencies] | 15 | [dependencies] |
| 16 | anyfmt = { version = "0.1.0", path = "../anyfmt" } | 16 | defmt = { version = "0.1.0" } |
| 17 | defmt = { version = "0.1.0", optional = true } | ||
| 18 | 17 | ||
| 19 | cortex-m = "0.6.3" | 18 | cortex-m = "0.6.4" |
| 20 | futures = { version = "0.3.5", default-features = false } | 19 | futures = { version = "0.3.5", default-features = false } |
| 21 | pin-project = { version = "0.4.23", default-features = false } | 20 | pin-project = { version = "1.0.2", default-features = false } |
| 22 | futures-intrusive = { version = "0.3.1", default-features = false } | 21 | futures-intrusive = { version = "0.3.1", default-features = false } |
| 23 | embassy-macros = { version = "0.1.0", path = "../embassy-macros"} | 22 | embassy-macros = { version = "0.1.0", path = "../embassy-macros"} |
| 24 | 23 | ||
diff --git a/embassy/src/executor/executor.rs b/embassy/src/executor/executor.rs index 4d73cf9f0..ff3a8517c 100644 --- a/embassy/src/executor/executor.rs +++ b/embassy/src/executor/executor.rs | |||
| @@ -63,8 +63,7 @@ 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)] | 66 | #[derive(Copy, Clone, Debug, defmt::Format)] |
| 67 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 68 | pub enum SpawnError { | 67 | pub enum SpawnError { |
| 69 | Busy, | 68 | Busy, |
| 70 | } | 69 | } |
diff --git a/embassy/src/flash.rs b/embassy/src/flash.rs index ca9fb5952..5d62e3b64 100644 --- a/embassy/src/flash.rs +++ b/embassy/src/flash.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | 2 | ||
| 3 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] | 3 | #[derive(Copy, Clone, Debug, Eq, PartialEq, defmt::Format)] |
| 4 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 5 | pub enum Error { | 4 | pub enum Error { |
| 6 | Failed, | 5 | Failed, |
| 7 | AddressMisaligned, | 6 | AddressMisaligned, |
diff --git a/embassy/src/io/error.rs b/embassy/src/io/error.rs index 8bad0cdb1..8bbdae7f8 100644 --- a/embassy/src/io/error.rs +++ b/embassy/src/io/error.rs | |||
| @@ -2,8 +2,7 @@ | |||
| 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(Debug, Clone, Copy, PartialEq, Eq)] | 5 | #[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)] |
| 6 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 7 | pub enum Error { | 6 | pub enum Error { |
| 8 | /// An entity was not found, often a file. | 7 | /// An entity was not found, often a file. |
| 9 | NotFound, | 8 | NotFound, |
diff --git a/embassy/src/rand.rs b/embassy/src/rand.rs index dbabb6f2b..3db164cf1 100644 --- a/embassy/src/rand.rs +++ b/embassy/src/rand.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use anyfmt::*; | 1 | use defmt::*; |
| 2 | 2 | ||
| 3 | pub trait Rand { | 3 | pub trait Rand { |
| 4 | fn rand(&self, buf: &mut [u8]); | 4 | fn rand(&self, buf: &mut [u8]); |
| @@ -11,5 +11,5 @@ pub unsafe fn set_rand(rand: &'static dyn Rand) { | |||
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | pub fn rand(buf: &mut [u8]) { | 13 | pub fn rand(buf: &mut [u8]) { |
| 14 | unsafe { expect!(RAND, "No rand set").rand(buf) } | 14 | unsafe { unwrap!(RAND, "No rand set").rand(buf) } |
| 15 | } | 15 | } |
diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs index 8135961ea..715d4155f 100644 --- a/embassy/src/time/duration.rs +++ b/embassy/src/time/duration.rs | |||
| @@ -3,8 +3,7 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; | |||
| 3 | 3 | ||
| 4 | use super::TICKS_PER_SECOND; | 4 | use super::TICKS_PER_SECOND; |
| 5 | 5 | ||
| 6 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] | 6 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, defmt::Format)] |
| 7 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 8 | pub struct Duration { | 7 | pub struct Duration { |
| 9 | pub(crate) ticks: u64, | 8 | pub(crate) ticks: u64, |
| 10 | } | 9 | } |
diff --git a/embassy/src/time/instant.rs b/embassy/src/time/instant.rs index 75098081f..a7f268e1a 100644 --- a/embassy/src/time/instant.rs +++ b/embassy/src/time/instant.rs | |||
| @@ -5,8 +5,7 @@ use core::ops::{Add, AddAssign, Sub, SubAssign}; | |||
| 5 | use super::TICKS_PER_SECOND; | 5 | use super::TICKS_PER_SECOND; |
| 6 | use super::{now, Duration}; | 6 | use super::{now, Duration}; |
| 7 | 7 | ||
| 8 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] | 8 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, defmt::Format)] |
| 9 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 10 | pub struct Instant { | 9 | pub struct Instant { |
| 11 | ticks: u64, | 10 | ticks: u64, |
| 12 | } | 11 | } |
diff --git a/embassy/src/time/mod.rs b/embassy/src/time/mod.rs index a3792e3c8..0d97a789e 100644 --- a/embassy/src/time/mod.rs +++ b/embassy/src/time/mod.rs | |||
| @@ -8,7 +8,7 @@ pub use instant::Instant; | |||
| 8 | pub use timer::Timer; | 8 | pub use timer::Timer; |
| 9 | pub use traits::*; | 9 | pub use traits::*; |
| 10 | 10 | ||
| 11 | use anyfmt::*; | 11 | use defmt::*; |
| 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. |
| 14 | pub const TICKS_PER_SECOND: u64 = 32768; | 14 | pub const TICKS_PER_SECOND: u64 = 32768; |
| @@ -20,5 +20,5 @@ pub unsafe fn set_clock(clock: &'static dyn Clock) { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub(crate) fn now() -> u64 { | 22 | pub(crate) fn now() -> u64 { |
| 23 | unsafe { expect!(CLOCK, "No clock set").now() } | 23 | unsafe { unwrap!(CLOCK, "No clock set").now() } |
| 24 | } | 24 | } |
diff --git a/embassy/src/util/drop_bomb.rs b/embassy/src/util/drop_bomb.rs index 0ef051cf4..d33591fc2 100644 --- a/embassy/src/util/drop_bomb.rs +++ b/embassy/src/util/drop_bomb.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use anyfmt::panic; | ||
| 2 | use core::mem; | 1 | use core::mem; |
| 2 | use defmt::panic; | ||
| 3 | 3 | ||
| 4 | pub struct DropBomb { | 4 | pub struct DropBomb { |
| 5 | _private: (), | 5 | _private: (), |
diff --git a/embassy/src/util/portal.rs b/embassy/src/util/portal.rs index 8f5d812f4..6eecf52cd 100644 --- a/embassy/src/util/portal.rs +++ b/embassy/src/util/portal.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use anyfmt::panic; | ||
| 2 | use core::cell::UnsafeCell; | 1 | use core::cell::UnsafeCell; |
| 3 | use core::future::Future; | 2 | use core::future::Future; |
| 4 | use core::mem; | 3 | use core::mem; |
| 5 | use core::mem::MaybeUninit; | 4 | use core::mem::MaybeUninit; |
| 5 | use defmt::panic; | ||
| 6 | 6 | ||
| 7 | use crate::util::*; | 7 | use crate::util::*; |
| 8 | 8 | ||
diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index e2cd3a80f..45205368d 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use anyfmt::panic; | ||
| 2 | use core::cell::UnsafeCell; | 1 | use core::cell::UnsafeCell; |
| 3 | use core::future::Future; | 2 | use core::future::Future; |
| 4 | use core::mem; | 3 | use core::mem; |
| 5 | use core::task::{Context, Poll, Waker}; | 4 | use core::task::{Context, Poll, Waker}; |
| 5 | use defmt::panic; | ||
| 6 | 6 | ||
| 7 | pub struct Signal<T> { | 7 | pub struct Signal<T> { |
| 8 | state: UnsafeCell<State<T>>, | 8 | state: UnsafeCell<State<T>>, |
diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 719f73269..71d0bbd77 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml | |||
| @@ -17,17 +17,16 @@ defmt-error = [] | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | [dependencies] | 19 | [dependencies] |
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt"] } | 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt-trace"] } |
| 21 | embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt", "defmt-trace", "52840"] } | 21 | embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt-trace", "52840"] } |
| 22 | anyfmt = { version = "0.1.0", path = "../anyfmt", features = ["defmt"] } | ||
| 23 | 22 | ||
| 24 | defmt = "0.1.0" | 23 | defmt = "0.1.2" |
| 25 | defmt-rtt = "0.1.0" | 24 | defmt-rtt = "0.1.0" |
| 26 | 25 | ||
| 27 | cortex-m = { version = "0.6.3" } | 26 | cortex-m = { version = "0.6.3" } |
| 28 | cortex-m-rt = "0.6.12" | 27 | cortex-m-rt = "0.6.12" |
| 29 | embedded-hal = { version = "0.2.4" } | 28 | embedded-hal = { version = "0.2.4" } |
| 30 | panic-probe = "0.1.0" | 29 | panic-probe = "0.1.0" |
| 31 | nrf52840-hal = { version = "0.11.0" } | 30 | nrf52840-hal = { version = "0.12.0" } |
| 32 | futures = { version = "0.3.7", default-features = false, features = ["async-await"] } | 31 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } |
| 33 | cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"} | 32 | cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"} |
diff --git a/examples/src/bin/qspi.rs b/examples/src/bin/qspi.rs index a7f668ca7..644018e2d 100644 --- a/examples/src/bin/qspi.rs +++ b/examples/src/bin/qspi.rs | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use example_common::*; | 7 | use example_common::*; |
| 8 | 8 | ||
| 9 | use anyfmt::panic; | ||
| 10 | use cortex_m_rt::entry; | 9 | use cortex_m_rt::entry; |
| 10 | use defmt::{assert_eq, panic, *}; | ||
| 11 | use nrf52840_hal::gpio; | 11 | use nrf52840_hal::gpio; |
| 12 | 12 | ||
| 13 | use embassy::executor::{task, Executor}; | 13 | use embassy::executor::{task, Executor}; |
| @@ -65,6 +65,7 @@ async fn run() { | |||
| 65 | write_opcode: qspi::WriteOpcode::PP4IO, | 65 | write_opcode: qspi::WriteOpcode::PP4IO, |
| 66 | xip_offset: 0, | 66 | xip_offset: 0, |
| 67 | write_page_size: qspi::WritePageSize::_256BYTES, | 67 | write_page_size: qspi::WritePageSize::_256BYTES, |
| 68 | deep_power_down: None, | ||
| 68 | }; | 69 | }; |
| 69 | 70 | ||
| 70 | let mut q = qspi::Qspi::new(p.QSPI, config); | 71 | let mut q = qspi::Qspi::new(p.QSPI, config); |
diff --git a/examples/src/example_common.rs b/examples/src/example_common.rs index 1a12fa69a..60bb02082 100644 --- a/examples/src/example_common.rs +++ b/examples/src/example_common.rs | |||
| @@ -4,7 +4,7 @@ use defmt_rtt as _; // global logger | |||
| 4 | use nrf52840_hal as _; | 4 | use nrf52840_hal as _; |
| 5 | use panic_probe as _; | 5 | use panic_probe as _; |
| 6 | 6 | ||
| 7 | pub use anyfmt::*; | 7 | pub use defmt::*; |
| 8 | 8 | ||
| 9 | use core::sync::atomic::{AtomicUsize, Ordering}; | 9 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 10 | 10 | ||
diff --git a/test-build.sh b/test-build.sh index 34a56782b..66128ddc2 100755 --- a/test-build.sh +++ b/test-build.sh | |||
| @@ -7,15 +7,11 @@ set -euxo pipefail | |||
| 7 | 7 | ||
| 8 | # embassy | 8 | # embassy |
| 9 | (cd embassy; cargo build --target thumbv7em-none-eabihf) | 9 | (cd embassy; cargo build --target thumbv7em-none-eabihf) |
| 10 | (cd embassy; cargo build --target thumbv7em-none-eabihf --features defmt,anyfmt/defmt) | ||
| 11 | (cd embassy; cargo build --target thumbv7em-none-eabihf --features anyfmt/log) | ||
| 12 | 10 | ||
| 13 | # embassy-nrf | 11 | # embassy-nrf |
| 14 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52810) | 12 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabi --features 52810) |
| 15 | #(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52811) # nrf52811-hal doesn't exist yet | 13 | #(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) | 14 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52832) |
| 17 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52833) | 15 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52833) |
| 18 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840) | 16 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840) |
| 19 | 17 | ||
| 20 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840,anyfmt/log) | ||
| 21 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840,defmt,embassy/defmt,anyfmt/defmt) | ||
