Skip to content

Commit

Permalink
Fix defmt compatibility (#2017)
Browse files Browse the repository at this point in the history
* Fix defmt compatibility

* Update tests to cover macros
  • Loading branch information
bugadani committed Aug 28, 2024
1 parent 61bb240 commit 84a0600
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ macro_rules! dma_circular_buffers_chunk_size {
macro_rules! dma_descriptors_chunk_size {
($tx_size:expr, $rx_size:expr, $chunk_size:expr) => {{
// these will check for size at compile time
const _: () = assert!($chunk_size <= 4092, "chunk size must be <= 4092");
const _: () = assert!($chunk_size > 0, "chunk size must be > 0");
const _: () = ::core::assert!($chunk_size <= 4092, "chunk size must be <= 4092");
const _: () = ::core::assert!($chunk_size > 0, "chunk size must be > 0");

static mut TX_DESCRIPTORS: [$crate::dma::DmaDescriptor;
($tx_size + $chunk_size - 1) / $chunk_size] =
Expand Down Expand Up @@ -473,8 +473,8 @@ macro_rules! dma_descriptors_chunk_size {
macro_rules! dma_circular_descriptors_chunk_size {
($tx_size:expr, $rx_size:expr, $chunk_size:expr) => {{
// these will check for size at compile time
const _: () = assert!($chunk_size <= 4092, "chunk size must be <= 4092");
const _: () = assert!($chunk_size > 0, "chunk size must be > 0");
const _: () = ::core::assert!($chunk_size <= 4092, "chunk size must be <= 4092");
const _: () = ::core::assert!($chunk_size > 0, "chunk size must be > 0");

const tx_descriptor_len: usize = if $tx_size > $chunk_size * 2 {
($tx_size + $chunk_size - 1) / $chunk_size
Expand Down
5 changes: 5 additions & 0 deletions hil-test/tests/i2s_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ async fn writer(tx_buffer: &'static mut [u8], i2s_tx: I2sTx<'static, I2S0, DmaCh
#[cfg(test)]
#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())]
mod tests {
// defmt::* is load-bearing, it ensures that the assert in dma_buffers! is not
// using defmt's non-const assert. Doing so would result in a compile error.
#[allow(unused_imports)]
use defmt::{assert_eq, *};

use super::*;

#[init]
Expand Down
5 changes: 4 additions & 1 deletion hil-test/tests/spi_half_duplex_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ struct Context {
#[cfg(test)]
#[embedded_test::tests]
mod tests {
use defmt::assert_eq;
// defmt::* is load-bearing, it ensures that the assert in dma_buffers! is not
// using defmt's non-const assert. Doing so would result in a compile error.
#[allow(unused_imports)]
use defmt::{assert_eq, *};

use super::*;

Expand Down

0 comments on commit 84a0600

Please sign in to comment.