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.
This commit is contained in:
pennae
2023-05-03 08:15:46 +02:00
parent 17e78175a6
commit 4ccb2bc95a
4 changed files with 45 additions and 27 deletions

View File

@ -4,9 +4,8 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::gpio::{self, Pin};
use embassy_rp::pio::{
FifoJoin, Pio, PioCommon, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection,
FifoJoin, Pio, PioCommon, PioInstance, PioPin, PioStateMachine, PioStateMachineInstance, ShiftDirection,
};
use embassy_rp::pio_instr_util;
use embassy_rp::relocate::RelocatedProgram;
@ -18,7 +17,7 @@ pub struct Ws2812<'d, P: PioInstance, const S: usize> {
}
impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> {
pub fn new(mut pio: PioCommon<'d, P>, mut sm: PioStateMachineInstance<'d, P, S>, pin: gpio::AnyPin) -> Self {
pub fn new(mut pio: PioCommon<'d, P>, mut sm: PioStateMachineInstance<'d, P, S>, pin: impl PioPin) -> Self {
// Setup sm0
// prepare the PIO program
@ -124,7 +123,7 @@ async fn main(_spawner: Spawner) {
// For the thing plus, use pin 8
// For the feather, use pin 16
let mut ws2812 = Ws2812::new(common, sm0, p.PIN_8.degrade());
let mut ws2812 = Ws2812::new(common, sm0, p.PIN_8);
// Loop forever making RGB values and pushing them out to the WS2812.
loop {