diff options
| author | pennae <[email protected]> | 2023-05-03 08:15:46 +0200 |
|---|---|---|
| committer | pennae <[email protected]> | 2023-05-03 11:25:43 +0200 |
| commit | 4ccb2bc95aab6202d6f53882a59265427cdd5655 (patch) | |
| tree | 48f8f93043b276ad08a4d3fdea6e4fe2c9a2ca12 /examples | |
| parent | 17e78175a69dc96ea8f71c41949cbc705d82b51a (diff) | |
rp/pio: add PioPin trait
pio can only access pins in bank 0, so it doesn't make sense to even
allow wrapping of other banks' pins.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp/src/bin/pio_async.rs | 7 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_hd44780.rs | 17 | ||||
| -rw-r--r-- | examples/rp/src/bin/ws2812-pio.rs | 7 |
3 files changed, 14 insertions, 17 deletions
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index 5fea7034b..154cc6b65 100644 --- a/examples/rp/src/bin/pio_async.rs +++ b/examples/rp/src/bin/pio_async.rs | |||
| @@ -3,14 +3,13 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_rp::gpio::{AnyPin, Pin}; | ||
| 7 | use embassy_rp::peripherals::PIO0; | 6 | use embassy_rp::peripherals::PIO0; |
| 8 | use embassy_rp::pio::{Pio, PioCommon, PioStateMachine, PioStateMachineInstance, ShiftDirection}; | 7 | use embassy_rp::pio::{Pio, PioCommon, PioPin, PioStateMachine, PioStateMachineInstance, ShiftDirection}; |
| 9 | use embassy_rp::pio_instr_util; | 8 | use embassy_rp::pio_instr_util; |
| 10 | use embassy_rp::relocate::RelocatedProgram; | 9 | use embassy_rp::relocate::RelocatedProgram; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | fn setup_pio_task_sm0(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstance<PIO0, 0>, pin: AnyPin) { | 12 | fn setup_pio_task_sm0(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstance<PIO0, 0>, pin: impl PioPin) { |
| 14 | // Setup sm0 | 13 | // Setup sm0 |
| 15 | 14 | ||
| 16 | // Send data serially to pin | 15 | // Send data serially to pin |
| @@ -121,7 +120,7 @@ async fn main(spawner: Spawner) { | |||
| 121 | .. | 120 | .. |
| 122 | } = Pio::new(pio); | 121 | } = Pio::new(pio); |
| 123 | 122 | ||
| 124 | setup_pio_task_sm0(&mut common, &mut sm0, p.PIN_0.degrade()); | 123 | setup_pio_task_sm0(&mut common, &mut sm0, p.PIN_0); |
| 125 | setup_pio_task_sm1(&mut common, &mut sm1); | 124 | setup_pio_task_sm1(&mut common, &mut sm1); |
| 126 | setup_pio_task_sm2(&mut common, &mut sm2); | 125 | setup_pio_task_sm2(&mut common, &mut sm2); |
| 127 | spawner.spawn(pio_task_sm0(sm0)).unwrap(); | 126 | spawner.spawn(pio_task_sm0(sm0)).unwrap(); |
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs index 59b4c1f52..6d56bc233 100644 --- a/examples/rp/src/bin/pio_hd44780.rs +++ b/examples/rp/src/bin/pio_hd44780.rs | |||
| @@ -6,9 +6,8 @@ use core::fmt::Write; | |||
| 6 | 6 | ||
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_rp::dma::{AnyChannel, Channel}; | 8 | use embassy_rp::dma::{AnyChannel, Channel}; |
| 9 | use embassy_rp::gpio::Pin; | ||
| 10 | use embassy_rp::peripherals::PIO0; | 9 | use embassy_rp::peripherals::PIO0; |
| 11 | use embassy_rp::pio::{FifoJoin, Pio, PioStateMachine, PioStateMachineInstance, ShiftDirection}; | 10 | use embassy_rp::pio::{FifoJoin, Pio, PioPin, PioStateMachine, PioStateMachineInstance, ShiftDirection}; |
| 12 | use embassy_rp::pwm::{Config, Pwm}; | 11 | use embassy_rp::pwm::{Config, Pwm}; |
| 13 | use embassy_rp::relocate::RelocatedProgram; | 12 | use embassy_rp::relocate::RelocatedProgram; |
| 14 | use embassy_rp::{into_ref, Peripheral, PeripheralRef}; | 13 | use embassy_rp::{into_ref, Peripheral, PeripheralRef}; |
| @@ -74,13 +73,13 @@ impl<'l> HD44780<'l> { | |||
| 74 | pub async fn new( | 73 | pub async fn new( |
| 75 | pio: impl Peripheral<P = PIO0> + 'l, | 74 | pio: impl Peripheral<P = PIO0> + 'l, |
| 76 | dma: impl Peripheral<P = impl Channel> + 'l, | 75 | dma: impl Peripheral<P = impl Channel> + 'l, |
| 77 | rs: impl Pin, | 76 | rs: impl PioPin, |
| 78 | rw: impl Pin, | 77 | rw: impl PioPin, |
| 79 | e: impl Pin, | 78 | e: impl PioPin, |
| 80 | db4: impl Pin, | 79 | db4: impl PioPin, |
| 81 | db5: impl Pin, | 80 | db5: impl PioPin, |
| 82 | db6: impl Pin, | 81 | db6: impl PioPin, |
| 83 | db7: impl Pin, | 82 | db7: impl PioPin, |
| 84 | ) -> HD44780<'l> { | 83 | ) -> HD44780<'l> { |
| 85 | into_ref!(dma); | 84 | into_ref!(dma); |
| 86 | 85 | ||
diff --git a/examples/rp/src/bin/ws2812-pio.rs b/examples/rp/src/bin/ws2812-pio.rs index 0975559d7..8276fad64 100644 --- a/examples/rp/src/bin/ws2812-pio.rs +++ b/examples/rp/src/bin/ws2812-pio.rs | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_rp::gpio::{self, Pin}; | ||
| 8 | use embassy_rp::pio::{ | 7 | use embassy_rp::pio::{ |
| 9 | FifoJoin, Pio, PioCommon, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, | 8 | FifoJoin, Pio, PioCommon, PioInstance, PioPin, PioStateMachine, PioStateMachineInstance, ShiftDirection, |
| 10 | }; | 9 | }; |
| 11 | use embassy_rp::pio_instr_util; | 10 | use embassy_rp::pio_instr_util; |
| 12 | use embassy_rp::relocate::RelocatedProgram; | 11 | use embassy_rp::relocate::RelocatedProgram; |
| @@ -18,7 +17,7 @@ pub struct Ws2812<'d, P: PioInstance, const S: usize> { | |||
| 18 | } | 17 | } |
| 19 | 18 | ||
| 20 | impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> { | 19 | impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> { |
| 21 | pub fn new(mut pio: PioCommon<'d, P>, mut sm: PioStateMachineInstance<'d, P, S>, pin: gpio::AnyPin) -> Self { | 20 | pub fn new(mut pio: PioCommon<'d, P>, mut sm: PioStateMachineInstance<'d, P, S>, pin: impl PioPin) -> Self { |
| 22 | // Setup sm0 | 21 | // Setup sm0 |
| 23 | 22 | ||
| 24 | // prepare the PIO program | 23 | // prepare the PIO program |
| @@ -124,7 +123,7 @@ async fn main(_spawner: Spawner) { | |||
| 124 | 123 | ||
| 125 | // For the thing plus, use pin 8 | 124 | // For the thing plus, use pin 8 |
| 126 | // For the feather, use pin 16 | 125 | // For the feather, use pin 16 |
| 127 | let mut ws2812 = Ws2812::new(common, sm0, p.PIN_8.degrade()); | 126 | let mut ws2812 = Ws2812::new(common, sm0, p.PIN_8); |
| 128 | 127 | ||
| 129 | // Loop forever making RGB values and pushing them out to the WS2812. | 128 | // Loop forever making RGB values and pushing them out to the WS2812. |
| 130 | loop { | 129 | loop { |
