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 /embassy-stm32/src | |
| parent | 4dda7be96841430c3aed2f014644b0b65cff0ef2 (diff) | |
fmt: make all macros `macro_rules` so scoping is consistent.
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/dac/v2.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/v2.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/fmt.rs | 191 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/h7/mod.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/h7/pll.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/sdmmc/v2.rs | 7 |
6 files changed, 149 insertions, 53 deletions
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 |
