diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp/src/bin/pio_spi.rs | 20 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_spi_async.rs | 10 |
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 @@ | |||
| 10 | use defmt::*; | 10 | use defmt::*; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::peripherals::PIO0; | 12 | use embassy_rp::peripherals::PIO0; |
| 13 | use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi}; | 13 | use embassy_rp::pio_programs::spi::Spi; |
| 14 | use embassy_rp::spi::Phase; | 14 | use embassy_rp::spi::Config; |
| 15 | use embassy_rp::{bind_interrupts, pio}; | 15 | use embassy_rp::{bind_interrupts, pio}; |
| 16 | use embassy_time::Timer; | 16 | use embassy_time::Timer; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {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 @@ | |||
| 10 | use defmt::*; | 10 | use defmt::*; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::peripherals::PIO0; | 12 | use embassy_rp::peripherals::PIO0; |
| 13 | use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi}; | 13 | use embassy_rp::pio_programs::spi::Spi; |
| 14 | use embassy_rp::spi::Phase; | 14 | use embassy_rp::spi::Config; |
| 15 | use embassy_rp::{bind_interrupts, pio}; | 15 | use embassy_rp::{bind_interrupts, pio}; |
| 16 | use embassy_time::Timer; | 16 | use embassy_time::Timer; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {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 | ||
