diff options
| author | Dario Nieuwenhuis <[email protected]> | 2020-12-01 17:46:56 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2020-12-01 17:46:56 +0100 |
| commit | 6f76c0ebccf1d3d7b8712eaa145f6033b277a6ae (patch) | |
| tree | b85002c833e5100080050c259754ad7b2945ef60 | |
| parent | 78135a81d96a8bb74207b3f73c9f261aa4561a18 (diff) | |
Add support for log+defmt again, but better.
| -rw-r--r-- | embassy-nrf/Cargo.toml | 3 | ||||
| -rw-r--r-- | embassy-nrf/src/fmt.rs | 110 | ||||
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 5 | ||||
| -rw-r--r-- | embassy-nrf/src/interrupt.rs | 3 | ||||
| -rw-r--r-- | embassy-nrf/src/lib.rs | 3 | ||||
| -rw-r--r-- | embassy-nrf/src/qspi.rs | 2 | ||||
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 2 | ||||
| -rw-r--r-- | embassy/Cargo.toml | 3 | ||||
| -rw-r--r-- | embassy/src/executor/executor.rs | 3 | ||||
| -rw-r--r-- | embassy/src/flash.rs | 3 | ||||
| -rw-r--r-- | embassy/src/fmt.rs | 110 | ||||
| -rw-r--r-- | embassy/src/io/error.rs | 3 | ||||
| -rw-r--r-- | embassy/src/lib.rs | 3 | ||||
| -rw-r--r-- | embassy/src/rand.rs | 2 | ||||
| -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 | 2 | ||||
| -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 | 8 | ||||
| -rwxr-xr-x | test-build.sh | 5 |
22 files changed, 261 insertions, 21 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index d1538908d..7fe285c62 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -21,7 +21,8 @@ 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 | defmt = { version = "0.1.2" } | 24 | defmt = { version = "0.1.3", optional = true } |
| 25 | log = { version = "0.4.11", optional = true } | ||
| 25 | cortex-m-rt = "0.6.13" | 26 | cortex-m-rt = "0.6.13" |
| 26 | cortex-m = { version = "0.6.4" } | 27 | cortex-m = { version = "0.6.4" } |
| 27 | embedded-hal = { version = "0.2.4" } | 28 | embedded-hal = { version = "0.2.4" } |
diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs new file mode 100644 index 000000000..93dda67d8 --- /dev/null +++ b/embassy-nrf/src/fmt.rs | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | #![macro_use] | ||
| 2 | |||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | ||
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | ||
| 5 | |||
| 6 | pub use fmt::*; | ||
| 7 | |||
| 8 | #[cfg(feature = "defmt")] | ||
| 9 | mod fmt { | ||
| 10 | pub use defmt::{ | ||
| 11 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | ||
| 12 | info, panic, todo, trace, unreachable, unwrap, warn, | ||
| 13 | }; | ||
| 14 | } | ||
| 15 | |||
| 16 | #[cfg(feature = "log")] | ||
| 17 | mod fmt { | ||
| 18 | pub use core::{ | ||
| 19 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | ||
| 20 | unreachable, | ||
| 21 | }; | ||
| 22 | pub use log::{debug, error, info, trace, warn}; | ||
| 23 | } | ||
| 24 | |||
| 25 | #[cfg(not(any(feature = "defmt", feature = "log")))] | ||
| 26 | mod fmt { | ||
| 27 | #![macro_use] | ||
| 28 | |||
| 29 | pub use core::{ | ||
| 30 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | ||
| 31 | unreachable, | ||
| 32 | }; | ||
| 33 | |||
| 34 | #[macro_export] | ||
| 35 | macro_rules! trace { | ||
| 36 | ($($msg:expr),*) => { | ||
| 37 | () | ||
| 38 | }; | ||
| 39 | } | ||
| 40 | |||
| 41 | #[macro_export] | ||
| 42 | macro_rules! debug { | ||
| 43 | ($($msg:expr),*) => { | ||
| 44 | () | ||
| 45 | }; | ||
| 46 | } | ||
| 47 | |||
| 48 | #[macro_export] | ||
| 49 | macro_rules! info { | ||
| 50 | ($($msg:expr),*) => { | ||
| 51 | () | ||
| 52 | }; | ||
| 53 | } | ||
| 54 | |||
| 55 | #[macro_export] | ||
| 56 | macro_rules! warn { | ||
| 57 | ($($msg:expr),*) => { | ||
| 58 | () | ||
| 59 | }; | ||
| 60 | } | ||
| 61 | |||
| 62 | #[macro_export] | ||
| 63 | macro_rules! error { | ||
| 64 | ($($msg:expr),*) => { | ||
| 65 | () | ||
| 66 | }; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | #[cfg(not(feature = "defmt"))] | ||
| 71 | #[macro_export] | ||
| 72 | macro_rules! unwrap { | ||
| 73 | ($arg:expr$(,$msg:expr)*) => { | ||
| 74 | match $crate::fmt::Try::into_result($arg) { | ||
| 75 | ::core::result::Result::Ok(t) => t, | ||
| 76 | ::core::result::Result::Err(e) => { | ||
| 77 | panic!($($msg,)*); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| 84 | pub struct NoneError; | ||
| 85 | |||
| 86 | pub trait Try { | ||
| 87 | type Ok; | ||
| 88 | type Error; | ||
| 89 | fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
| 90 | } | ||
| 91 | |||
| 92 | impl<T> Try for Option<T> { | ||
| 93 | type Ok = T; | ||
| 94 | type Error = NoneError; | ||
| 95 | |||
| 96 | #[inline] | ||
| 97 | fn into_result(self) -> Result<T, NoneError> { | ||
| 98 | self.ok_or(NoneError) | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | impl<T, E> Try for Result<T, E> { | ||
| 103 | type Ok = T; | ||
| 104 | type Error = E; | ||
| 105 | |||
| 106 | #[inline] | ||
| 107 | fn into_result(self) -> Self { | ||
| 108 | self | ||
| 109 | } | ||
| 110 | } | ||
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index bb15cca66..069e9140b 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use crate::fmt::{panic, *}; | ||
| 1 | use core::cell::Cell; | 2 | use core::cell::Cell; |
| 2 | use core::future::Future; | 3 | use core::future::Future; |
| 3 | use core::ptr; | 4 | use core::ptr; |
| 4 | use core::task::{Context, Poll}; | 5 | 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,7 +51,8 @@ pub enum OutputChannelPolarity { | |||
| 51 | Toggle, | 51 | Toggle, |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | #[derive(Debug, Copy, Clone, Eq, PartialEq, defmt::Format)] | 54 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 55 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 55 | pub enum NewChannelError { | 56 | pub enum NewChannelError { |
| 56 | NoFreeChannels, | 57 | NoFreeChannels, |
| 57 | } | 58 | } |
diff --git a/embassy-nrf/src/interrupt.rs b/embassy-nrf/src/interrupt.rs index 384426ea2..17fc9ab34 100644 --- a/embassy-nrf/src/interrupt.rs +++ b/embassy-nrf/src/interrupt.rs | |||
| @@ -12,7 +12,8 @@ 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 cortex_m::interrupt::{CriticalSection, Mutex}; | 13 | pub use cortex_m::interrupt::{CriticalSection, Mutex}; |
| 14 | 14 | ||
| 15 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, defmt::Format)] | 15 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 16 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 16 | #[repr(u8)] | 17 | #[repr(u8)] |
| 17 | pub enum Priority { | 18 | pub enum Priority { |
| 18 | Level0 = 0, | 19 | Level0 = 0, |
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 8efd6c568..7b3368d66 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -48,6 +48,9 @@ pub use nrf52833_hal as hal; | |||
| 48 | #[cfg(feature = "52840")] | 48 | #[cfg(feature = "52840")] |
| 49 | pub use nrf52840_hal as hal; | 49 | pub use nrf52840_hal as hal; |
| 50 | 50 | ||
| 51 | // This mod MUST go first, so that the others see its macros. | ||
| 52 | pub(crate) mod fmt; | ||
| 53 | |||
| 51 | pub mod gpiote; | 54 | pub mod gpiote; |
| 52 | pub mod interrupt; | 55 | pub mod interrupt; |
| 53 | #[cfg(feature = "52840")] | 56 | #[cfg(feature = "52840")] |
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 75cbe7ddc..79fc7029c 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::fmt::{assert, assert_eq, panic, *}; | ||
| 1 | use core::future::Future; | 2 | use core::future::Future; |
| 2 | use defmt::{assert, assert_eq, panic, *}; | ||
| 3 | 3 | ||
| 4 | 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}; |
| 5 | use crate::pac::{Interrupt, QSPI}; | 5 | use crate::pac::{Interrupt, QSPI}; |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 0f2030c98..3a33e7597 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 defmt::{assert, panic, todo, *}; | 31 | use crate::fmt::{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 832b06fd7..0e4c801bb 100644 --- a/embassy/Cargo.toml +++ b/embassy/Cargo.toml | |||
| @@ -13,7 +13,8 @@ defmt-warn = [] | |||
| 13 | defmt-error = [] | 13 | defmt-error = [] |
| 14 | 14 | ||
| 15 | [dependencies] | 15 | [dependencies] |
| 16 | defmt = { version = "0.1.0" } | 16 | defmt = { version = "0.1.3", optional = true } |
| 17 | log = { version = "0.4.11", optional = true } | ||
| 17 | 18 | ||
| 18 | cortex-m = "0.6.4" | 19 | cortex-m = "0.6.4" |
| 19 | futures = { version = "0.3.5", default-features = false } | 20 | futures = { version = "0.3.5", default-features = false } |
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))] | ||
| 67 | pub enum SpawnError { | 68 | pub enum SpawnError { |
| 68 | Busy, | 69 | Busy, |
| 69 | } | 70 | } |
diff --git a/embassy/src/flash.rs b/embassy/src/flash.rs index 5d62e3b64..ca9fb5952 100644 --- a/embassy/src/flash.rs +++ b/embassy/src/flash.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | 2 | ||
| 3 | #[derive(Copy, Clone, Debug, Eq, PartialEq, defmt::Format)] | 3 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
| 4 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 4 | pub enum Error { | 5 | pub enum Error { |
| 5 | Failed, | 6 | Failed, |
| 6 | AddressMisaligned, | 7 | AddressMisaligned, |
diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs new file mode 100644 index 000000000..93dda67d8 --- /dev/null +++ b/embassy/src/fmt.rs | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | #![macro_use] | ||
| 2 | |||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | ||
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | ||
| 5 | |||
| 6 | pub use fmt::*; | ||
| 7 | |||
| 8 | #[cfg(feature = "defmt")] | ||
| 9 | mod fmt { | ||
| 10 | pub use defmt::{ | ||
| 11 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | ||
| 12 | info, panic, todo, trace, unreachable, unwrap, warn, | ||
| 13 | }; | ||
| 14 | } | ||
| 15 | |||
| 16 | #[cfg(feature = "log")] | ||
| 17 | mod fmt { | ||
| 18 | pub use core::{ | ||
| 19 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | ||
| 20 | unreachable, | ||
| 21 | }; | ||
| 22 | pub use log::{debug, error, info, trace, warn}; | ||
| 23 | } | ||
| 24 | |||
| 25 | #[cfg(not(any(feature = "defmt", feature = "log")))] | ||
| 26 | mod fmt { | ||
| 27 | #![macro_use] | ||
| 28 | |||
| 29 | pub use core::{ | ||
| 30 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | ||
| 31 | unreachable, | ||
| 32 | }; | ||
| 33 | |||
| 34 | #[macro_export] | ||
| 35 | macro_rules! trace { | ||
| 36 | ($($msg:expr),*) => { | ||
| 37 | () | ||
| 38 | }; | ||
| 39 | } | ||
| 40 | |||
| 41 | #[macro_export] | ||
| 42 | macro_rules! debug { | ||
| 43 | ($($msg:expr),*) => { | ||
| 44 | () | ||
| 45 | }; | ||
| 46 | } | ||
| 47 | |||
| 48 | #[macro_export] | ||
| 49 | macro_rules! info { | ||
| 50 | ($($msg:expr),*) => { | ||
| 51 | () | ||
| 52 | }; | ||
| 53 | } | ||
| 54 | |||
| 55 | #[macro_export] | ||
| 56 | macro_rules! warn { | ||
| 57 | ($($msg:expr),*) => { | ||
| 58 | () | ||
| 59 | }; | ||
| 60 | } | ||
| 61 | |||
| 62 | #[macro_export] | ||
| 63 | macro_rules! error { | ||
| 64 | ($($msg:expr),*) => { | ||
| 65 | () | ||
| 66 | }; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | #[cfg(not(feature = "defmt"))] | ||
| 71 | #[macro_export] | ||
| 72 | macro_rules! unwrap { | ||
| 73 | ($arg:expr$(,$msg:expr)*) => { | ||
| 74 | match $crate::fmt::Try::into_result($arg) { | ||
| 75 | ::core::result::Result::Ok(t) => t, | ||
| 76 | ::core::result::Result::Err(e) => { | ||
| 77 | panic!($($msg,)*); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| 84 | pub struct NoneError; | ||
| 85 | |||
| 86 | pub trait Try { | ||
| 87 | type Ok; | ||
| 88 | type Error; | ||
| 89 | fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
| 90 | } | ||
| 91 | |||
| 92 | impl<T> Try for Option<T> { | ||
| 93 | type Ok = T; | ||
| 94 | type Error = NoneError; | ||
| 95 | |||
| 96 | #[inline] | ||
| 97 | fn into_result(self) -> Result<T, NoneError> { | ||
| 98 | self.ok_or(NoneError) | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | impl<T, E> Try for Result<T, E> { | ||
| 103 | type Ok = T; | ||
| 104 | type Error = E; | ||
| 105 | |||
| 106 | #[inline] | ||
| 107 | fn into_result(self) -> Self { | ||
| 108 | self | ||
| 109 | } | ||
| 110 | } | ||
diff --git a/embassy/src/io/error.rs b/embassy/src/io/error.rs index 8bbdae7f8..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(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)] | 5 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 6 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 6 | pub enum Error { | 7 | pub 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/lib.rs b/embassy/src/lib.rs index 65aabef01..49ba8eea8 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs | |||
| @@ -4,6 +4,9 @@ | |||
| 4 | #![feature(const_fn)] | 4 | #![feature(const_fn)] |
| 5 | #![feature(const_fn_fn_ptr_basics)] | 5 | #![feature(const_fn_fn_ptr_basics)] |
| 6 | 6 | ||
| 7 | // This mod MUST go first, so that the others see its macros. | ||
| 8 | pub(crate) mod fmt; | ||
| 9 | |||
| 7 | pub mod executor; | 10 | pub mod executor; |
| 8 | pub mod flash; | 11 | pub mod flash; |
| 9 | pub mod io; | 12 | pub mod io; |
diff --git a/embassy/src/rand.rs b/embassy/src/rand.rs index 3db164cf1..7e3788380 100644 --- a/embassy/src/rand.rs +++ b/embassy/src/rand.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use defmt::*; | 1 | use crate::fmt::*; |
| 2 | 2 | ||
| 3 | pub trait Rand { | 3 | pub trait Rand { |
| 4 | fn rand(&self, buf: &mut [u8]); | 4 | fn rand(&self, buf: &mut [u8]); |
diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs index 715d4155f..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 | ||
| 4 | use super::TICKS_PER_SECOND; | 4 | use super::TICKS_PER_SECOND; |
| 5 | 5 | ||
| 6 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, defmt::Format)] | 6 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] |
| 7 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 7 | pub struct Duration { | 8 | pub 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}; | |||
| 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, defmt::Format)] | 8 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] |
| 9 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 9 | pub struct Instant { | 10 | pub 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 0d97a789e..d6a9a3013 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 defmt::*; | 11 | use crate::fmt::*; |
| 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; |
diff --git a/embassy/src/util/drop_bomb.rs b/embassy/src/util/drop_bomb.rs index d33591fc2..b2b0684e5 100644 --- a/embassy/src/util/drop_bomb.rs +++ b/embassy/src/util/drop_bomb.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::fmt::panic; | ||
| 1 | use core::mem; | 2 | 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 6eecf52cd..05bdccf58 100644 --- a/embassy/src/util/portal.rs +++ b/embassy/src/util/portal.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use crate::fmt::panic; | ||
| 1 | use core::cell::UnsafeCell; | 2 | use core::cell::UnsafeCell; |
| 2 | use core::future::Future; | 3 | use core::future::Future; |
| 3 | use core::mem; | 4 | use core::mem; |
| 4 | use core::mem::MaybeUninit; | 5 | 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 45205368d..bde10c562 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use crate::fmt::panic; | ||
| 1 | use core::cell::UnsafeCell; | 2 | use core::cell::UnsafeCell; |
| 2 | use core::future::Future; | 3 | use core::future::Future; |
| 3 | use core::mem; | 4 | use core::mem; |
| 4 | use core::task::{Context, Poll, Waker}; | 5 | 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 71d0bbd77..c845c1bfb 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml | |||
| @@ -17,14 +17,14 @@ defmt-error = [] | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | [dependencies] | 19 | [dependencies] |
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt-trace", "52840"] } | 21 | embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt", "defmt-trace", "52840"] } |
| 22 | 22 | ||
| 23 | defmt = "0.1.2" | 23 | defmt = "0.1.3" |
| 24 | defmt-rtt = "0.1.0" | 24 | defmt-rtt = "0.1.0" |
| 25 | 25 | ||
| 26 | cortex-m = { version = "0.6.3" } | 26 | cortex-m = { version = "0.6.3" } |
| 27 | cortex-m-rt = "0.6.12" | 27 | cortex-m-rt = "0.6.13" |
| 28 | embedded-hal = { version = "0.2.4" } | 28 | embedded-hal = { version = "0.2.4" } |
| 29 | panic-probe = "0.1.0" | 29 | panic-probe = "0.1.0" |
| 30 | nrf52840-hal = { version = "0.12.0" } | 30 | nrf52840-hal = { version = "0.12.0" } |
diff --git a/test-build.sh b/test-build.sh index 66128ddc2..a3b5e8dfc 100755 --- a/test-build.sh +++ b/test-build.sh | |||
| @@ -7,6 +7,8 @@ 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 log) | ||
| 11 | (cd embassy; cargo build --target thumbv7em-none-eabihf --features defmt) | ||
| 10 | 12 | ||
| 11 | # embassy-nrf | 13 | # embassy-nrf |
| 12 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabi --features 52810) | 14 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabi --features 52810) |
| @@ -15,3 +17,6 @@ set -euxo pipefail | |||
| 15 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52833) | 17 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52833) |
| 16 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840) | 18 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840) |
| 17 | 19 | ||
| 20 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840,log) | ||
| 21 | (cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840,defmt) | ||
| 22 | |||
