aboutsummaryrefslogtreecommitdiff
path: root/tests/rp/src/bin/dma_copy_async.rs
blob: 3dcf4f4d8a2627b3b9f08257982b7f66645589f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#![no_std]
#![no_main]
#[cfg(feature = "rp2040")]
teleprobe_meta::target!(b"rpi-pico");
#[cfg(feature = "rp235xb")]
teleprobe_meta::target!(b"pimoroni-pico-plus-2");

use defmt::{assert_eq, *};
use embassy_executor::Spawner;
use embassy_rp::dma::copy;
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let p = embassy_rp::init(Default::default());
    info!("Hello World!");

    // Check `u8` copy
    {
        let data: [u8; 2] = [0xC0, 0xDE];
        let mut buf = [0; 2];
        unsafe { copy(p.DMA_CH0, &data, &mut buf).await };
        assert_eq!(buf, data);
    }

    // Check `u16` copy
    {
        let data: [u16; 2] = [0xC0BE, 0xDEAD];
        let mut buf = [0; 2];
        unsafe { copy(p.DMA_CH1, &data, &mut buf).await };
        assert_eq!(buf, data);
    }

    // Check `u32` copy
    {
        let data: [u32; 2] = [0xC0BEDEAD, 0xDEADAAFF];
        let mut buf = [0; 2];
        unsafe { copy(p.DMA_CH2, &data, &mut buf).await };
        assert_eq!(buf, data);
    }

    info!("Test OK");
    cortex_m::asm::bkpt();
}