aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-04-15 09:54:02 +0000
committerGitHub <[email protected]>2023-04-15 09:54:02 +0000
commitefb67dfc1b782487ee8584211bda3dc16812b5dc (patch)
treebbd05679decbc7f9f379ebc3a0907cbe58040cda /examples
parent46efce6ea2d4280d5e8e1eaece53269a94fb4847 (diff)
parent9ca5bcd57686bc8144c31b1937a15dccb6cf07ce (diff)
Merge pull request #66 from mattiasgronlund/remove_myspi
Remove MySpi from example
Diffstat (limited to 'examples')
-rw-r--r--examples/rpi-pico-w/src/main.rs95
1 files changed, 2 insertions, 93 deletions
diff --git a/examples/rpi-pico-w/src/main.rs b/examples/rpi-pico-w/src/main.rs
index d5610d2ba..d075aec2a 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;
@@ -62,11 +61,6 @@ async fn main(spawner: Spawner) {
62 61
63 let pwr = Output::new(p.PIN_23, Level::Low); 62 let pwr = Output::new(p.PIN_23, Level::Low);
64 let cs = Output::new(p.PIN_25, Level::High); 63 let cs = Output::new(p.PIN_25, Level::High);
65 // let clk = Output::new(p.PIN_29, Level::Low);
66 // let mut dio = Flex::new(p.PIN_24);
67 // dio.set_low();
68 // dio.set_as_output();
69 // // let bus = MySpi { clk, dio };
70 64
71 let (_, sm, _, _, _) = p.PIO0.split(); 65 let (_, sm, _, _, _) = p.PIO0.split();
72 let dma = p.DMA_CH0; 66 let dma = p.DMA_CH0;
@@ -150,88 +144,3 @@ async fn main(spawner: Spawner) {
150 } 144 }
151} 145}
152 146
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}