diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-02-28 22:05:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-02-28 22:05:37 +0100 |
| commit | 7433dc1039fb16bdadda401a22e1a0c3db4eafc9 (patch) | |
| tree | df31216acdabd858599400acd44da0bb7716d2c8 /embassy-nrf-examples/src | |
| parent | 962fb95ff088cdf747291e72cbf6aa8f1bd57ebc (diff) | |
Port qspi to PeripheralMutex
Diffstat (limited to 'embassy-nrf-examples/src')
| -rw-r--r-- | embassy-nrf-examples/src/bin/qspi.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/embassy-nrf-examples/src/bin/qspi.rs b/embassy-nrf-examples/src/bin/qspi.rs index 850681d7c..790dedc91 100644 --- a/embassy-nrf-examples/src/bin/qspi.rs +++ b/embassy-nrf-examples/src/bin/qspi.rs | |||
| @@ -8,6 +8,7 @@ use example_common::*; | |||
| 8 | 8 | ||
| 9 | use cortex_m_rt::entry; | 9 | use cortex_m_rt::entry; |
| 10 | use defmt::{assert_eq, panic}; | 10 | use defmt::{assert_eq, panic}; |
| 11 | use futures::pin_mut; | ||
| 11 | use nrf52840_hal::gpio; | 12 | use nrf52840_hal::gpio; |
| 12 | 13 | ||
| 13 | use embassy::executor::{task, Executor}; | 14 | use embassy::executor::{task, Executor}; |
| @@ -69,22 +70,32 @@ async fn run() { | |||
| 69 | }; | 70 | }; |
| 70 | 71 | ||
| 71 | let irq = interrupt::take!(QSPI); | 72 | let irq = interrupt::take!(QSPI); |
| 72 | let mut q = qspi::Qspi::new(p.QSPI, irq, config); | 73 | let q = qspi::Qspi::new(p.QSPI, irq, config); |
| 74 | pin_mut!(q); | ||
| 73 | 75 | ||
| 74 | let mut id = [1; 3]; | 76 | let mut id = [1; 3]; |
| 75 | q.custom_instruction(0x9F, &[], &mut id).await.unwrap(); | 77 | q.as_mut() |
| 78 | .custom_instruction(0x9F, &[], &mut id) | ||
| 79 | .await | ||
| 80 | .unwrap(); | ||
| 76 | info!("id: {}", id); | 81 | info!("id: {}", id); |
| 77 | 82 | ||
| 78 | // Read status register | 83 | // Read status register |
| 79 | let mut status = [0; 1]; | 84 | let mut status = [0; 1]; |
| 80 | q.custom_instruction(0x05, &[], &mut status).await.unwrap(); | 85 | q.as_mut() |
| 86 | .custom_instruction(0x05, &[], &mut status) | ||
| 87 | .await | ||
| 88 | .unwrap(); | ||
| 81 | 89 | ||
| 82 | info!("status: {:?}", status[0]); | 90 | info!("status: {:?}", status[0]); |
| 83 | 91 | ||
| 84 | if status[0] & 0x40 == 0 { | 92 | if status[0] & 0x40 == 0 { |
| 85 | status[0] |= 0x40; | 93 | status[0] |= 0x40; |
| 86 | 94 | ||
| 87 | q.custom_instruction(0x01, &status, &mut []).await.unwrap(); | 95 | q.as_mut() |
| 96 | .custom_instruction(0x01, &status, &mut []) | ||
| 97 | .await | ||
| 98 | .unwrap(); | ||
| 88 | 99 | ||
| 89 | info!("enabled quad in status"); | 100 | info!("enabled quad in status"); |
| 90 | } | 101 | } |
| @@ -95,19 +106,19 @@ async fn run() { | |||
| 95 | 106 | ||
| 96 | for i in 0..8 { | 107 | for i in 0..8 { |
| 97 | info!("page {:?}: erasing... ", i); | 108 | info!("page {:?}: erasing... ", i); |
| 98 | q.erase(i * PAGE_SIZE).await.unwrap(); | 109 | q.as_mut().erase(i * PAGE_SIZE).await.unwrap(); |
| 99 | 110 | ||
| 100 | for j in 0..PAGE_SIZE { | 111 | for j in 0..PAGE_SIZE { |
| 101 | buf.0[j] = pattern((j + i * PAGE_SIZE) as u32); | 112 | buf.0[j] = pattern((j + i * PAGE_SIZE) as u32); |
| 102 | } | 113 | } |
| 103 | 114 | ||
| 104 | info!("programming..."); | 115 | info!("programming..."); |
| 105 | q.write(i * PAGE_SIZE, &buf.0).await.unwrap(); | 116 | q.as_mut().write(i * PAGE_SIZE, &buf.0).await.unwrap(); |
| 106 | } | 117 | } |
| 107 | 118 | ||
| 108 | for i in 0..8 { | 119 | for i in 0..8 { |
| 109 | info!("page {:?}: reading... ", i); | 120 | info!("page {:?}: reading... ", i); |
| 110 | q.read(i * PAGE_SIZE, &mut buf.0).await.unwrap(); | 121 | q.as_mut().read(i * PAGE_SIZE, &mut buf.0).await.unwrap(); |
| 111 | 122 | ||
| 112 | info!("verifying..."); | 123 | info!("verifying..."); |
| 113 | for j in 0..PAGE_SIZE { | 124 | for j in 0..PAGE_SIZE { |
