aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMattias Grönlund <[email protected]>2023-04-14 09:38:35 +0200
committerMattias Grönlund <[email protected]>2023-04-14 09:38:35 +0200
commit4be1e4bd44600737bf80ef7210c2b913d63364de (patch)
treeab910a4a8413de1b8b0546a53cf9fc050ea5a3f4 /examples
parent46efce6ea2d4280d5e8e1eaece53269a94fb4847 (diff)
Remove MySpi
MySpi was replaced by PioSpi and no longer used.
Diffstat (limited to 'examples')
-rw-r--r--examples/rpi-pico-w/src/main.rs90
1 files changed, 2 insertions, 88 deletions
diff --git a/examples/rpi-pico-w/src/main.rs b/examples/rpi-pico-w/src/main.rs
index d5610d2ba..b773cea18 100644
--- a/examples/rpi-pico-w/src/main.rs
+++ b/examples/rpi-pico-w/src/main.rs
@@ -4,7 +4,6 @@
4#![feature(async_fn_in_trait)] 4#![feature(async_fn_in_trait)]
5#![allow(incomplete_features)] 5#![allow(incomplete_features)]
6 6
7use core::slice;
8use core::str::from_utf8; 7use core::str::from_utf8;
9 8
10use cyw43_pio::PioSpi; 9use cyw43_pio::PioSpi;
@@ -12,8 +11,8 @@ use defmt::*;
12use embassy_executor::Spawner; 11use embassy_executor::Spawner;
13use embassy_net::tcp::TcpSocket; 12use embassy_net::tcp::TcpSocket;
14use embassy_net::{Config, Stack, StackResources}; 13use embassy_net::{Config, Stack, StackResources};
15use embassy_rp::gpio::{Flex, Level, Output}; 14use embassy_rp::gpio::{Level, Output};
16use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_24, PIN_25, PIN_29}; 15use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25};
17use embassy_rp::pio::{Pio0, PioPeripheral, PioStateMachineInstance, Sm0}; 16use embassy_rp::pio::{Pio0, PioPeripheral, PioStateMachineInstance, Sm0};
18use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
19use static_cell::StaticCell; 18use static_cell::StaticCell;
@@ -150,88 +149,3 @@ async fn main(spawner: Spawner) {
150 } 149 }
151} 150}
152 151
153struct MySpi {
154 /// SPI clock
155 clk: Output<'static, PIN_29>,
156
157 /// 4 signals, all in one!!
158 /// - SPI MISO
159 /// - SPI MOSI
160 /// - IRQ
161 /// - strap to set to gSPI mode on boot.
162 dio: Flex<'static, PIN_24>,
163
164 /// Chip select
165 cs: Output<'static, PIN_25>,
166}
167
168impl MySpi {
169 async fn read(&mut self, words: &mut [u32]) {
170 self.dio.set_as_input();
171 for word in words {
172 let mut w = 0;
173 for _ in 0..32 {
174 w = w << 1;
175
176 // rising edge, sample data
177 if self.dio.is_high() {
178 w |= 0x01;
179 }
180 self.clk.set_high();
181
182 // falling edge
183 self.clk.set_low();
184 }
185 *word = w
186 }
187 }
188
189 async fn write(&mut self, words: &[u32]) {
190 self.dio.set_as_output();
191 for word in words {
192 let mut word = *word;
193 for _ in 0..32 {
194 // falling edge, setup data
195 self.clk.set_low();
196 if word & 0x8000_0000 == 0 {
197 self.dio.set_low();
198 } else {
199 self.dio.set_high();
200 }
201
202 // rising edge
203 self.clk.set_high();
204
205 word = word << 1;
206 }
207 }
208 self.clk.set_low();
209
210 self.dio.set_as_input();
211 }
212}
213
214impl cyw43::SpiBusCyw43 for MySpi {
215 async fn cmd_write(&mut self, write: &[u32]) -> u32 {
216 self.cs.set_low();
217 self.write(write).await;
218
219 let mut status = 0;
220 self.read(slice::from_mut(&mut status)).await;
221
222 self.cs.set_high();
223 status
224 }
225
226 async fn cmd_read(&mut self, write: u32, read: &mut [u32]) -> u32 {
227 self.cs.set_low();
228 self.write(slice::from_ref(&write)).await;
229 self.read(read).await;
230
231 let mut status = 0;
232 self.read(slice::from_mut(&mut status)).await;
233
234 self.cs.set_high();
235 status
236 }
237}