aboutsummaryrefslogtreecommitdiff
path: root/examples/rp/src/bin
diff options
context:
space:
mode:
authorAdrian Wowk <[email protected]>2025-07-18 19:19:27 -0500
committerDario Nieuwenhuis <[email protected]>2025-09-05 20:35:48 +0200
commit62ff0194f4b7413b17dbc69813ec205638248aa7 (patch)
tree7f954609bf7e3eaad08f05284f9e8f49a8483168 /examples/rp/src/bin
parent83b42e0db620b7fc2364763b452b346b711e8d9f (diff)
rp: add pio spi runtime reconfiguration
Diffstat (limited to 'examples/rp/src/bin')
-rw-r--r--examples/rp/src/bin/pio_spi.rs20
-rw-r--r--examples/rp/src/bin/pio_spi_async.rs10
2 files changed, 7 insertions, 23 deletions
diff --git a/examples/rp/src/bin/pio_spi.rs b/examples/rp/src/bin/pio_spi.rs
index 0164e4c81..4218327ec 100644
--- a/examples/rp/src/bin/pio_spi.rs
+++ b/examples/rp/src/bin/pio_spi.rs
@@ -10,8 +10,8 @@
10use defmt::*; 10use defmt::*;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_rp::peripherals::PIO0; 12use embassy_rp::peripherals::PIO0;
13use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi}; 13use embassy_rp::pio_programs::spi::Spi;
14use embassy_rp::spi::Phase; 14use embassy_rp::spi::Config;
15use embassy_rp::{bind_interrupts, pio}; 15use embassy_rp::{bind_interrupts, pio};
16use embassy_time::Timer; 16use embassy_time::Timer;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
25 let p = embassy_rp::init(Default::default()); 25 let p = embassy_rp::init(Default::default());
26 info!("Hello World!"); 26 info!("Hello World!");
27 27
28 // These pins are routed to differnet hardware SPI peripherals, but we can 28 // These pins are routed to different hardware SPI peripherals, but we can
29 // use them together regardless 29 // use them together regardless
30 let mosi = p.PIN_6; // SPI0 SCLK 30 let mosi = p.PIN_6; // SPI0 SCLK
31 let miso = p.PIN_7; // SPI0 MOSI 31 let miso = p.PIN_7; // SPI0 MOSI
@@ -33,20 +33,8 @@ async fn main(_spawner: Spawner) {
33 33
34 let pio::Pio { mut common, sm0, .. } = pio::Pio::new(p.PIO0, Irqs); 34 let pio::Pio { mut common, sm0, .. } = pio::Pio::new(p.PIO0, Irqs);
35 35
36 // The PIO program must be configured with the clock phase
37 let program = PioSpiProgram::new(&mut common, Phase::CaptureOnFirstTransition);
38
39 // Construct an SPI driver backed by a PIO state machine 36 // Construct an SPI driver backed by a PIO state machine
40 let mut spi = Spi::new_blocking( 37 let mut spi = Spi::new_blocking(&mut common, sm0, clk, mosi, miso, Config::default());
41 &mut common,
42 sm0,
43 clk,
44 mosi,
45 miso,
46 &program,
47 // Only the frequency and polarity are set here
48 Config::default(),
49 );
50 38
51 loop { 39 loop {
52 let tx_buf = [1_u8, 2, 3, 4, 5, 6]; 40 let tx_buf = [1_u8, 2, 3, 4, 5, 6];
diff --git a/examples/rp/src/bin/pio_spi_async.rs b/examples/rp/src/bin/pio_spi_async.rs
index 1dbdff609..74a2dd11b 100644
--- a/examples/rp/src/bin/pio_spi_async.rs
+++ b/examples/rp/src/bin/pio_spi_async.rs
@@ -10,8 +10,8 @@
10use defmt::*; 10use defmt::*;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_rp::peripherals::PIO0; 12use embassy_rp::peripherals::PIO0;
13use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi}; 13use embassy_rp::pio_programs::spi::Spi;
14use embassy_rp::spi::Phase; 14use embassy_rp::spi::Config;
15use embassy_rp::{bind_interrupts, pio}; 15use embassy_rp::{bind_interrupts, pio};
16use embassy_time::Timer; 16use embassy_time::Timer;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
25 let p = embassy_rp::init(Default::default()); 25 let p = embassy_rp::init(Default::default());
26 info!("Hello World!"); 26 info!("Hello World!");
27 27
28 // These pins are routed to differnet hardware SPI peripherals, but we can 28 // These pins are routed to different hardware SPI peripherals, but we can
29 // use them together regardless 29 // use them together regardless
30 let mosi = p.PIN_6; // SPI0 SCLK 30 let mosi = p.PIN_6; // SPI0 SCLK
31 let miso = p.PIN_7; // SPI0 MOSI 31 let miso = p.PIN_7; // SPI0 MOSI
@@ -33,9 +33,6 @@ async fn main(_spawner: Spawner) {
33 33
34 let pio::Pio { mut common, sm0, .. } = pio::Pio::new(p.PIO0, Irqs); 34 let pio::Pio { mut common, sm0, .. } = pio::Pio::new(p.PIO0, Irqs);
35 35
36 // The PIO program must be configured with the clock phase
37 let program = PioSpiProgram::new(&mut common, Phase::CaptureOnFirstTransition);
38
39 // Construct an SPI driver backed by a PIO state machine 36 // Construct an SPI driver backed by a PIO state machine
40 let mut spi = Spi::new( 37 let mut spi = Spi::new(
41 &mut common, 38 &mut common,
@@ -46,7 +43,6 @@ async fn main(_spawner: Spawner) {
46 p.DMA_CH0, 43 p.DMA_CH0,
47 p.DMA_CH1, 44 p.DMA_CH1,
48 &program, 45 &program,
49 // Only the frequency and polarity are set here
50 Config::default(), 46 Config::default(),
51 ); 47 );
52 48