aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpennae <[email protected]>2023-05-03 08:15:46 +0200
committerpennae <[email protected]>2023-05-03 11:25:43 +0200
commit4ccb2bc95aab6202d6f53882a59265427cdd5655 (patch)
tree48f8f93043b276ad08a4d3fdea6e4fe2c9a2ca12 /examples
parent17e78175a69dc96ea8f71c41949cbc705d82b51a (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.rs7
-rw-r--r--examples/rp/src/bin/pio_hd44780.rs17
-rw-r--r--examples/rp/src/bin/ws2812-pio.rs7
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)]
4use defmt::info; 4use defmt::info;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_rp::gpio::{AnyPin, Pin};
7use embassy_rp::peripherals::PIO0; 6use embassy_rp::peripherals::PIO0;
8use embassy_rp::pio::{Pio, PioCommon, PioStateMachine, PioStateMachineInstance, ShiftDirection}; 7use embassy_rp::pio::{Pio, PioCommon, PioPin, PioStateMachine, PioStateMachineInstance, ShiftDirection};
9use embassy_rp::pio_instr_util; 8use embassy_rp::pio_instr_util;
10use embassy_rp::relocate::RelocatedProgram; 9use embassy_rp::relocate::RelocatedProgram;
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13fn setup_pio_task_sm0(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstance<PIO0, 0>, pin: AnyPin) { 12fn 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
7use embassy_executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_rp::dma::{AnyChannel, Channel}; 8use embassy_rp::dma::{AnyChannel, Channel};
9use embassy_rp::gpio::Pin;
10use embassy_rp::peripherals::PIO0; 9use embassy_rp::peripherals::PIO0;
11use embassy_rp::pio::{FifoJoin, Pio, PioStateMachine, PioStateMachineInstance, ShiftDirection}; 10use embassy_rp::pio::{FifoJoin, Pio, PioPin, PioStateMachine, PioStateMachineInstance, ShiftDirection};
12use embassy_rp::pwm::{Config, Pwm}; 11use embassy_rp::pwm::{Config, Pwm};
13use embassy_rp::relocate::RelocatedProgram; 12use embassy_rp::relocate::RelocatedProgram;
14use embassy_rp::{into_ref, Peripheral, PeripheralRef}; 13use 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
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_rp::gpio::{self, Pin};
8use embassy_rp::pio::{ 7use embassy_rp::pio::{
9 FifoJoin, Pio, PioCommon, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, 8 FifoJoin, Pio, PioCommon, PioInstance, PioPin, PioStateMachine, PioStateMachineInstance, ShiftDirection,
10}; 9};
11use embassy_rp::pio_instr_util; 10use embassy_rp::pio_instr_util;
12use embassy_rp::relocate::RelocatedProgram; 11use embassy_rp::relocate::RelocatedProgram;
@@ -18,7 +17,7 @@ pub struct Ws2812<'d, P: PioInstance, const S: usize> {
18} 17}
19 18
20impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> { 19impl<'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 {