diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-06-07 00:10:54 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-06-07 00:16:39 +0200 |
| commit | e7dc5c0939d30ccba98418c42799c4e39f646d23 (patch) | |
| tree | 896ebf078e97f15443dd85342f498231e142f975 | |
| parent | 4dda7be96841430c3aed2f014644b0b65cff0ef2 (diff) | |
fmt: make all macros `macro_rules` so scoping is consistent.
33 files changed, 884 insertions, 311 deletions
diff --git a/embassy-extras/src/fmt.rs b/embassy-extras/src/fmt.rs index 160642ccd..6c5063f7c 100644 --- a/embassy-extras/src/fmt.rs +++ b/embassy-extras/src/fmt.rs | |||
| @@ -1,67 +1,168 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(clippy::module_inception)] | 2 | #![allow(unused_macros)] |
| 3 | #![allow(unused)] | ||
| 4 | 3 | ||
| 5 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 6 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 7 | 6 | ||
| 8 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 9 | 17 | ||
| 10 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 11 | mod fmt { | 19 | ($($x:tt)*) => { |
| 12 | pub use defmt::{ | 20 | { |
| 13 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 14 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 15 | }; | 26 | }; |
| 16 | } | 27 | } |
| 17 | 28 | ||
| 18 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 19 | mod fmt { | 30 | ($($x:tt)*) => { |
| 20 | pub use core::{ | 31 | { |
| 21 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 22 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 23 | }; | 37 | }; |
| 24 | pub use log::{debug, error, info, trace, warn}; | ||
| 25 | } | 38 | } |
| 26 | 39 | ||
| 27 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 28 | mod fmt { | 41 | ($($x:tt)*) => { |
| 29 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 30 | 50 | ||
| 31 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 32 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 33 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 34 | }; | 59 | }; |
| 60 | } | ||
| 35 | 61 | ||
| 36 | macro_rules! trace { | 62 | macro_rules! debug_assert_ne { |
| 37 | ($($msg:expr),+ $(,)?) => { | 63 | ($($x:tt)*) => { |
| 38 | () | 64 | { |
| 39 | }; | 65 | #[cfg(not(feature = "defmt"))] |
| 40 | } | 66 | core::debug_assert_ne!($($x)*); |
| 67 | #[cfg(feature = "defmt")] | ||
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 41 | 72 | ||
| 42 | macro_rules! debug { | 73 | macro_rules! todo { |
| 43 | ($($msg:expr),+ $(,)?) => { | 74 | ($($x:tt)*) => { |
| 44 | () | 75 | { |
| 45 | }; | 76 | #[cfg(not(feature = "defmt"))] |
| 46 | } | 77 | core::todo!($($x)*); |
| 78 | #[cfg(feature = "defmt")] | ||
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | macro_rules! info { | 84 | macro_rules! unreachable { |
| 49 | ($($msg:expr),+ $(,)?) => { | 85 | ($($x:tt)*) => { |
| 50 | () | 86 | { |
| 51 | }; | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | } | 88 | core::unreachable!($($x)*); |
| 89 | #[cfg(feature = "defmt")] | ||
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 53 | 94 | ||
| 54 | macro_rules! warn { | 95 | macro_rules! panic { |
| 55 | ($($msg:expr),+ $(,)?) => { | 96 | ($($x:tt)*) => { |
| 56 | () | 97 | { |
| 57 | }; | 98 | #[cfg(not(feature = "defmt"))] |
| 58 | } | 99 | core::panic!($($x)*); |
| 100 | #[cfg(feature = "defmt")] | ||
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 59 | 105 | ||
| 60 | macro_rules! error { | 106 | macro_rules! trace { |
| 61 | ($($msg:expr),+ $(,)?) => { | 107 | ($($x:tt)*) => { |
| 62 | () | 108 | { |
| 63 | }; | 109 | #[cfg(feature = "log")] |
| 64 | } | 110 | log::trace!($($x)*); |
| 111 | #[cfg(feature = "defmt")] | ||
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 65 | } | 166 | } |
| 66 | 167 | ||
| 67 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
diff --git a/embassy-extras/src/ring_buffer.rs b/embassy-extras/src/ring_buffer.rs index dafdd958a..18795787f 100644 --- a/embassy-extras/src/ring_buffer.rs +++ b/embassy-extras/src/ring_buffer.rs | |||
| @@ -1,5 +1,3 @@ | |||
| 1 | use crate::fmt::assert; | ||
| 2 | |||
| 3 | pub struct RingBuffer<'a> { | 1 | pub struct RingBuffer<'a> { |
| 4 | buf: &'a mut [u8], | 2 | buf: &'a mut [u8], |
| 5 | start: usize, | 3 | start: usize, |
diff --git a/embassy-net/src/config/dhcp.rs b/embassy-net/src/config/dhcp.rs index f0c144321..8bbcd8176 100644 --- a/embassy-net/src/config/dhcp.rs +++ b/embassy-net/src/config/dhcp.rs | |||
| @@ -4,7 +4,6 @@ use smoltcp::time::Instant; | |||
| 4 | 4 | ||
| 5 | use super::*; | 5 | use super::*; |
| 6 | use crate::device::LinkState; | 6 | use crate::device::LinkState; |
| 7 | use crate::fmt::*; | ||
| 8 | use crate::{Interface, SocketSet}; | 7 | use crate::{Interface, SocketSet}; |
| 9 | 8 | ||
| 10 | pub struct DhcpConfigurator { | 9 | pub struct DhcpConfigurator { |
diff --git a/embassy-net/src/config/mod.rs b/embassy-net/src/config/mod.rs index 94725dba6..0f1886ae8 100644 --- a/embassy-net/src/config/mod.rs +++ b/embassy-net/src/config/mod.rs | |||
| @@ -2,7 +2,6 @@ use heapless::Vec; | |||
| 2 | use smoltcp::time::Instant; | 2 | use smoltcp::time::Instant; |
| 3 | use smoltcp::wire::{Ipv4Address, Ipv4Cidr}; | 3 | use smoltcp::wire::{Ipv4Address, Ipv4Cidr}; |
| 4 | 4 | ||
| 5 | use crate::fmt::*; | ||
| 6 | use crate::{Interface, SocketSet}; | 5 | use crate::{Interface, SocketSet}; |
| 7 | 6 | ||
| 8 | mod statik; | 7 | mod statik; |
diff --git a/embassy-net/src/config/statik.rs b/embassy-net/src/config/statik.rs index 912143bff..9a530717b 100644 --- a/embassy-net/src/config/statik.rs +++ b/embassy-net/src/config/statik.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | use smoltcp::time::Instant; | 1 | use smoltcp::time::Instant; |
| 2 | 2 | ||
| 3 | use super::*; | 3 | use super::*; |
| 4 | use crate::fmt::*; | ||
| 5 | use crate::{Interface, SocketSet}; | 4 | use crate::{Interface, SocketSet}; |
| 6 | 5 | ||
| 7 | pub struct StaticConfigurator { | 6 | pub struct StaticConfigurator { |
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 6c06b0605..5fcb94ac8 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs | |||
| @@ -3,7 +3,6 @@ use smoltcp::phy::Device as SmolDevice; | |||
| 3 | use smoltcp::phy::DeviceCapabilities; | 3 | use smoltcp::phy::DeviceCapabilities; |
| 4 | use smoltcp::time::Instant as SmolInstant; | 4 | use smoltcp::time::Instant as SmolInstant; |
| 5 | 5 | ||
| 6 | use crate::fmt::*; | ||
| 7 | use crate::packet_pool::PacketBoxExt; | 6 | use crate::packet_pool::PacketBoxExt; |
| 8 | use crate::Result; | 7 | use crate::Result; |
| 9 | use crate::{Packet, PacketBox, PacketBuf}; | 8 | use crate::{Packet, PacketBox, PacketBuf}; |
diff --git a/embassy-net/src/fmt.rs b/embassy-net/src/fmt.rs index 4da69766c..6c5063f7c 100644 --- a/embassy-net/src/fmt.rs +++ b/embassy-net/src/fmt.rs | |||
| @@ -1,74 +1,171 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(unused_macros)] | ||
| 2 | 3 | ||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 5 | 6 | ||
| 6 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 7 | 17 | ||
| 8 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 9 | mod fmt { | 19 | ($($x:tt)*) => { |
| 10 | pub use defmt::{ | 20 | { |
| 11 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 12 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 13 | }; | 26 | }; |
| 14 | } | 27 | } |
| 15 | 28 | ||
| 16 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 17 | mod fmt { | 30 | ($($x:tt)*) => { |
| 18 | pub use core::{ | 31 | { |
| 19 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 20 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 21 | }; | 37 | }; |
| 22 | pub use log::{debug, error, info, trace, warn}; | ||
| 23 | } | 38 | } |
| 24 | 39 | ||
| 25 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 26 | mod fmt { | 41 | ($($x:tt)*) => { |
| 27 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 28 | 50 | ||
| 29 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 30 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 31 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 32 | }; | 59 | }; |
| 60 | } | ||
| 33 | 61 | ||
| 34 | #[macro_export] | 62 | macro_rules! debug_assert_ne { |
| 35 | macro_rules! trace { | 63 | ($($x:tt)*) => { |
| 36 | ($($msg:expr),+ $(,)?) => { | 64 | { |
| 37 | () | 65 | #[cfg(not(feature = "defmt"))] |
| 38 | }; | 66 | core::debug_assert_ne!($($x)*); |
| 39 | } | 67 | #[cfg(feature = "defmt")] |
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 40 | 72 | ||
| 41 | #[macro_export] | 73 | macro_rules! todo { |
| 42 | macro_rules! debug { | 74 | ($($x:tt)*) => { |
| 43 | ($($msg:expr),+ $(,)?) => { | 75 | { |
| 44 | () | 76 | #[cfg(not(feature = "defmt"))] |
| 45 | }; | 77 | core::todo!($($x)*); |
| 46 | } | 78 | #[cfg(feature = "defmt")] |
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | #[macro_export] | 84 | macro_rules! unreachable { |
| 49 | macro_rules! info { | 85 | ($($x:tt)*) => { |
| 50 | ($($msg:expr),+ $(,)?) => { | 86 | { |
| 51 | () | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | }; | 88 | core::unreachable!($($x)*); |
| 53 | } | 89 | #[cfg(feature = "defmt")] |
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 54 | 94 | ||
| 55 | #[macro_export] | 95 | macro_rules! panic { |
| 56 | macro_rules! warn { | 96 | ($($x:tt)*) => { |
| 57 | ($($msg:expr),+ $(,)?) => { | 97 | { |
| 58 | () | 98 | #[cfg(not(feature = "defmt"))] |
| 59 | }; | 99 | core::panic!($($x)*); |
| 60 | } | 100 | #[cfg(feature = "defmt")] |
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 61 | 105 | ||
| 62 | #[macro_export] | 106 | macro_rules! trace { |
| 63 | macro_rules! error { | 107 | ($($x:tt)*) => { |
| 64 | ($($msg:expr),+ $(,)?) => { | 108 | { |
| 65 | () | 109 | #[cfg(feature = "log")] |
| 66 | }; | 110 | log::trace!($($x)*); |
| 67 | } | 111 | #[cfg(feature = "defmt")] |
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 68 | } | 166 | } |
| 69 | 167 | ||
| 70 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
| 71 | #[macro_export] | ||
| 72 | macro_rules! unwrap { | 169 | macro_rules! unwrap { |
| 73 | ($arg:expr) => { | 170 | ($arg:expr) => { |
| 74 | match $crate::fmt::Try::into_result($arg) { | 171 | match $crate::fmt::Try::into_result($arg) { |
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index e436beb1e..a38f00958 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs | |||
| @@ -20,7 +20,6 @@ use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; | |||
| 20 | use crate::config::Configurator; | 20 | use crate::config::Configurator; |
| 21 | use crate::config::Event; | 21 | use crate::config::Event; |
| 22 | use crate::device::{Device, DeviceAdapter, LinkState}; | 22 | use crate::device::{Device, DeviceAdapter, LinkState}; |
| 23 | use crate::fmt::*; | ||
| 24 | use crate::{Interface, SocketSet}; | 23 | use crate::{Interface, SocketSet}; |
| 25 | 24 | ||
| 26 | const ADDRESSES_LEN: usize = 1; | 25 | const ADDRESSES_LEN: usize = 1; |
diff --git a/embassy-net/src/tcp_socket.rs b/embassy-net/src/tcp_socket.rs index 4f43bc611..def4c8176 100644 --- a/embassy-net/src/tcp_socket.rs +++ b/embassy-net/src/tcp_socket.rs | |||
| @@ -11,7 +11,6 @@ use smoltcp::time::Duration; | |||
| 11 | use smoltcp::wire::IpEndpoint; | 11 | use smoltcp::wire::IpEndpoint; |
| 12 | 12 | ||
| 13 | use super::stack::Stack; | 13 | use super::stack::Stack; |
| 14 | use crate::fmt::*; | ||
| 15 | use crate::{Error, Result}; | 14 | use crate::{Error, Result}; |
| 16 | 15 | ||
| 17 | pub struct TcpSocket<'a> { | 16 | pub struct TcpSocket<'a> { |
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index b4ec70913..d853bda73 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -11,7 +11,6 @@ use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; | |||
| 11 | use embassy_extras::ring_buffer::RingBuffer; | 11 | use embassy_extras::ring_buffer::RingBuffer; |
| 12 | use embassy_extras::{low_power_wait_until, unborrow}; | 12 | use embassy_extras::{low_power_wait_until, unborrow}; |
| 13 | 13 | ||
| 14 | use crate::fmt::{panic, *}; | ||
| 15 | use crate::gpio::sealed::Pin as _; | 14 | use crate::gpio::sealed::Pin as _; |
| 16 | use crate::gpio::{OptionalPin as GpioOptionalPin, Pin as GpioPin}; | 15 | use crate::gpio::{OptionalPin as GpioOptionalPin, Pin as GpioPin}; |
| 17 | use crate::pac; | 16 | use crate::pac; |
diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs index 160642ccd..6c5063f7c 100644 --- a/embassy-nrf/src/fmt.rs +++ b/embassy-nrf/src/fmt.rs | |||
| @@ -1,67 +1,168 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(clippy::module_inception)] | 2 | #![allow(unused_macros)] |
| 3 | #![allow(unused)] | ||
| 4 | 3 | ||
| 5 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 6 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 7 | 6 | ||
| 8 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 9 | 17 | ||
| 10 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 11 | mod fmt { | 19 | ($($x:tt)*) => { |
| 12 | pub use defmt::{ | 20 | { |
| 13 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 14 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 15 | }; | 26 | }; |
| 16 | } | 27 | } |
| 17 | 28 | ||
| 18 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 19 | mod fmt { | 30 | ($($x:tt)*) => { |
| 20 | pub use core::{ | 31 | { |
| 21 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 22 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 23 | }; | 37 | }; |
| 24 | pub use log::{debug, error, info, trace, warn}; | ||
| 25 | } | 38 | } |
| 26 | 39 | ||
| 27 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 28 | mod fmt { | 41 | ($($x:tt)*) => { |
| 29 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 30 | 50 | ||
| 31 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 32 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 33 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 34 | }; | 59 | }; |
| 60 | } | ||
| 35 | 61 | ||
| 36 | macro_rules! trace { | 62 | macro_rules! debug_assert_ne { |
| 37 | ($($msg:expr),+ $(,)?) => { | 63 | ($($x:tt)*) => { |
| 38 | () | 64 | { |
| 39 | }; | 65 | #[cfg(not(feature = "defmt"))] |
| 40 | } | 66 | core::debug_assert_ne!($($x)*); |
| 67 | #[cfg(feature = "defmt")] | ||
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 41 | 72 | ||
| 42 | macro_rules! debug { | 73 | macro_rules! todo { |
| 43 | ($($msg:expr),+ $(,)?) => { | 74 | ($($x:tt)*) => { |
| 44 | () | 75 | { |
| 45 | }; | 76 | #[cfg(not(feature = "defmt"))] |
| 46 | } | 77 | core::todo!($($x)*); |
| 78 | #[cfg(feature = "defmt")] | ||
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | macro_rules! info { | 84 | macro_rules! unreachable { |
| 49 | ($($msg:expr),+ $(,)?) => { | 85 | ($($x:tt)*) => { |
| 50 | () | 86 | { |
| 51 | }; | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | } | 88 | core::unreachable!($($x)*); |
| 89 | #[cfg(feature = "defmt")] | ||
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 53 | 94 | ||
| 54 | macro_rules! warn { | 95 | macro_rules! panic { |
| 55 | ($($msg:expr),+ $(,)?) => { | 96 | ($($x:tt)*) => { |
| 56 | () | 97 | { |
| 57 | }; | 98 | #[cfg(not(feature = "defmt"))] |
| 58 | } | 99 | core::panic!($($x)*); |
| 100 | #[cfg(feature = "defmt")] | ||
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 59 | 105 | ||
| 60 | macro_rules! error { | 106 | macro_rules! trace { |
| 61 | ($($msg:expr),+ $(,)?) => { | 107 | ($($x:tt)*) => { |
| 62 | () | 108 | { |
| 63 | }; | 109 | #[cfg(feature = "log")] |
| 64 | } | 110 | log::trace!($($x)*); |
| 111 | #[cfg(feature = "defmt")] | ||
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 65 | } | 166 | } |
| 66 | 167 | ||
| 67 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 8fc16a3ba..07509aef9 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -6,7 +6,6 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 6 | use embassy::util::Unborrow; | 6 | use embassy::util::Unborrow; |
| 7 | use embassy_extras::unborrow; | 7 | use embassy_extras::unborrow; |
| 8 | 8 | ||
| 9 | use crate::fmt::{unreachable, *}; | ||
| 10 | use crate::gpio::sealed::Pin as _; | 9 | use crate::gpio::sealed::Pin as _; |
| 11 | use crate::gpio::OptionalPin as GpioOptionalPin; | 10 | use crate::gpio::OptionalPin as GpioOptionalPin; |
| 12 | use crate::interrupt::Interrupt; | 11 | use crate::interrupt::Interrupt; |
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 882db9d8b..42bf8f419 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -10,7 +10,6 @@ use embassy::util::{AtomicWaker, DropBomb, Unborrow}; | |||
| 10 | use embassy_extras::unborrow; | 10 | use embassy_extras::unborrow; |
| 11 | use futures::future::poll_fn; | 11 | use futures::future::poll_fn; |
| 12 | 12 | ||
| 13 | use crate::fmt::{assert, assert_eq, *}; | ||
| 14 | use crate::gpio::sealed::Pin as _; | 13 | use crate::gpio::sealed::Pin as _; |
| 15 | use crate::gpio::{self, Pin as GpioPin}; | 14 | use crate::gpio::{self, Pin as GpioPin}; |
| 16 | use crate::pac; | 15 | use crate::pac; |
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index b5e9afbc1..47d7c5f90 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -11,10 +11,10 @@ use embassy_extras::unborrow; | |||
| 11 | use futures::future::poll_fn; | 11 | use futures::future::poll_fn; |
| 12 | use traits::spi::FullDuplex; | 12 | use traits::spi::FullDuplex; |
| 13 | 13 | ||
| 14 | use crate::gpio; | ||
| 14 | use crate::gpio::sealed::Pin as _; | 15 | use crate::gpio::sealed::Pin as _; |
| 15 | use crate::gpio::{OptionalPin, Pin as GpioPin}; | 16 | use crate::gpio::{OptionalPin, Pin as GpioPin}; |
| 16 | use crate::interrupt::Interrupt; | 17 | use crate::interrupt::Interrupt; |
| 17 | use crate::{fmt::*, gpio}; | ||
| 18 | use crate::{pac, util::slice_in_ram_or}; | 18 | use crate::{pac, util::slice_in_ram_or}; |
| 19 | 19 | ||
| 20 | pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 20 | pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 160868d7d..5f3c51578 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -18,10 +18,10 @@ use futures::future::poll_fn; | |||
| 18 | use traits::i2c::I2c; | 18 | use traits::i2c::I2c; |
| 19 | 19 | ||
| 20 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 20 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 21 | use crate::gpio; | ||
| 21 | use crate::gpio::Pin as GpioPin; | 22 | use crate::gpio::Pin as GpioPin; |
| 22 | use crate::pac; | 23 | use crate::pac; |
| 23 | use crate::util::{slice_in_ram, slice_in_ram_or}; | 24 | use crate::util::{slice_in_ram, slice_in_ram_or}; |
| 24 | use crate::{fmt::*, gpio}; | ||
| 25 | 25 | ||
| 26 | pub enum Frequency { | 26 | pub enum Frequency { |
| 27 | #[doc = "26738688: 100 kbps"] | 27 | #[doc = "26738688: 100 kbps"] |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 2f6d1a391..de093c7f0 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -13,7 +13,6 @@ use embassy_extras::unborrow; | |||
| 13 | use futures::future::poll_fn; | 13 | use futures::future::poll_fn; |
| 14 | 14 | ||
| 15 | use crate::chip::EASY_DMA_SIZE; | 15 | use crate::chip::EASY_DMA_SIZE; |
| 16 | use crate::fmt::{assert, panic, *}; | ||
| 17 | use crate::gpio::sealed::Pin as _; | 16 | use crate::gpio::sealed::Pin as _; |
| 18 | use crate::gpio::{self, OptionalPin as GpioOptionalPin, Pin as GpioPin}; | 17 | use crate::gpio::{self, OptionalPin as GpioOptionalPin, Pin as GpioPin}; |
| 19 | use crate::interrupt::Interrupt; | 18 | use crate::interrupt::Interrupt; |
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index a74b9b92b..235e92d7c 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | use core::sync::atomic::{compiler_fence, Ordering}; | 1 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 2 | 2 | ||
| 3 | use crate::fmt::assert; | ||
| 4 | use crate::pac::dma::vals; | 3 | use crate::pac::dma::vals; |
| 5 | use crate::{pac, peripherals}; | 4 | use crate::{pac, peripherals}; |
| 6 | 5 | ||
diff --git a/embassy-rp/src/fmt.rs b/embassy-rp/src/fmt.rs index 4da69766c..6c5063f7c 100644 --- a/embassy-rp/src/fmt.rs +++ b/embassy-rp/src/fmt.rs | |||
| @@ -1,74 +1,171 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(unused_macros)] | ||
| 2 | 3 | ||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 5 | 6 | ||
| 6 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 7 | 17 | ||
| 8 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 9 | mod fmt { | 19 | ($($x:tt)*) => { |
| 10 | pub use defmt::{ | 20 | { |
| 11 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 12 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 13 | }; | 26 | }; |
| 14 | } | 27 | } |
| 15 | 28 | ||
| 16 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 17 | mod fmt { | 30 | ($($x:tt)*) => { |
| 18 | pub use core::{ | 31 | { |
| 19 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 20 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 21 | }; | 37 | }; |
| 22 | pub use log::{debug, error, info, trace, warn}; | ||
| 23 | } | 38 | } |
| 24 | 39 | ||
| 25 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 26 | mod fmt { | 41 | ($($x:tt)*) => { |
| 27 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 28 | 50 | ||
| 29 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 30 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 31 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 32 | }; | 59 | }; |
| 60 | } | ||
| 33 | 61 | ||
| 34 | #[macro_export] | 62 | macro_rules! debug_assert_ne { |
| 35 | macro_rules! trace { | 63 | ($($x:tt)*) => { |
| 36 | ($($msg:expr),+ $(,)?) => { | 64 | { |
| 37 | () | 65 | #[cfg(not(feature = "defmt"))] |
| 38 | }; | 66 | core::debug_assert_ne!($($x)*); |
| 39 | } | 67 | #[cfg(feature = "defmt")] |
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 40 | 72 | ||
| 41 | #[macro_export] | 73 | macro_rules! todo { |
| 42 | macro_rules! debug { | 74 | ($($x:tt)*) => { |
| 43 | ($($msg:expr),+ $(,)?) => { | 75 | { |
| 44 | () | 76 | #[cfg(not(feature = "defmt"))] |
| 45 | }; | 77 | core::todo!($($x)*); |
| 46 | } | 78 | #[cfg(feature = "defmt")] |
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | #[macro_export] | 84 | macro_rules! unreachable { |
| 49 | macro_rules! info { | 85 | ($($x:tt)*) => { |
| 50 | ($($msg:expr),+ $(,)?) => { | 86 | { |
| 51 | () | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | }; | 88 | core::unreachable!($($x)*); |
| 53 | } | 89 | #[cfg(feature = "defmt")] |
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 54 | 94 | ||
| 55 | #[macro_export] | 95 | macro_rules! panic { |
| 56 | macro_rules! warn { | 96 | ($($x:tt)*) => { |
| 57 | ($($msg:expr),+ $(,)?) => { | 97 | { |
| 58 | () | 98 | #[cfg(not(feature = "defmt"))] |
| 59 | }; | 99 | core::panic!($($x)*); |
| 60 | } | 100 | #[cfg(feature = "defmt")] |
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 61 | 105 | ||
| 62 | #[macro_export] | 106 | macro_rules! trace { |
| 63 | macro_rules! error { | 107 | ($($x:tt)*) => { |
| 64 | ($($msg:expr),+ $(,)?) => { | 108 | { |
| 65 | () | 109 | #[cfg(feature = "log")] |
| 66 | }; | 110 | log::trace!($($x)*); |
| 67 | } | 111 | #[cfg(feature = "defmt")] |
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 68 | } | 166 | } |
| 69 | 167 | ||
| 70 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
| 71 | #[macro_export] | ||
| 72 | macro_rules! unwrap { | 169 | macro_rules! unwrap { |
| 73 | ($arg:expr) => { | 170 | ($arg:expr) => { |
| 74 | match $crate::fmt::Try::into_result($arg) { | 171 | match $crate::fmt::Try::into_result($arg) { |
diff --git a/embassy-rp/src/pll.rs b/embassy-rp/src/pll.rs index befb368c5..13c16baf8 100644 --- a/embassy-rp/src/pll.rs +++ b/embassy-rp/src/pll.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use crate::fmt::assert; | ||
| 2 | use crate::pac; | 1 | use crate::pac; |
| 3 | 2 | ||
| 4 | const XOSC_MHZ: u32 = 12; | 3 | const XOSC_MHZ: u32 = 12; |
diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index a7aad04f0..d8c9415b6 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | use crate::dac::{DacPin, Instance}; | 1 | use crate::dac::{DacPin, Instance}; |
| 2 | use crate::fmt::*; | ||
| 3 | use crate::gpio::AnyPin; | 2 | use crate::gpio::AnyPin; |
| 4 | use crate::pac::dac; | 3 | use crate::pac::dac; |
| 5 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
diff --git a/embassy-stm32/src/dma/v2.rs b/embassy-stm32/src/dma/v2.rs index 5b2505463..e7bd69130 100644 --- a/embassy-stm32/src/dma/v2.rs +++ b/embassy-stm32/src/dma/v2.rs | |||
| @@ -5,7 +5,6 @@ use embassy::util::AtomicWaker; | |||
| 5 | use futures::future::poll_fn; | 5 | use futures::future::poll_fn; |
| 6 | 6 | ||
| 7 | use super::*; | 7 | use super::*; |
| 8 | use crate::fmt::assert; | ||
| 9 | use crate::interrupt; | 8 | use crate::interrupt; |
| 10 | use crate::pac; | 9 | use crate::pac; |
| 11 | use crate::pac::dma::{regs, vals}; | 10 | use crate::pac::dma::{regs, vals}; |
diff --git a/embassy-stm32/src/fmt.rs b/embassy-stm32/src/fmt.rs index 160642ccd..6c5063f7c 100644 --- a/embassy-stm32/src/fmt.rs +++ b/embassy-stm32/src/fmt.rs | |||
| @@ -1,67 +1,168 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(clippy::module_inception)] | 2 | #![allow(unused_macros)] |
| 3 | #![allow(unused)] | ||
| 4 | 3 | ||
| 5 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 6 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 7 | 6 | ||
| 8 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 9 | 17 | ||
| 10 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 11 | mod fmt { | 19 | ($($x:tt)*) => { |
| 12 | pub use defmt::{ | 20 | { |
| 13 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 14 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 15 | }; | 26 | }; |
| 16 | } | 27 | } |
| 17 | 28 | ||
| 18 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 19 | mod fmt { | 30 | ($($x:tt)*) => { |
| 20 | pub use core::{ | 31 | { |
| 21 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 22 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 23 | }; | 37 | }; |
| 24 | pub use log::{debug, error, info, trace, warn}; | ||
| 25 | } | 38 | } |
| 26 | 39 | ||
| 27 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 28 | mod fmt { | 41 | ($($x:tt)*) => { |
| 29 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 30 | 50 | ||
| 31 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 32 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 33 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 34 | }; | 59 | }; |
| 60 | } | ||
| 35 | 61 | ||
| 36 | macro_rules! trace { | 62 | macro_rules! debug_assert_ne { |
| 37 | ($($msg:expr),+ $(,)?) => { | 63 | ($($x:tt)*) => { |
| 38 | () | 64 | { |
| 39 | }; | 65 | #[cfg(not(feature = "defmt"))] |
| 40 | } | 66 | core::debug_assert_ne!($($x)*); |
| 67 | #[cfg(feature = "defmt")] | ||
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 41 | 72 | ||
| 42 | macro_rules! debug { | 73 | macro_rules! todo { |
| 43 | ($($msg:expr),+ $(,)?) => { | 74 | ($($x:tt)*) => { |
| 44 | () | 75 | { |
| 45 | }; | 76 | #[cfg(not(feature = "defmt"))] |
| 46 | } | 77 | core::todo!($($x)*); |
| 78 | #[cfg(feature = "defmt")] | ||
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | macro_rules! info { | 84 | macro_rules! unreachable { |
| 49 | ($($msg:expr),+ $(,)?) => { | 85 | ($($x:tt)*) => { |
| 50 | () | 86 | { |
| 51 | }; | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | } | 88 | core::unreachable!($($x)*); |
| 89 | #[cfg(feature = "defmt")] | ||
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 53 | 94 | ||
| 54 | macro_rules! warn { | 95 | macro_rules! panic { |
| 55 | ($($msg:expr),+ $(,)?) => { | 96 | ($($x:tt)*) => { |
| 56 | () | 97 | { |
| 57 | }; | 98 | #[cfg(not(feature = "defmt"))] |
| 58 | } | 99 | core::panic!($($x)*); |
| 100 | #[cfg(feature = "defmt")] | ||
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 59 | 105 | ||
| 60 | macro_rules! error { | 106 | macro_rules! trace { |
| 61 | ($($msg:expr),+ $(,)?) => { | 107 | ($($x:tt)*) => { |
| 62 | () | 108 | { |
| 63 | }; | 109 | #[cfg(feature = "log")] |
| 64 | } | 110 | log::trace!($($x)*); |
| 111 | #[cfg(feature = "defmt")] | ||
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 65 | } | 166 | } |
| 66 | 167 | ||
| 67 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs index fbf864bf6..57cdd5470 100644 --- a/embassy-stm32/src/rcc/h7/mod.rs +++ b/embassy-stm32/src/rcc/h7/mod.rs | |||
| @@ -2,7 +2,6 @@ use core::marker::PhantomData; | |||
| 2 | 2 | ||
| 3 | use embassy::util::Unborrow; | 3 | use embassy::util::Unborrow; |
| 4 | 4 | ||
| 5 | use crate::fmt::{assert, panic}; | ||
| 6 | use crate::pac::rcc::vals::Timpre; | 5 | use crate::pac::rcc::vals::Timpre; |
| 7 | use crate::pac::{DBGMCU, RCC, SYSCFG}; | 6 | use crate::pac::{DBGMCU, RCC, SYSCFG}; |
| 8 | use crate::peripherals; | 7 | use crate::peripherals; |
diff --git a/embassy-stm32/src/rcc/h7/pll.rs b/embassy-stm32/src/rcc/h7/pll.rs index af958d093..4c40d84d4 100644 --- a/embassy-stm32/src/rcc/h7/pll.rs +++ b/embassy-stm32/src/rcc/h7/pll.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | use super::{Hertz, RCC}; | 1 | use super::{Hertz, RCC}; |
| 2 | use crate::fmt::assert; | ||
| 3 | 2 | ||
| 4 | const VCO_MIN: u32 = 150_000_000; | 3 | const VCO_MIN: u32 = 150_000_000; |
| 5 | const VCO_MAX: u32 = 420_000_000; | 4 | const VCO_MAX: u32 = 420_000_000; |
diff --git a/embassy-stm32/src/sdmmc/v2.rs b/embassy-stm32/src/sdmmc/v2.rs index 2c7f8ac00..9c7bad4df 100644 --- a/embassy-stm32/src/sdmmc/v2.rs +++ b/embassy-stm32/src/sdmmc/v2.rs | |||
| @@ -10,7 +10,6 @@ use embassy_extras::unborrow; | |||
| 10 | use futures::future::poll_fn; | 10 | use futures::future::poll_fn; |
| 11 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; | 11 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; |
| 12 | 12 | ||
| 13 | use crate::fmt::*; | ||
| 14 | use crate::interrupt::Interrupt; | 13 | use crate::interrupt::Interrupt; |
| 15 | use crate::pac; | 14 | use crate::pac; |
| 16 | use crate::pac::gpio::Gpio; | 15 | use crate::pac::gpio::Gpio; |
| @@ -434,7 +433,7 @@ impl SdmmcInner { | |||
| 434 | BusWidth::One => 0, | 433 | BusWidth::One => 0, |
| 435 | BusWidth::Four => 1, | 434 | BusWidth::Four => 1, |
| 436 | BusWidth::Eight => 2, | 435 | BusWidth::Eight => 2, |
| 437 | _ => self::panic!("Invalid Bus Width"), | 436 | _ => panic!("Invalid Bus Width"), |
| 438 | }) | 437 | }) |
| 439 | }); | 438 | }); |
| 440 | 439 | ||
| @@ -637,7 +636,7 @@ impl SdmmcInner { | |||
| 637 | direction: Dir, | 636 | direction: Dir, |
| 638 | data_transfer_timeout: u32, | 637 | data_transfer_timeout: u32, |
| 639 | ) { | 638 | ) { |
| 640 | self::assert!(block_size <= 14, "Block size up to 2^14 bytes"); | 639 | assert!(block_size <= 14, "Block size up to 2^14 bytes"); |
| 641 | let regs = self.0; | 640 | let regs = self.0; |
| 642 | 641 | ||
| 643 | let dtdir = match direction { | 642 | let dtdir = match direction { |
| @@ -678,7 +677,7 @@ impl SdmmcInner { | |||
| 678 | // Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7 | 677 | // Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7 |
| 679 | // Section 55.5.8 | 678 | // Section 55.5.8 |
| 680 | let sdmmc_bus_bandwidth = new_clock.0 * (width as u32); | 679 | let sdmmc_bus_bandwidth = new_clock.0 * (width as u32); |
| 681 | self::assert!(hclk.0 > 3 * sdmmc_bus_bandwidth / 32); | 680 | assert!(hclk.0 > 3 * sdmmc_bus_bandwidth / 32); |
| 682 | *clock = new_clock; | 681 | *clock = new_clock; |
| 683 | 682 | ||
| 684 | // NOTE(unsafe) We have exclusive access to the regblock | 683 | // NOTE(unsafe) We have exclusive access to the regblock |
diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index 8a3a8991a..598d4e558 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs | |||
| @@ -9,7 +9,6 @@ mod timer_queue; | |||
| 9 | mod util; | 9 | mod util; |
| 10 | mod waker; | 10 | mod waker; |
| 11 | 11 | ||
| 12 | use crate::fmt::panic; | ||
| 13 | use crate::interrupt::{Interrupt, InterruptExt}; | 12 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 14 | use crate::time::Alarm; | 13 | use crate::time::Alarm; |
| 15 | 14 | ||
diff --git a/embassy/src/executor/waker.rs b/embassy/src/executor/waker.rs index 050f6a1cf..ea5b501f1 100644 --- a/embassy/src/executor/waker.rs +++ b/embassy/src/executor/waker.rs | |||
| @@ -24,7 +24,9 @@ pub(crate) unsafe fn from_task(p: NonNull<TaskHeader>) -> Waker { | |||
| 24 | 24 | ||
| 25 | pub unsafe fn task_from_waker(waker: &Waker) -> NonNull<TaskHeader> { | 25 | pub unsafe fn task_from_waker(waker: &Waker) -> NonNull<TaskHeader> { |
| 26 | let hack: &WakerHack = mem::transmute(waker); | 26 | let hack: &WakerHack = mem::transmute(waker); |
| 27 | assert_eq!(hack.vtable, &VTABLE); | 27 | if hack.vtable != &VTABLE { |
| 28 | panic!("Found waker not created by the embassy executor. Consider enabling the `executor-agnostic` feature on the `embassy` crate.") | ||
| 29 | } | ||
| 28 | NonNull::new_unchecked(hack.data as *mut TaskHeader) | 30 | NonNull::new_unchecked(hack.data as *mut TaskHeader) |
| 29 | } | 31 | } |
| 30 | 32 | ||
diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs index 160642ccd..6c5063f7c 100644 --- a/embassy/src/fmt.rs +++ b/embassy/src/fmt.rs | |||
| @@ -1,67 +1,168 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(clippy::module_inception)] | 2 | #![allow(unused_macros)] |
| 3 | #![allow(unused)] | ||
| 4 | 3 | ||
| 5 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 6 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 7 | 6 | ||
| 8 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 9 | 17 | ||
| 10 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 11 | mod fmt { | 19 | ($($x:tt)*) => { |
| 12 | pub use defmt::{ | 20 | { |
| 13 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 14 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 15 | }; | 26 | }; |
| 16 | } | 27 | } |
| 17 | 28 | ||
| 18 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 19 | mod fmt { | 30 | ($($x:tt)*) => { |
| 20 | pub use core::{ | 31 | { |
| 21 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 22 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 23 | }; | 37 | }; |
| 24 | pub use log::{debug, error, info, trace, warn}; | ||
| 25 | } | 38 | } |
| 26 | 39 | ||
| 27 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 28 | mod fmt { | 41 | ($($x:tt)*) => { |
| 29 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 30 | 50 | ||
| 31 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 32 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 33 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 34 | }; | 59 | }; |
| 60 | } | ||
| 35 | 61 | ||
| 36 | macro_rules! trace { | 62 | macro_rules! debug_assert_ne { |
| 37 | ($($msg:expr),+ $(,)?) => { | 63 | ($($x:tt)*) => { |
| 38 | () | 64 | { |
| 39 | }; | 65 | #[cfg(not(feature = "defmt"))] |
| 40 | } | 66 | core::debug_assert_ne!($($x)*); |
| 67 | #[cfg(feature = "defmt")] | ||
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 41 | 72 | ||
| 42 | macro_rules! debug { | 73 | macro_rules! todo { |
| 43 | ($($msg:expr),+ $(,)?) => { | 74 | ($($x:tt)*) => { |
| 44 | () | 75 | { |
| 45 | }; | 76 | #[cfg(not(feature = "defmt"))] |
| 46 | } | 77 | core::todo!($($x)*); |
| 78 | #[cfg(feature = "defmt")] | ||
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | macro_rules! info { | 84 | macro_rules! unreachable { |
| 49 | ($($msg:expr),+ $(,)?) => { | 85 | ($($x:tt)*) => { |
| 50 | () | 86 | { |
| 51 | }; | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | } | 88 | core::unreachable!($($x)*); |
| 89 | #[cfg(feature = "defmt")] | ||
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 53 | 94 | ||
| 54 | macro_rules! warn { | 95 | macro_rules! panic { |
| 55 | ($($msg:expr),+ $(,)?) => { | 96 | ($($x:tt)*) => { |
| 56 | () | 97 | { |
| 57 | }; | 98 | #[cfg(not(feature = "defmt"))] |
| 58 | } | 99 | core::panic!($($x)*); |
| 100 | #[cfg(feature = "defmt")] | ||
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 59 | 105 | ||
| 60 | macro_rules! error { | 106 | macro_rules! trace { |
| 61 | ($($msg:expr),+ $(,)?) => { | 107 | ($($x:tt)*) => { |
| 62 | () | 108 | { |
| 63 | }; | 109 | #[cfg(feature = "log")] |
| 64 | } | 110 | log::trace!($($x)*); |
| 111 | #[cfg(feature = "defmt")] | ||
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 65 | } | 166 | } |
| 66 | 167 | ||
| 67 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
diff --git a/embassy/src/time/mod.rs b/embassy/src/time/mod.rs index d7284b7a2..21b93d384 100644 --- a/embassy/src/time/mod.rs +++ b/embassy/src/time/mod.rs | |||
| @@ -10,8 +10,6 @@ pub use duration::Duration; | |||
| 10 | pub use instant::Instant; | 10 | pub use instant::Instant; |
| 11 | pub use traits::*; | 11 | pub use traits::*; |
| 12 | 12 | ||
| 13 | use crate::fmt::*; | ||
| 14 | |||
| 15 | // 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. |
| 16 | pub const TICKS_PER_SECOND: u64 = 32768; | 14 | pub const TICKS_PER_SECOND: u64 = 32768; |
| 17 | 15 | ||
diff --git a/embassy/src/util/drop_bomb.rs b/embassy/src/util/drop_bomb.rs index 388209a23..efb36a97d 100644 --- a/embassy/src/util/drop_bomb.rs +++ b/embassy/src/util/drop_bomb.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use crate::fmt::panic; | ||
| 2 | use core::mem; | 1 | use core::mem; |
| 3 | 2 | ||
| 4 | /// An explosive ordinance that panics if it is improperly disposed of. | 3 | /// An explosive ordinance that panics if it is improperly disposed of. |
diff --git a/embassy/src/util/mutex.rs b/embassy/src/util/mutex.rs index 86ab070a3..e4b7764ce 100644 --- a/embassy/src/util/mutex.rs +++ b/embassy/src/util/mutex.rs | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | use core::cell::UnsafeCell; | 1 | use core::cell::UnsafeCell; |
| 2 | use critical_section::CriticalSection; | 2 | use critical_section::CriticalSection; |
| 3 | 3 | ||
| 4 | use crate::fmt::assert; | ||
| 5 | |||
| 6 | /// A "mutex" based on critical sections | 4 | /// A "mutex" based on critical sections |
| 7 | /// | 5 | /// |
| 8 | /// # Safety | 6 | /// # Safety |
diff --git a/embassy/src/util/portal.rs b/embassy/src/util/portal.rs index f4f2824aa..8ea481093 100644 --- a/embassy/src/util/portal.rs +++ b/embassy/src/util/portal.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use crate::fmt::panic; | ||
| 2 | use core::cell::UnsafeCell; | 1 | use core::cell::UnsafeCell; |
| 3 | use core::mem; | 2 | use core::mem; |
| 4 | use core::mem::MaybeUninit; | 3 | use core::mem::MaybeUninit; |
diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index 2eefe658b..af261c457 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs | |||
| @@ -9,7 +9,6 @@ use executor::raw::TaskHeader; | |||
| 9 | use ptr::NonNull; | 9 | use ptr::NonNull; |
| 10 | 10 | ||
| 11 | use crate::executor; | 11 | use crate::executor; |
| 12 | use crate::fmt::panic; | ||
| 13 | use crate::interrupt::{Interrupt, InterruptExt}; | 12 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 14 | 13 | ||
| 15 | /// Synchronization primitive. Allows creating awaitable signals that may be passed between tasks. | 14 | /// Synchronization primitive. Allows creating awaitable signals that may be passed between tasks. |
