summaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2021-06-07 00:10:54 +0200
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2021-06-07 00:16:39 +0200
commite7dc5c0939d30ccba98418c42799c4e39f646d23 (patch)
tree896ebf078e97f15443dd85342f498231e142f975 /embassy-nrf
parent4dda7be96841430c3aed2f014644b0b65cff0ef2 (diff)
downloadembassy-e7dc5c0939d30ccba98418c42799c4e39f646d23.zip
fmt: make all macros `macro_rules` so scoping is consistent.
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs1
-rw-r--r--embassy-nrf/src/fmt.rs191
-rw-r--r--embassy-nrf/src/pwm.rs1
-rw-r--r--embassy-nrf/src/qspi.rs1
-rw-r--r--embassy-nrf/src/spim.rs2
-rw-r--r--embassy-nrf/src/twim.rs2
-rw-r--r--embassy-nrf/src/uarte.rs1
7 files changed, 148 insertions, 51 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index b4ec7091..d853bda7 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};
use embassy_extras::ring_buffer::RingBuffer;
use embassy_extras::{low_power_wait_until, unborrow};
-use crate::fmt::{panic, *};
use crate::gpio::sealed::Pin as _;
use crate::gpio::{OptionalPin as GpioOptionalPin, Pin as GpioPin};
use crate::pac;
diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs
index 160642cc..6c5063f7 100644
--- a/embassy-nrf/src/fmt.rs
+++ b/embassy-nrf/src/fmt.rs
@@ -1,67 +1,168 @@
#![macro_use]
-#![allow(clippy::module_inception)]
-#![allow(unused)]
+#![allow(unused_macros)]
#[cfg(all(feature = "defmt", feature = "log"))]
compile_error!("You may not enable both `defmt` and `log` features.");
-pub use fmt::*;
+macro_rules! assert {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::assert!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::assert!($($x)*);
+ }
+ };
+}
-#[cfg(feature = "defmt")]
-mod fmt {
- pub use defmt::{
- assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error,
- info, panic, todo, trace, unreachable, unwrap, warn,
+macro_rules! assert_eq {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::assert_eq!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::assert_eq!($($x)*);
+ }
};
}
-#[cfg(feature = "log")]
-mod fmt {
- pub use core::{
- assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
- unreachable,
+macro_rules! assert_ne {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::assert_ne!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::assert_ne!($($x)*);
+ }
};
- pub use log::{debug, error, info, trace, warn};
}
-#[cfg(not(any(feature = "defmt", feature = "log")))]
-mod fmt {
- #![macro_use]
+macro_rules! debug_assert {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::debug_assert!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::debug_assert!($($x)*);
+ }
+ };
+}
- pub use core::{
- assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
- unreachable,
+macro_rules! debug_assert_eq {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::debug_assert_eq!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::debug_assert_eq!($($x)*);
+ }
};
+}
- macro_rules! trace {
- ($($msg:expr),+ $(,)?) => {
- ()
- };
- }
+macro_rules! debug_assert_ne {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::debug_assert_ne!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::debug_assert_ne!($($x)*);
+ }
+ };
+}
- macro_rules! debug {
- ($($msg:expr),+ $(,)?) => {
- ()
- };
- }
+macro_rules! todo {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::todo!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::todo!($($x)*);
+ }
+ };
+}
- macro_rules! info {
- ($($msg:expr),+ $(,)?) => {
- ()
- };
- }
+macro_rules! unreachable {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::unreachable!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::unreachable!($($x)*);
+ }
+ };
+}
- macro_rules! warn {
- ($($msg:expr),+ $(,)?) => {
- ()
- };
- }
+macro_rules! panic {
+ ($($x:tt)*) => {
+ {
+ #[cfg(not(feature = "defmt"))]
+ core::panic!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::panic!($($x)*);
+ }
+ };
+}
- macro_rules! error {
- ($($msg:expr),+ $(,)?) => {
- ()
- };
- }
+macro_rules! trace {
+ ($($x:tt)*) => {
+ {
+ #[cfg(feature = "log")]
+ log::trace!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::trace!($($x)*);
+ }
+ };
+}
+
+macro_rules! debug {
+ ($($x:tt)*) => {
+ {
+ #[cfg(fevature = "log")]
+ log::debug!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::debug!($($x)*);
+ }
+ };
+}
+
+macro_rules! info {
+ ($($x:tt)*) => {
+ {
+ #[cfg(feature = "log")]
+ log::info!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::info!($($x)*);
+ }
+ };
+}
+
+macro_rules! warn {
+ ($($x:tt)*) => {
+ {
+ #[cfg(feature = "log")]
+ log::warn!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::warn!($($x)*);
+ }
+ };
+}
+
+macro_rules! error {
+ ($($x:tt)*) => {
+ {
+ #[cfg(feature = "log")]
+ log::error!($($x)*);
+ #[cfg(feature = "defmt")]
+ defmt::error!($($x)*);
+ }
+ };
+}
+
+#[cfg(feature = "defmt")]
+macro_rules! unwrap {
+ ($($x:tt)*) => {
+ defmt::unwrap!($($x)*)
+ };
}
#[cfg(not(feature = "defmt"))]
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 8fc16a3b..07509aef 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -6,7 +6,6 @@ use core::sync::atomic::{compiler_fence, Ordering};
use embassy::util::Unborrow;
use embassy_extras::unborrow;
-use crate::fmt::{unreachable, *};
use crate::gpio::sealed::Pin as _;
use crate::gpio::OptionalPin as GpioOptionalPin;
use crate::interrupt::Interrupt;
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index 882db9d8..42bf8f41 100644
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -10,7 +10,6 @@ use embassy::util::{AtomicWaker, DropBomb, Unborrow};
use embassy_extras::unborrow;
use futures::future::poll_fn;
-use crate::fmt::{assert, assert_eq, *};
use crate::gpio::sealed::Pin as _;
use crate::gpio::{self, Pin as GpioPin};
use crate::pac;
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index b5e9afbc..47d7c5f9 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -11,10 +11,10 @@ use embassy_extras::unborrow;
use futures::future::poll_fn;
use traits::spi::FullDuplex;
+use crate::gpio;
use crate::gpio::sealed::Pin as _;
use crate::gpio::{OptionalPin, Pin as GpioPin};
use crate::interrupt::Interrupt;
-use crate::{fmt::*, gpio};
use crate::{pac, util::slice_in_ram_or};
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 160868d7..5f3c5157 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -18,10 +18,10 @@ use futures::future::poll_fn;
use traits::i2c::I2c;
use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
+use crate::gpio;
use crate::gpio::Pin as GpioPin;
use crate::pac;
use crate::util::{slice_in_ram, slice_in_ram_or};
-use crate::{fmt::*, gpio};
pub enum Frequency {
#[doc = "26738688: 100 kbps"]
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 2f6d1a39..de093c7f 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -13,7 +13,6 @@ use embassy_extras::unborrow;
use futures::future::poll_fn;
use crate::chip::EASY_DMA_SIZE;
-use crate::fmt::{assert, panic, *};
use crate::gpio::sealed::Pin as _;
use crate::gpio::{self, OptionalPin as GpioOptionalPin, Pin as GpioPin};
use crate::interrupt::Interrupt;