rp/pio: remove PioPeripheral
merge into PioInstance instead. PioPeripheral was mostly a wrapper
around PioInstance anyway, and the way the wrapping was done required
PioInstanceBase<N> types where PIO{N} could've been used instead.
			
			
This commit is contained in:
		@@ -904,19 +904,19 @@ impl<const SM_NO: u8> sealed::SmInstance for SmInstanceBase<SM_NO> {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
impl<const SM_NO: u8> SmInstance for SmInstanceBase<SM_NO> {}
 | 
					impl<const SM_NO: u8> SmInstance for SmInstanceBase<SM_NO> {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub trait PioPeripheral: sealed::PioPeripheral + Sized {
 | 
					pub trait PioInstance: sealed::PioInstance + Sized + Unpin {
 | 
				
			||||||
    fn pio(&self) -> u8 {
 | 
					    fn pio(&self) -> u8 {
 | 
				
			||||||
        Self::Pio::PIO_NO
 | 
					        Self::PIO_NO
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn split(
 | 
					    fn split(
 | 
				
			||||||
        self,
 | 
					        self,
 | 
				
			||||||
    ) -> (
 | 
					    ) -> (
 | 
				
			||||||
        PioCommonInstance<Self::Pio>,
 | 
					        PioCommonInstance<Self>,
 | 
				
			||||||
        PioStateMachineInstance<Self::Pio, SmInstanceBase<0>>,
 | 
					        PioStateMachineInstance<Self, SmInstanceBase<0>>,
 | 
				
			||||||
        PioStateMachineInstance<Self::Pio, SmInstanceBase<1>>,
 | 
					        PioStateMachineInstance<Self, SmInstanceBase<1>>,
 | 
				
			||||||
        PioStateMachineInstance<Self::Pio, SmInstanceBase<2>>,
 | 
					        PioStateMachineInstance<Self, SmInstanceBase<2>>,
 | 
				
			||||||
        PioStateMachineInstance<Self::Pio, SmInstanceBase<3>>,
 | 
					        PioStateMachineInstance<Self, SmInstanceBase<3>>,
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
        (
 | 
					        (
 | 
				
			||||||
            PioCommonInstance {
 | 
					            PioCommonInstance {
 | 
				
			||||||
@@ -944,12 +944,6 @@ pub trait PioPeripheral: sealed::PioPeripheral + Sized {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod sealed {
 | 
					mod sealed {
 | 
				
			||||||
    pub trait PioInstance {
 | 
					 | 
				
			||||||
        const PIO_NO: u8;
 | 
					 | 
				
			||||||
        const PIO: &'static crate::pac::pio::Pio;
 | 
					 | 
				
			||||||
        const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub trait PioCommon {
 | 
					    pub trait PioCommon {
 | 
				
			||||||
        type Pio: super::PioInstance;
 | 
					        type Pio: super::PioInstance;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -968,46 +962,28 @@ mod sealed {
 | 
				
			|||||||
        const SM_NO: u8;
 | 
					        const SM_NO: u8;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub trait PioPeripheral {
 | 
					    pub trait PioInstance {
 | 
				
			||||||
        type Pio: super::PioInstance;
 | 
					        const PIO_NO: u8;
 | 
				
			||||||
 | 
					        const PIO: &'static crate::pac::pio::Pio;
 | 
				
			||||||
 | 
					        const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Identifies a specific PIO device
 | 
					 | 
				
			||||||
pub struct PioInstanceBase<const PIO_NO: u8> {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub trait PioInstance: sealed::PioInstance + Unpin {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl sealed::PioInstance for PioInstanceBase<0> {
 | 
					 | 
				
			||||||
    const PIO_NO: u8 = 0;
 | 
					 | 
				
			||||||
    const PIO: &'static pac::pio::Pio = &pac::PIO0;
 | 
					 | 
				
			||||||
    const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::PIO0_0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
impl PioInstance for PioInstanceBase<0> {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl sealed::PioInstance for PioInstanceBase<1> {
 | 
					 | 
				
			||||||
    const PIO_NO: u8 = 1;
 | 
					 | 
				
			||||||
    const PIO: &'static pac::pio::Pio = &pac::PIO1;
 | 
					 | 
				
			||||||
    const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::PIO1_0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
impl PioInstance for PioInstanceBase<1> {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub type Pio0 = PioInstanceBase<0>;
 | 
					 | 
				
			||||||
pub type Pio1 = PioInstanceBase<1>;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub type Sm0 = SmInstanceBase<0>;
 | 
					pub type Sm0 = SmInstanceBase<0>;
 | 
				
			||||||
pub type Sm1 = SmInstanceBase<1>;
 | 
					pub type Sm1 = SmInstanceBase<1>;
 | 
				
			||||||
pub type Sm2 = SmInstanceBase<2>;
 | 
					pub type Sm2 = SmInstanceBase<2>;
 | 
				
			||||||
pub type Sm3 = SmInstanceBase<3>;
 | 
					pub type Sm3 = SmInstanceBase<3>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
macro_rules! impl_pio_sm {
 | 
					macro_rules! impl_pio {
 | 
				
			||||||
    ($name:ident, $pio:expr) => {
 | 
					    ($name:ident, $pio:expr, $pac:ident, $funcsel:ident) => {
 | 
				
			||||||
        impl sealed::PioPeripheral for peripherals::$name {
 | 
					        impl sealed::PioInstance for peripherals::$name {
 | 
				
			||||||
            type Pio = PioInstanceBase<$pio>;
 | 
					            const PIO_NO: u8 = $pio;
 | 
				
			||||||
 | 
					            const PIO: &'static pac::pio::Pio = &pac::$pac;
 | 
				
			||||||
 | 
					            const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        impl PioPeripheral for peripherals::$name {}
 | 
					        impl PioInstance for peripherals::$name {}
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl_pio_sm!(PIO0, 0);
 | 
					impl_pio!(PIO0, 0, PIO0, PIO0_0);
 | 
				
			||||||
impl_pio_sm!(PIO1, 1);
 | 
					impl_pio!(PIO1, 1, PIO1, PIO1_0);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,15 +4,15 @@
 | 
				
			|||||||
use defmt::info;
 | 
					use defmt::info;
 | 
				
			||||||
use embassy_executor::Spawner;
 | 
					use embassy_executor::Spawner;
 | 
				
			||||||
use embassy_rp::gpio::{AnyPin, Pin};
 | 
					use embassy_rp::gpio::{AnyPin, Pin};
 | 
				
			||||||
 | 
					use embassy_rp::peripherals::PIO0;
 | 
				
			||||||
use embassy_rp::pio::{
 | 
					use embassy_rp::pio::{
 | 
				
			||||||
    Pio0, PioCommon, PioCommonInstance, PioPeripheral, PioStateMachine, PioStateMachineInstance, ShiftDirection, Sm0,
 | 
					    PioCommon, PioCommonInstance, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, Sm0, Sm1, Sm2,
 | 
				
			||||||
    Sm1, Sm2,
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use embassy_rp::pio_instr_util;
 | 
					use embassy_rp::pio_instr_util;
 | 
				
			||||||
use embassy_rp::relocate::RelocatedProgram;
 | 
					use embassy_rp::relocate::RelocatedProgram;
 | 
				
			||||||
use {defmt_rtt as _, panic_probe as _};
 | 
					use {defmt_rtt as _, panic_probe as _};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn setup_pio_task_sm0(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachineInstance<Pio0, Sm0>, pin: AnyPin) {
 | 
					fn setup_pio_task_sm0(pio: &mut PioCommonInstance<PIO0>, sm: &mut PioStateMachineInstance<PIO0, Sm0>, pin: AnyPin) {
 | 
				
			||||||
    // Setup sm0
 | 
					    // Setup sm0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Send data serially to pin
 | 
					    // Send data serially to pin
 | 
				
			||||||
@@ -40,7 +40,7 @@ fn setup_pio_task_sm0(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachin
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[embassy_executor::task]
 | 
					#[embassy_executor::task]
 | 
				
			||||||
async fn pio_task_sm0(mut sm: PioStateMachineInstance<Pio0, Sm0>) {
 | 
					async fn pio_task_sm0(mut sm: PioStateMachineInstance<PIO0, Sm0>) {
 | 
				
			||||||
    sm.set_enable(true);
 | 
					    sm.set_enable(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let mut v = 0x0f0caffa;
 | 
					    let mut v = 0x0f0caffa;
 | 
				
			||||||
@@ -51,7 +51,7 @@ async fn pio_task_sm0(mut sm: PioStateMachineInstance<Pio0, Sm0>) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn setup_pio_task_sm1(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachineInstance<Pio0, Sm1>) {
 | 
					fn setup_pio_task_sm1(pio: &mut PioCommonInstance<PIO0>, sm: &mut PioStateMachineInstance<PIO0, Sm1>) {
 | 
				
			||||||
    // Setupm sm1
 | 
					    // Setupm sm1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Read 0b10101 repeatedly until ISR is full
 | 
					    // Read 0b10101 repeatedly until ISR is full
 | 
				
			||||||
@@ -70,7 +70,7 @@ fn setup_pio_task_sm1(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachin
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[embassy_executor::task]
 | 
					#[embassy_executor::task]
 | 
				
			||||||
async fn pio_task_sm1(mut sm: PioStateMachineInstance<Pio0, Sm1>) {
 | 
					async fn pio_task_sm1(mut sm: PioStateMachineInstance<PIO0, Sm1>) {
 | 
				
			||||||
    sm.set_enable(true);
 | 
					    sm.set_enable(true);
 | 
				
			||||||
    loop {
 | 
					    loop {
 | 
				
			||||||
        let rx = sm.wait_pull().await;
 | 
					        let rx = sm.wait_pull().await;
 | 
				
			||||||
@@ -78,7 +78,7 @@ async fn pio_task_sm1(mut sm: PioStateMachineInstance<Pio0, Sm1>) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn setup_pio_task_sm2(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachineInstance<Pio0, Sm2>) {
 | 
					fn setup_pio_task_sm2(pio: &mut PioCommonInstance<PIO0>, sm: &mut PioStateMachineInstance<PIO0, Sm2>) {
 | 
				
			||||||
    // Setup sm2
 | 
					    // Setup sm2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Repeatedly trigger IRQ 3
 | 
					    // Repeatedly trigger IRQ 3
 | 
				
			||||||
@@ -102,7 +102,7 @@ fn setup_pio_task_sm2(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachin
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[embassy_executor::task]
 | 
					#[embassy_executor::task]
 | 
				
			||||||
async fn pio_task_sm2(mut sm: PioStateMachineInstance<Pio0, Sm2>) {
 | 
					async fn pio_task_sm2(mut sm: PioStateMachineInstance<PIO0, Sm2>) {
 | 
				
			||||||
    sm.set_enable(true);
 | 
					    sm.set_enable(true);
 | 
				
			||||||
    loop {
 | 
					    loop {
 | 
				
			||||||
        sm.wait_irq(3).await;
 | 
					        sm.wait_irq(3).await;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@
 | 
				
			|||||||
use defmt::info;
 | 
					use defmt::info;
 | 
				
			||||||
use embassy_executor::Spawner;
 | 
					use embassy_executor::Spawner;
 | 
				
			||||||
use embassy_futures::join::join;
 | 
					use embassy_futures::join::join;
 | 
				
			||||||
use embassy_rp::pio::{PioCommon, PioPeripheral, PioStateMachine, ShiftDirection};
 | 
					use embassy_rp::pio::{PioCommon, PioInstance, PioStateMachine, ShiftDirection};
 | 
				
			||||||
use embassy_rp::relocate::RelocatedProgram;
 | 
					use embassy_rp::relocate::RelocatedProgram;
 | 
				
			||||||
use embassy_rp::{pio_instr_util, Peripheral};
 | 
					use embassy_rp::{pio_instr_util, Peripheral};
 | 
				
			||||||
use {defmt_rtt as _, panic_probe as _};
 | 
					use {defmt_rtt as _, panic_probe as _};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,8 +9,7 @@ use embassy_rp::dma::{AnyChannel, Channel};
 | 
				
			|||||||
use embassy_rp::gpio::Pin;
 | 
					use embassy_rp::gpio::Pin;
 | 
				
			||||||
use embassy_rp::peripherals::PIO0;
 | 
					use embassy_rp::peripherals::PIO0;
 | 
				
			||||||
use embassy_rp::pio::{
 | 
					use embassy_rp::pio::{
 | 
				
			||||||
    FifoJoin, PioCommon, PioInstanceBase, PioPeripheral, PioStateMachine, PioStateMachineInstance, ShiftDirection,
 | 
					    FifoJoin, PioCommon, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, SmInstanceBase,
 | 
				
			||||||
    SmInstanceBase,
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use embassy_rp::pwm::{Config, Pwm};
 | 
					use embassy_rp::pwm::{Config, Pwm};
 | 
				
			||||||
use embassy_rp::relocate::RelocatedProgram;
 | 
					use embassy_rp::relocate::RelocatedProgram;
 | 
				
			||||||
@@ -68,7 +67,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
pub struct HD44780<'l> {
 | 
					pub struct HD44780<'l> {
 | 
				
			||||||
    dma: PeripheralRef<'l, AnyChannel>,
 | 
					    dma: PeripheralRef<'l, AnyChannel>,
 | 
				
			||||||
    sm: PioStateMachineInstance<PioInstanceBase<0>, SmInstanceBase<0>>,
 | 
					    sm: PioStateMachineInstance<PIO0, SmInstanceBase<0>>,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    buf: [u8; 40],
 | 
					    buf: [u8; 40],
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,8 +6,8 @@ use defmt::*;
 | 
				
			|||||||
use embassy_executor::Spawner;
 | 
					use embassy_executor::Spawner;
 | 
				
			||||||
use embassy_rp::gpio::{self, Pin};
 | 
					use embassy_rp::gpio::{self, Pin};
 | 
				
			||||||
use embassy_rp::pio::{
 | 
					use embassy_rp::pio::{
 | 
				
			||||||
    FifoJoin, PioCommon, PioCommonInstance, PioInstance, PioPeripheral, PioStateMachine, PioStateMachineInstance,
 | 
					    FifoJoin, PioCommon, PioCommonInstance, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection,
 | 
				
			||||||
    ShiftDirection, SmInstance,
 | 
					    SmInstance,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use embassy_rp::pio_instr_util;
 | 
					use embassy_rp::pio_instr_util;
 | 
				
			||||||
use embassy_rp::relocate::RelocatedProgram;
 | 
					use embassy_rp::relocate::RelocatedProgram;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user