diff options
| author | sander <[email protected]> | 2023-03-30 14:37:51 +0200 |
|---|---|---|
| committer | sander <[email protected]> | 2023-03-30 14:37:51 +0200 |
| commit | 6b2aaacf830d69fcb05f9611d3780f56b4ae82bc (patch) | |
| tree | a6e4d7628cd5153bbfd122b902a598b0862feeb9 /tests | |
| parent | ba9afbc26d06ab38065cbff5b17a7f76db297ad4 (diff) | |
| parent | 754bb802ba377c19be97d092c4b2afe542de20b5 (diff) | |
Update embassy
Merge commit '9dd3719f09835f646e3a8f3abaa33726a1e3f9ca'
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/src/bin/spi_async.rs | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/tests/rp/src/bin/spi_async.rs b/tests/rp/src/bin/spi_async.rs index 6c85ef60a..2e22c9de7 100644 --- a/tests/rp/src/bin/spi_async.rs +++ b/tests/rp/src/bin/spi_async.rs | |||
| @@ -1,3 +1,6 @@ | |||
| 1 | //! Make sure to connect GPIO pins 3 (`PIN_3`) and 4 (`PIN_4`) together | ||
| 2 | //! to run this test. | ||
| 3 | //! | ||
| 1 | #![no_std] | 4 | #![no_std] |
| 2 | #![no_main] | 5 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 6 | #![feature(type_alias_impl_trait)] |
| @@ -18,10 +21,63 @@ async fn main(_spawner: Spawner) { | |||
| 18 | 21 | ||
| 19 | let mut spi = Spi::new(p.SPI0, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); | 22 | let mut spi = Spi::new(p.SPI0, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); |
| 20 | 23 | ||
| 21 | let tx_buf = [1_u8, 2, 3, 4, 5, 6]; | 24 | // equal rx & tx buffers |
| 22 | let mut rx_buf = [0_u8; 6]; | 25 | { |
| 23 | spi.transfer(&mut rx_buf, &tx_buf).await.unwrap(); | 26 | let tx_buf = [1_u8, 2, 3, 4, 5, 6]; |
| 24 | assert_eq!(rx_buf, tx_buf); | 27 | let mut rx_buf = [0_u8; 6]; |
| 28 | spi.transfer(&mut rx_buf, &tx_buf).await.unwrap(); | ||
| 29 | assert_eq!(rx_buf, tx_buf); | ||
| 30 | } | ||
| 31 | |||
| 32 | // tx > rx buffer | ||
| 33 | { | ||
| 34 | let tx_buf = [7_u8, 8, 9, 10, 11, 12]; | ||
| 35 | |||
| 36 | let mut rx_buf = [0_u8; 3]; | ||
| 37 | spi.transfer(&mut rx_buf, &tx_buf).await.unwrap(); | ||
| 38 | assert_eq!(rx_buf, tx_buf[..3]); | ||
| 39 | |||
| 40 | defmt::info!("tx > rx buffer - OK"); | ||
| 41 | } | ||
| 42 | |||
| 43 | // we make sure to that clearing FIFO works after the uneven buffers | ||
| 44 | |||
| 45 | // equal rx & tx buffers | ||
| 46 | { | ||
| 47 | let tx_buf = [13_u8, 14, 15, 16, 17, 18]; | ||
| 48 | let mut rx_buf = [0_u8; 6]; | ||
| 49 | spi.transfer(&mut rx_buf, &tx_buf).await.unwrap(); | ||
| 50 | assert_eq!(rx_buf, tx_buf); | ||
| 51 | |||
| 52 | defmt::info!("buffer rx length == tx length - OK"); | ||
| 53 | } | ||
| 54 | |||
| 55 | // rx > tx buffer | ||
| 56 | { | ||
| 57 | let tx_buf = [19_u8, 20, 21]; | ||
| 58 | let mut rx_buf = [0_u8; 6]; | ||
| 59 | |||
| 60 | // we should have written dummy data to tx buffer to sync clock. | ||
| 61 | spi.transfer(&mut rx_buf, &tx_buf).await.unwrap(); | ||
| 62 | |||
| 63 | assert_eq!( | ||
| 64 | rx_buf[..3], | ||
| 65 | tx_buf, | ||
| 66 | "only the first 3 TX bytes should have been received in the RX buffer" | ||
| 67 | ); | ||
| 68 | assert_eq!(rx_buf[3..], [0, 0, 0], "the rest of the RX bytes should be empty"); | ||
| 69 | defmt::info!("buffer rx length > tx length - OK"); | ||
| 70 | } | ||
| 71 | |||
| 72 | // equal rx & tx buffers | ||
| 73 | { | ||
| 74 | let tx_buf = [22_u8, 23, 24, 25, 26, 27]; | ||
| 75 | let mut rx_buf = [0_u8; 6]; | ||
| 76 | spi.transfer(&mut rx_buf, &tx_buf).await.unwrap(); | ||
| 77 | |||
| 78 | assert_eq!(rx_buf, tx_buf); | ||
| 79 | defmt::info!("buffer rx length = tx length - OK"); | ||
| 80 | } | ||
| 25 | 81 | ||
| 26 | info!("Test OK"); | 82 | info!("Test OK"); |
| 27 | cortex_m::asm::bkpt(); | 83 | cortex_m::asm::bkpt(); |
