diff options
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/rpi-pico-w/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/rpi-pico-w/src/main.rs | 60 | ||||
| -rw-r--r-- | examples/rpi-pico-w/src/pio.rs | 61 | ||||
| -rw-r--r-- | src/bus.rs | 104 | ||||
| -rw-r--r-- | src/lib.rs | 7 |
6 files changed, 58 insertions, 177 deletions
diff --git a/Cargo.toml b/Cargo.toml index 6e3237448..3bdeb0cfb 100644 --- a/Cargo.toml +++ b/Cargo.toml | |||
| @@ -25,5 +25,4 @@ cortex-m-rt = "0.7.0" | |||
| 25 | futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } | 25 | futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } |
| 26 | 26 | ||
| 27 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.9" } | 27 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.9" } |
| 28 | embedded-hal-async = { version = "0.2.0-alpha.0" } | ||
| 29 | num_enum = { version = "0.5.7", default-features = false } | 28 | num_enum = { version = "0.5.7", default-features = false } |
diff --git a/examples/rpi-pico-w/Cargo.toml b/examples/rpi-pico-w/Cargo.toml index 0d789a932..17b4214d8 100644 --- a/examples/rpi-pico-w/Cargo.toml +++ b/examples/rpi-pico-w/Cargo.toml | |||
| @@ -47,8 +47,6 @@ futures = { version = "0.3.17", default-features = false, features = [ | |||
| 47 | pio-proc = "0.2" | 47 | pio-proc = "0.2" |
| 48 | pio = "0.2.1" | 48 | pio = "0.2.1" |
| 49 | 49 | ||
| 50 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.9" } | ||
| 51 | embedded-hal-async = { version = "0.2.0-alpha.0" } | ||
| 52 | embedded-io = { version = "0.4.0", features = ["async", "defmt"] } | 50 | embedded-io = { version = "0.4.0", features = ["async", "defmt"] } |
| 53 | heapless = "0.7.15" | 51 | heapless = "0.7.15" |
| 54 | 52 | ||
diff --git a/examples/rpi-pico-w/src/main.rs b/examples/rpi-pico-w/src/main.rs index 3563d165a..f30a20bac 100644 --- a/examples/rpi-pico-w/src/main.rs +++ b/examples/rpi-pico-w/src/main.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | #![feature(async_fn_in_trait)] | 4 | #![feature(async_fn_in_trait)] |
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | mod pio; | 7 | mod pio; |
| 8 | 8 | ||
| 9 | use core::convert::Infallible; | 9 | use core::slice; |
| 10 | use core::str::from_utf8; | 10 | use core::str::from_utf8; |
| 11 | 11 | ||
| 12 | use defmt::*; | 12 | use defmt::*; |
| @@ -16,8 +16,6 @@ use embassy_net::{Config, Stack, StackResources}; | |||
| 16 | use embassy_rp::gpio::{Flex, Level, Output}; | 16 | use embassy_rp::gpio::{Flex, Level, Output}; |
| 17 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_24, PIN_25, PIN_29}; | 17 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_24, PIN_25, PIN_29}; |
| 18 | use embassy_rp::pio::{Pio0, PioPeripherial, PioStateMachineInstance, Sm0}; | 18 | use embassy_rp::pio::{Pio0, PioPeripherial, PioStateMachineInstance, Sm0}; |
| 19 | use embedded_hal_1::spi::ErrorType; | ||
| 20 | use embedded_hal_async::spi::{ExclusiveDevice, SpiBusFlush, SpiBusRead, SpiBusWrite}; | ||
| 21 | use embedded_io::asynch::Write; | 19 | use embedded_io::asynch::Write; |
| 22 | use static_cell::StaticCell; | 20 | use static_cell::StaticCell; |
| 23 | use {defmt_rtt as _, panic_probe as _}; | 21 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -37,7 +35,7 @@ async fn wifi_task( | |||
| 37 | runner: cyw43::Runner< | 35 | runner: cyw43::Runner< |
| 38 | 'static, | 36 | 'static, |
| 39 | Output<'static, PIN_23>, | 37 | Output<'static, PIN_23>, |
| 40 | ExclusiveDevice<PioSpi<PioStateMachineInstance<Pio0, Sm0>, DMA_CH0>, Output<'static, PIN_25>>, | 38 | PioSpi<PIN_25, PioStateMachineInstance<Pio0, Sm0>, DMA_CH0>, |
| 41 | >, | 39 | >, |
| 42 | ) -> ! { | 40 | ) -> ! { |
| 43 | runner.run().await | 41 | runner.run().await |
| @@ -75,8 +73,7 @@ async fn main(spawner: Spawner) { | |||
| 75 | 73 | ||
| 76 | let (_, sm, _, _, _) = p.PIO0.split(); | 74 | let (_, sm, _, _, _) = p.PIO0.split(); |
| 77 | let dma = p.DMA_CH0; | 75 | let dma = p.DMA_CH0; |
| 78 | let bus = PioSpi::new(sm, p.PIN_24, p.PIN_29, dma); | 76 | let spi = PioSpi::new(sm, cs, p.PIN_24, p.PIN_29, dma); |
| 79 | let spi = ExclusiveDevice::new(bus, cs); | ||
| 80 | 77 | ||
| 81 | let state = singleton!(cyw43::State::new()); | 78 | let state = singleton!(cyw43::State::new()); |
| 82 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | 79 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; |
| @@ -146,7 +143,6 @@ async fn main(spawner: Spawner) { | |||
| 146 | 143 | ||
| 147 | info!("rxd {}", from_utf8(&buf[..n]).unwrap()); | 144 | info!("rxd {}", from_utf8(&buf[..n]).unwrap()); |
| 148 | 145 | ||
| 149 | |||
| 150 | match socket.write_all(&buf[..n]).await { | 146 | match socket.write_all(&buf[..n]).await { |
| 151 | Ok(()) => {} | 147 | Ok(()) => {} |
| 152 | Err(e) => { | 148 | Err(e) => { |
| @@ -168,31 +164,13 @@ struct MySpi { | |||
| 168 | /// - IRQ | 164 | /// - IRQ |
| 169 | /// - strap to set to gSPI mode on boot. | 165 | /// - strap to set to gSPI mode on boot. |
| 170 | dio: Flex<'static, PIN_24>, | 166 | dio: Flex<'static, PIN_24>, |
| 171 | } | ||
| 172 | 167 | ||
| 173 | impl ErrorType for MySpi { | 168 | /// Chip select |
| 174 | type Error = Infallible; | 169 | cs: Output<'static, PIN_25>, |
| 175 | } | 170 | } |
| 176 | 171 | ||
| 177 | impl cyw43::SpiBusCyw43<u32> for MySpi { | 172 | impl MySpi { |
| 178 | async fn cmd_write<'a>(&'a mut self, write: &'a [u32]) -> Result<(), Self::Error> { | 173 | async fn read(&mut self, words: &mut [u32]) { |
| 179 | self.write(write).await | ||
| 180 | } | ||
| 181 | |||
| 182 | async fn cmd_read<'a>(&'a mut self, write: &'a [u32], read: &'a mut [u32]) -> Result<(), Self::Error> { | ||
| 183 | self.write(write).await?; | ||
| 184 | self.read(read).await | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | impl SpiBusFlush for MySpi { | ||
| 189 | async fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 190 | Ok(()) | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | impl SpiBusRead<u32> for MySpi { | ||
| 195 | async fn read(&mut self, words: &mut [u32]) -> Result<(), Self::Error> { | ||
| 196 | self.dio.set_as_input(); | 174 | self.dio.set_as_input(); |
| 197 | for word in words { | 175 | for word in words { |
| 198 | let mut w = 0; | 176 | let mut w = 0; |
| @@ -210,13 +188,9 @@ impl SpiBusRead<u32> for MySpi { | |||
| 210 | } | 188 | } |
| 211 | *word = w | 189 | *word = w |
| 212 | } | 190 | } |
| 213 | |||
| 214 | Ok(()) | ||
| 215 | } | 191 | } |
| 216 | } | ||
| 217 | 192 | ||
| 218 | impl SpiBusWrite<u32> for MySpi { | 193 | async fn write(&mut self, words: &[u32]) { |
| 219 | async fn write(&mut self, words: &[u32]) -> Result<(), Self::Error> { | ||
| 220 | self.dio.set_as_output(); | 194 | self.dio.set_as_output(); |
| 221 | for word in words { | 195 | for word in words { |
| 222 | let mut word = *word; | 196 | let mut word = *word; |
| @@ -238,6 +212,20 @@ impl SpiBusWrite<u32> for MySpi { | |||
| 238 | self.clk.set_low(); | 212 | self.clk.set_low(); |
| 239 | 213 | ||
| 240 | self.dio.set_as_input(); | 214 | self.dio.set_as_input(); |
| 241 | Ok(()) | 215 | } |
| 216 | } | ||
| 217 | |||
| 218 | impl cyw43::SpiBusCyw43 for MySpi { | ||
| 219 | async fn cmd_write(&mut self, write: &[u32]) { | ||
| 220 | self.cs.set_low(); | ||
| 221 | self.write(write).await; | ||
| 222 | self.cs.set_high(); | ||
| 223 | } | ||
| 224 | |||
| 225 | async fn cmd_read(&mut self, write: u32, read: &mut [u32]) { | ||
| 226 | self.cs.set_low(); | ||
| 227 | self.write(slice::from_ref(&write)).await; | ||
| 228 | self.read(read).await; | ||
| 229 | self.cs.set_high(); | ||
| 242 | } | 230 | } |
| 243 | } | 231 | } |
diff --git a/examples/rpi-pico-w/src/pio.rs b/examples/rpi-pico-w/src/pio.rs index 1bf304d5d..896fd0457 100644 --- a/examples/rpi-pico-w/src/pio.rs +++ b/examples/rpi-pico-w/src/pio.rs | |||
| @@ -2,34 +2,27 @@ use core::slice; | |||
| 2 | 2 | ||
| 3 | use cyw43::SpiBusCyw43; | 3 | use cyw43::SpiBusCyw43; |
| 4 | use embassy_rp::dma::Channel; | 4 | use embassy_rp::dma::Channel; |
| 5 | use embassy_rp::gpio::{Drive, Pin, Pull, SlewRate}; | 5 | use embassy_rp::gpio::{Drive, Output, Pin, Pull, SlewRate}; |
| 6 | use embassy_rp::pio::{PioStateMachine, ShiftDirection}; | 6 | use embassy_rp::pio::{PioStateMachine, ShiftDirection}; |
| 7 | use embassy_rp::relocate::RelocatedProgram; | 7 | use embassy_rp::relocate::RelocatedProgram; |
| 8 | use embassy_rp::{pio_instr_util, Peripheral}; | 8 | use embassy_rp::{pio_instr_util, Peripheral}; |
| 9 | use embedded_hal_1::spi::ErrorType; | ||
| 10 | use embedded_hal_async::spi::SpiBusFlush; | ||
| 11 | use pio::Wrap; | 9 | use pio::Wrap; |
| 12 | use pio_proc::pio_asm; | 10 | use pio_proc::pio_asm; |
| 13 | 11 | ||
| 14 | pub struct PioSpi<SM, DMA> { | 12 | pub struct PioSpi<CS: Pin, SM, DMA> { |
| 15 | // cs: Output<'static, AnyPin>, | 13 | cs: Output<'static, CS>, |
| 16 | sm: SM, | 14 | sm: SM, |
| 17 | dma: DMA, | 15 | dma: DMA, |
| 18 | wrap_target: u8, | 16 | wrap_target: u8, |
| 19 | } | 17 | } |
| 20 | 18 | ||
| 21 | impl<SM, DMA> PioSpi<SM, DMA> | 19 | impl<CS, SM, DMA> PioSpi<CS, SM, DMA> |
| 22 | where | 20 | where |
| 23 | SM: PioStateMachine, | 21 | SM: PioStateMachine, |
| 24 | DMA: Channel, | 22 | DMA: Channel, |
| 23 | CS: Pin, | ||
| 25 | { | 24 | { |
| 26 | pub fn new<DIO, CLK>( | 25 | pub fn new<DIO, CLK>(mut sm: SM, cs: Output<'static, CS>, dio: DIO, clk: CLK, dma: DMA) -> Self |
| 27 | mut sm: SM, | ||
| 28 | // cs: AnyPin, | ||
| 29 | dio: DIO, | ||
| 30 | clk: CLK, | ||
| 31 | dma: DMA, | ||
| 32 | ) -> Self | ||
| 33 | where | 26 | where |
| 34 | DIO: Pin, | 27 | DIO: Pin, |
| 35 | CLK: Pin, | 28 | CLK: Pin, |
| @@ -105,7 +98,7 @@ where | |||
| 105 | pio_instr_util::set_pin(&mut sm, 0); | 98 | pio_instr_util::set_pin(&mut sm, 0); |
| 106 | 99 | ||
| 107 | Self { | 100 | Self { |
| 108 | // cs: Output::new(cs, Level::High), | 101 | cs, |
| 109 | sm, | 102 | sm, |
| 110 | dma, | 103 | dma, |
| 111 | wrap_target: target, | 104 | wrap_target: target, |
| @@ -156,43 +149,21 @@ where | |||
| 156 | } | 149 | } |
| 157 | } | 150 | } |
| 158 | 151 | ||
| 159 | #[derive(Debug)] | 152 | impl<CS, SM, DMA> SpiBusCyw43 for PioSpi<CS, SM, DMA> |
| 160 | pub enum PioError {} | ||
| 161 | |||
| 162 | impl embedded_hal_async::spi::Error for PioError { | ||
| 163 | fn kind(&self) -> embedded_hal_1::spi::ErrorKind { | ||
| 164 | embedded_hal_1::spi::ErrorKind::Other | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | impl<SM, DMA> ErrorType for PioSpi<SM, DMA> | ||
| 169 | where | ||
| 170 | SM: PioStateMachine, | ||
| 171 | { | ||
| 172 | type Error = PioError; | ||
| 173 | } | ||
| 174 | |||
| 175 | impl<SM, DMA> SpiBusFlush for PioSpi<SM, DMA> | ||
| 176 | where | ||
| 177 | SM: PioStateMachine, | ||
| 178 | { | ||
| 179 | async fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 180 | Ok(()) | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | impl<SM, DMA> SpiBusCyw43<u32> for PioSpi<SM, DMA> | ||
| 185 | where | 153 | where |
| 154 | CS: Pin, | ||
| 186 | SM: PioStateMachine, | 155 | SM: PioStateMachine, |
| 187 | DMA: Channel, | 156 | DMA: Channel, |
| 188 | { | 157 | { |
| 189 | async fn cmd_write<'a>(&'a mut self, write: &'a [u32]) -> Result<(), Self::Error> { | 158 | async fn cmd_write(&mut self, write: & [u32]) { |
| 159 | self.cs.set_low(); | ||
| 190 | self.write(write).await; | 160 | self.write(write).await; |
| 191 | Ok(()) | 161 | self.cs.set_high(); |
| 192 | } | 162 | } |
| 193 | 163 | ||
| 194 | async fn cmd_read<'a>(&'a mut self, write: &'a [u32], read: &'a mut [u32]) -> Result<(), Self::Error> { | 164 | async fn cmd_read(&mut self, write: u32, read: & mut [u32]) { |
| 195 | self.cmd_read(write[0], read).await; | 165 | self.cs.set_low(); |
| 196 | Ok(()) | 166 | self.cmd_read(write, read).await; |
| 167 | self.cs.set_high(); | ||
| 197 | } | 168 | } |
| 198 | } | 169 | } |
diff --git a/src/bus.rs b/src/bus.rs index e4f9a69bb..90990f35a 100644 --- a/src/bus.rs +++ b/src/bus.rs | |||
| @@ -2,22 +2,22 @@ use core::slice; | |||
| 2 | 2 | ||
| 3 | use embassy_time::{Duration, Timer}; | 3 | use embassy_time::{Duration, Timer}; |
| 4 | use embedded_hal_1::digital::OutputPin; | 4 | use embedded_hal_1::digital::OutputPin; |
| 5 | use embedded_hal_1::spi::ErrorType; | ||
| 6 | use embedded_hal_async::spi::{transaction, SpiDevice}; | ||
| 7 | use futures::FutureExt; | 5 | use futures::FutureExt; |
| 8 | 6 | ||
| 9 | use crate::consts::*; | 7 | use crate::consts::*; |
| 10 | 8 | ||
| 11 | /// Custom Spi Trait that _only_ supports the bus operation of the cyw43 | 9 | /// Custom Spi Trait that _only_ supports the bus operation of the cyw43 |
| 12 | pub trait SpiBusCyw43<Word: 'static + Copy>: ErrorType { | 10 | /// Implementors are expected to hold the CS pin low during an operation. |
| 11 | pub trait SpiBusCyw43 { | ||
| 13 | /// Issues a write command on the bus | 12 | /// Issues a write command on the bus |
| 14 | /// Frist 32 bits of `word` are expected to be a cmd word | 13 | /// First 32 bits of `word` are expected to be a cmd word |
| 15 | async fn cmd_write<'a>(&'a mut self, write: &'a [Word]) -> Result<(), Self::Error>; | 14 | async fn cmd_write(&mut self, write: &[u32]); |
| 16 | 15 | ||
| 17 | /// Issues a read command on the bus | 16 | /// Issues a read command on the bus |
| 18 | /// `write` is expected to be a 32 bit cmd word | 17 | /// `write` is expected to be a 32 bit cmd word |
| 19 | /// `read` will contain the response of the device | 18 | /// `read` will contain the response of the device |
| 20 | async fn cmd_read<'a>(&'a mut self, write: &'a [Word], read: &'a mut [Word]) -> Result<(), Self::Error>; | 19 | /// |
| 20 | async fn cmd_read(&mut self, write: u32, read: &mut [u32]); | ||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | pub(crate) struct Bus<PWR, SPI> { | 23 | pub(crate) struct Bus<PWR, SPI> { |
| @@ -29,8 +29,7 @@ pub(crate) struct Bus<PWR, SPI> { | |||
| 29 | impl<PWR, SPI> Bus<PWR, SPI> | 29 | impl<PWR, SPI> Bus<PWR, SPI> |
| 30 | where | 30 | where |
| 31 | PWR: OutputPin, | 31 | PWR: OutputPin, |
| 32 | SPI: SpiDevice, | 32 | SPI: SpiBusCyw43, |
| 33 | SPI::Bus: SpiBusCyw43<u32>, | ||
| 34 | { | 33 | { |
| 35 | pub(crate) fn new(pwr: PWR, spi: SPI) -> Self { | 34 | pub(crate) fn new(pwr: PWR, spi: SPI) -> Self { |
| 36 | Self { | 35 | Self { |
| @@ -87,14 +86,8 @@ where | |||
| 87 | pub async fn wlan_read(&mut self, buf: &mut [u32], len_in_u8: u32) { | 86 | pub async fn wlan_read(&mut self, buf: &mut [u32], len_in_u8: u32) { |
| 88 | let cmd = cmd_word(READ, INC_ADDR, FUNC_WLAN, 0, len_in_u8); | 87 | let cmd = cmd_word(READ, INC_ADDR, FUNC_WLAN, 0, len_in_u8); |
| 89 | let len_in_u32 = (len_in_u8 as usize + 3) / 4; | 88 | let len_in_u32 = (len_in_u8 as usize + 3) / 4; |
| 90 | transaction!(&mut self.spi, |bus| async { | 89 | |
| 91 | // bus.write(&[cmd]).await?; | 90 | self.spi.cmd_read(cmd, &mut buf[..len_in_u32]).await; |
| 92 | // bus.read(&mut buf[..len_in_u32]).await?; | ||
| 93 | bus.cmd_read(slice::from_ref(&cmd), &mut buf[..len_in_u32]).await?; | ||
| 94 | Ok(()) | ||
| 95 | }) | ||
| 96 | .await | ||
| 97 | .unwrap(); | ||
| 98 | } | 91 | } |
| 99 | 92 | ||
| 100 | pub async fn wlan_write(&mut self, buf: &[u32]) { | 93 | pub async fn wlan_write(&mut self, buf: &[u32]) { |
| @@ -104,15 +97,7 @@ where | |||
| 104 | cmd_buf[0] = cmd; | 97 | cmd_buf[0] = cmd; |
| 105 | cmd_buf[1..][..buf.len()].copy_from_slice(buf); | 98 | cmd_buf[1..][..buf.len()].copy_from_slice(buf); |
| 106 | 99 | ||
| 107 | transaction!(&mut self.spi, |bus| async { | 100 | self.spi.cmd_write(&cmd_buf).await; |
| 108 | // bus.write(&[cmd]).await?; | ||
| 109 | // bus.write(buf).await?; | ||
| 110 | |||
| 111 | bus.cmd_write(&cmd_buf).await?; | ||
| 112 | Ok(()) | ||
| 113 | }) | ||
| 114 | .await | ||
| 115 | .unwrap(); | ||
| 116 | } | 101 | } |
| 117 | 102 | ||
| 118 | #[allow(unused)] | 103 | #[allow(unused)] |
| @@ -136,22 +121,7 @@ where | |||
| 136 | 121 | ||
| 137 | let cmd = cmd_word(READ, INC_ADDR, FUNC_BACKPLANE, window_offs, len as u32); | 122 | let cmd = cmd_word(READ, INC_ADDR, FUNC_BACKPLANE, window_offs, len as u32); |
| 138 | 123 | ||
| 139 | transaction!(&mut self.spi, |bus| async { | 124 | self.spi.cmd_read(cmd, &mut buf[..(len + 3) / 4 + 1]).await; |
| 140 | // bus.write(&[cmd]).await?; | ||
| 141 | |||
| 142 | // // 4-byte response delay. | ||
| 143 | // let mut junk = [0; 1]; | ||
| 144 | // bus.read(&mut junk).await?; | ||
| 145 | |||
| 146 | // // Read data | ||
| 147 | // bus.read(&mut buf[..(len + 3) / 4]).await?; | ||
| 148 | |||
| 149 | bus.cmd_read(slice::from_ref(&cmd), &mut buf[..(len + 3) / 4 + 1]) | ||
| 150 | .await?; | ||
| 151 | Ok(()) | ||
| 152 | }) | ||
| 153 | .await | ||
| 154 | .unwrap(); | ||
| 155 | 125 | ||
| 156 | data[..len].copy_from_slice(&slice8_mut(&mut buf[1..])[..len]); | 126 | data[..len].copy_from_slice(&slice8_mut(&mut buf[1..])[..len]); |
| 157 | 127 | ||
| @@ -183,16 +153,7 @@ where | |||
| 183 | let cmd = cmd_word(WRITE, INC_ADDR, FUNC_BACKPLANE, window_offs, len as u32); | 153 | let cmd = cmd_word(WRITE, INC_ADDR, FUNC_BACKPLANE, window_offs, len as u32); |
| 184 | buf[0] = cmd; | 154 | buf[0] = cmd; |
| 185 | 155 | ||
| 186 | transaction!(&mut self.spi, |bus| async { | 156 | self.spi.cmd_write(&buf[..(len + 3) / 4 + 1]).await; |
| 187 | // bus.write(&[cmd]).await?; | ||
| 188 | // bus.write(&buf[..(len + 3) / 4]).await?; | ||
| 189 | |||
| 190 | bus.cmd_write(&buf[..(len + 3) / 4 + 1]).await?; | ||
| 191 | |||
| 192 | Ok(()) | ||
| 193 | }) | ||
| 194 | .await | ||
| 195 | .unwrap(); | ||
| 196 | 157 | ||
| 197 | // Advance ptr. | 158 | // Advance ptr. |
| 198 | addr += len as u32; | 159 | addr += len as u32; |
| @@ -307,19 +268,7 @@ where | |||
| 307 | let mut buf = [0; 2]; | 268 | let mut buf = [0; 2]; |
| 308 | let len = if func == FUNC_BACKPLANE { 2 } else { 1 }; | 269 | let len = if func == FUNC_BACKPLANE { 2 } else { 1 }; |
| 309 | 270 | ||
| 310 | transaction!(&mut self.spi, |bus| async { | 271 | self.spi.cmd_read(cmd, &mut buf[..len]).await; |
| 311 | // bus.write(&[cmd]).await?; | ||
| 312 | // if func == FUNC_BACKPLANE { | ||
| 313 | // // 4-byte response delay. | ||
| 314 | // bus.read(&mut buf).await?; | ||
| 315 | // } | ||
| 316 | // bus.read(&mut buf).await?; | ||
| 317 | |||
| 318 | bus.cmd_read(slice::from_ref(&cmd), &mut buf[..len]).await?; | ||
| 319 | Ok(()) | ||
| 320 | }) | ||
| 321 | .await | ||
| 322 | .unwrap(); | ||
| 323 | 272 | ||
| 324 | if func == FUNC_BACKPLANE { | 273 | if func == FUNC_BACKPLANE { |
| 325 | buf[1] | 274 | buf[1] |
| @@ -331,13 +280,7 @@ where | |||
| 331 | async fn writen(&mut self, func: u32, addr: u32, val: u32, len: u32) { | 280 | async fn writen(&mut self, func: u32, addr: u32, val: u32, len: u32) { |
| 332 | let cmd = cmd_word(WRITE, INC_ADDR, func, addr, len); | 281 | let cmd = cmd_word(WRITE, INC_ADDR, func, addr, len); |
| 333 | 282 | ||
| 334 | transaction!(&mut self.spi, |bus| async { | 283 | self.spi.cmd_write(&[cmd, val]).await; |
| 335 | // bus.write(&[cmd, val]).await?; | ||
| 336 | bus.cmd_write(&[cmd, val]).await?; | ||
| 337 | Ok(()) | ||
| 338 | }) | ||
| 339 | .await | ||
| 340 | .unwrap(); | ||
| 341 | } | 284 | } |
| 342 | 285 | ||
| 343 | async fn read32_swapped(&mut self, addr: u32) -> u32 { | 286 | async fn read32_swapped(&mut self, addr: u32) -> u32 { |
| @@ -345,15 +288,7 @@ where | |||
| 345 | let cmd = swap16(cmd); | 288 | let cmd = swap16(cmd); |
| 346 | let mut buf = [0; 1]; | 289 | let mut buf = [0; 1]; |
| 347 | 290 | ||
| 348 | transaction!(&mut self.spi, |bus| async { | 291 | self.spi.cmd_read(cmd, &mut buf).await; |
| 349 | // bus.write(&[swap16(cmd)]).await?; | ||
| 350 | // bus.read(&mut buf).await?; | ||
| 351 | |||
| 352 | bus.cmd_read(slice::from_ref(&cmd), &mut buf).await?; | ||
| 353 | Ok(()) | ||
| 354 | }) | ||
| 355 | .await | ||
| 356 | .unwrap(); | ||
| 357 | 292 | ||
| 358 | swap16(buf[0]) | 293 | swap16(buf[0]) |
| 359 | } | 294 | } |
| @@ -362,14 +297,7 @@ where | |||
| 362 | let cmd = cmd_word(WRITE, INC_ADDR, FUNC_BUS, addr, 4); | 297 | let cmd = cmd_word(WRITE, INC_ADDR, FUNC_BUS, addr, 4); |
| 363 | let buf = [swap16(cmd), swap16(val)]; | 298 | let buf = [swap16(cmd), swap16(val)]; |
| 364 | 299 | ||
| 365 | transaction!(&mut self.spi, |bus| async { | 300 | self.spi.cmd_write(&buf).await; |
| 366 | // bus.write(&[swap16(cmd), swap16(val)]).await?; | ||
| 367 | |||
| 368 | bus.cmd_write(&buf).await?; | ||
| 369 | Ok(()) | ||
| 370 | }) | ||
| 371 | .await | ||
| 372 | .unwrap(); | ||
| 373 | } | 301 | } |
| 374 | } | 302 | } |
| 375 | 303 | ||
diff --git a/src/lib.rs b/src/lib.rs index bcc3c59bd..f0a7aaa0f 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -22,7 +22,6 @@ use embassy_futures::yield_now; | |||
| 22 | use embassy_net_driver_channel as ch; | 22 | use embassy_net_driver_channel as ch; |
| 23 | use embassy_time::{block_for, Duration, Timer}; | 23 | use embassy_time::{block_for, Duration, Timer}; |
| 24 | use embedded_hal_1::digital::OutputPin; | 24 | use embedded_hal_1::digital::OutputPin; |
| 25 | use embedded_hal_async::spi::SpiDevice; | ||
| 26 | 25 | ||
| 27 | use crate::bus::Bus; | 26 | use crate::bus::Bus; |
| 28 | pub use crate::bus::SpiBusCyw43; | 27 | pub use crate::bus::SpiBusCyw43; |
| @@ -513,8 +512,7 @@ pub async fn new<'a, PWR, SPI>( | |||
| 513 | ) -> (NetDriver<'a>, Control<'a>, Runner<'a, PWR, SPI>) | 512 | ) -> (NetDriver<'a>, Control<'a>, Runner<'a, PWR, SPI>) |
| 514 | where | 513 | where |
| 515 | PWR: OutputPin, | 514 | PWR: OutputPin, |
| 516 | SPI: SpiDevice, | 515 | SPI: SpiBusCyw43, |
| 517 | SPI::Bus: SpiBusCyw43<u32>, | ||
| 518 | { | 516 | { |
| 519 | let (ch_runner, device) = ch::new(&mut state.ch, [0; 6]); | 517 | let (ch_runner, device) = ch::new(&mut state.ch, [0; 6]); |
| 520 | let state_ch = ch_runner.state_runner(); | 518 | let state_ch = ch_runner.state_runner(); |
| @@ -552,8 +550,7 @@ where | |||
| 552 | impl<'a, PWR, SPI> Runner<'a, PWR, SPI> | 550 | impl<'a, PWR, SPI> Runner<'a, PWR, SPI> |
| 553 | where | 551 | where |
| 554 | PWR: OutputPin, | 552 | PWR: OutputPin, |
| 555 | SPI: SpiDevice, | 553 | SPI: SpiBusCyw43, |
| 556 | SPI::Bus: SpiBusCyw43<u32>, | ||
| 557 | { | 554 | { |
| 558 | async fn init(&mut self, firmware: &[u8]) { | 555 | async fn init(&mut self, firmware: &[u8]) { |
| 559 | self.bus.init().await; | 556 | self.bus.init().await; |
