diff options
Diffstat (limited to 'examples/mcxa/src/bin/dma_wrap_transfer.rs')
| -rw-r--r-- | examples/mcxa/src/bin/dma_wrap_transfer.rs | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/examples/mcxa/src/bin/dma_wrap_transfer.rs b/examples/mcxa/src/bin/dma_wrap_transfer.rs index 82936d9d0..7fea4bf76 100644 --- a/examples/mcxa/src/bin/dma_wrap_transfer.rs +++ b/examples/mcxa/src/bin/dma_wrap_transfer.rs | |||
| @@ -16,6 +16,7 @@ use embassy_mcxa::dma::{DmaCh0InterruptHandler, DmaChannel}; | |||
| 16 | use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx}; | 16 | use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx}; |
| 17 | use embassy_mcxa::{bind_interrupts, pac}; | 17 | use embassy_mcxa::{bind_interrupts, pac}; |
| 18 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 18 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| 19 | use core::fmt::Write as _; | ||
| 19 | 20 | ||
| 20 | // Bind DMA channel 0 interrupt using Embassy-style macro | 21 | // Bind DMA channel 0 interrupt using Embassy-style macro |
| 21 | bind_interrupts!(struct Irqs { | 22 | bind_interrupts!(struct Irqs { |
| @@ -29,38 +30,9 @@ struct AlignedSrc([u32; 4]); | |||
| 29 | static mut SRC: AlignedSrc = AlignedSrc([0; 4]); | 30 | static mut SRC: AlignedSrc = AlignedSrc([0; 4]); |
| 30 | static mut DST: [u32; 8] = [0; 8]; | 31 | static mut DST: [u32; 8] = [0; 8]; |
| 31 | 32 | ||
| 32 | /// Helper to write a u32 as decimal ASCII to UART | ||
| 33 | fn write_u32(tx: &mut LpuartTx<'_, Blocking>, val: u32) { | ||
| 34 | let mut buf = [0u8; 10]; | ||
| 35 | let mut n = val; | ||
| 36 | let mut i = buf.len(); | ||
| 37 | |||
| 38 | if n == 0 { | ||
| 39 | tx.blocking_write(b"0").ok(); | ||
| 40 | return; | ||
| 41 | } | ||
| 42 | |||
| 43 | while n > 0 { | ||
| 44 | i -= 1; | ||
| 45 | buf[i] = b'0' + (n % 10) as u8; | ||
| 46 | n /= 10; | ||
| 47 | } | ||
| 48 | |||
| 49 | tx.blocking_write(&buf[i..]).ok(); | ||
| 50 | } | ||
| 51 | |||
| 52 | /// Helper to print a buffer to UART | 33 | /// Helper to print a buffer to UART |
| 53 | fn print_buffer(tx: &mut LpuartTx<'_, Blocking>, buf_ptr: *const u32, len: usize) { | 34 | fn print_buffer(tx: &mut LpuartTx<'_, Blocking>, buf_ptr: *const u32, len: usize) { |
| 54 | tx.blocking_write(b"[").ok(); | 35 | write!(tx, "{:?}", unsafe { core::slice::from_raw_parts(buf_ptr, len) }).ok(); |
| 55 | unsafe { | ||
| 56 | for i in 0..len { | ||
| 57 | write_u32(tx, *buf_ptr.add(i)); | ||
| 58 | if i < len - 1 { | ||
| 59 | tx.blocking_write(b", ").ok(); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | tx.blocking_write(b"]").ok(); | ||
| 64 | } | 36 | } |
| 65 | 37 | ||
| 66 | #[embassy_executor::main] | 38 | #[embassy_executor::main] |
