diff options
| -rw-r--r-- | embassy-rp/src/pio.rs | 64 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_async.rs | 16 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_dma.rs | 2 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_hd44780.rs | 5 | ||||
| -rw-r--r-- | examples/rp/src/bin/ws2812-pio.rs | 4 |
5 files changed, 33 insertions, 58 deletions
diff --git a/embassy-rp/src/pio.rs b/embassy-rp/src/pio.rs index e9a67fd48..459b7806b 100644 --- a/embassy-rp/src/pio.rs +++ b/embassy-rp/src/pio.rs | |||
| @@ -904,19 +904,19 @@ impl<const SM_NO: u8> sealed::SmInstance for SmInstanceBase<SM_NO> { | |||
| 904 | } | 904 | } |
| 905 | impl<const SM_NO: u8> SmInstance for SmInstanceBase<SM_NO> {} | 905 | impl<const SM_NO: u8> SmInstance for SmInstanceBase<SM_NO> {} |
| 906 | 906 | ||
| 907 | pub trait PioPeripheral: sealed::PioPeripheral + Sized { | 907 | pub trait PioInstance: sealed::PioInstance + Sized + Unpin { |
| 908 | fn pio(&self) -> u8 { | 908 | fn pio(&self) -> u8 { |
| 909 | Self::Pio::PIO_NO | 909 | Self::PIO_NO |
| 910 | } | 910 | } |
| 911 | 911 | ||
| 912 | fn split( | 912 | fn split( |
| 913 | self, | 913 | self, |
| 914 | ) -> ( | 914 | ) -> ( |
| 915 | PioCommonInstance<Self::Pio>, | 915 | PioCommonInstance<Self>, |
| 916 | PioStateMachineInstance<Self::Pio, SmInstanceBase<0>>, | 916 | PioStateMachineInstance<Self, SmInstanceBase<0>>, |
| 917 | PioStateMachineInstance<Self::Pio, SmInstanceBase<1>>, | 917 | PioStateMachineInstance<Self, SmInstanceBase<1>>, |
| 918 | PioStateMachineInstance<Self::Pio, SmInstanceBase<2>>, | 918 | PioStateMachineInstance<Self, SmInstanceBase<2>>, |
| 919 | PioStateMachineInstance<Self::Pio, SmInstanceBase<3>>, | 919 | PioStateMachineInstance<Self, SmInstanceBase<3>>, |
| 920 | ) { | 920 | ) { |
| 921 | ( | 921 | ( |
| 922 | PioCommonInstance { | 922 | PioCommonInstance { |
| @@ -944,12 +944,6 @@ pub trait PioPeripheral: sealed::PioPeripheral + Sized { | |||
| 944 | } | 944 | } |
| 945 | 945 | ||
| 946 | mod sealed { | 946 | mod sealed { |
| 947 | pub trait PioInstance { | ||
| 948 | const PIO_NO: u8; | ||
| 949 | const PIO: &'static crate::pac::pio::Pio; | ||
| 950 | const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel; | ||
| 951 | } | ||
| 952 | |||
| 953 | pub trait PioCommon { | 947 | pub trait PioCommon { |
| 954 | type Pio: super::PioInstance; | 948 | type Pio: super::PioInstance; |
| 955 | } | 949 | } |
| @@ -968,46 +962,28 @@ mod sealed { | |||
| 968 | const SM_NO: u8; | 962 | const SM_NO: u8; |
| 969 | } | 963 | } |
| 970 | 964 | ||
| 971 | pub trait PioPeripheral { | 965 | pub trait PioInstance { |
| 972 | type Pio: super::PioInstance; | 966 | const PIO_NO: u8; |
| 967 | const PIO: &'static crate::pac::pio::Pio; | ||
| 968 | const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel; | ||
| 973 | } | 969 | } |
| 974 | } | 970 | } |
| 975 | 971 | ||
| 976 | // Identifies a specific PIO device | ||
| 977 | pub struct PioInstanceBase<const PIO_NO: u8> {} | ||
| 978 | |||
| 979 | pub trait PioInstance: sealed::PioInstance + Unpin {} | ||
| 980 | |||
| 981 | impl sealed::PioInstance for PioInstanceBase<0> { | ||
| 982 | const PIO_NO: u8 = 0; | ||
| 983 | const PIO: &'static pac::pio::Pio = &pac::PIO0; | ||
| 984 | const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::PIO0_0; | ||
| 985 | } | ||
| 986 | impl PioInstance for PioInstanceBase<0> {} | ||
| 987 | |||
| 988 | impl sealed::PioInstance for PioInstanceBase<1> { | ||
| 989 | const PIO_NO: u8 = 1; | ||
| 990 | const PIO: &'static pac::pio::Pio = &pac::PIO1; | ||
| 991 | const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::PIO1_0; | ||
| 992 | } | ||
| 993 | impl PioInstance for PioInstanceBase<1> {} | ||
| 994 | |||
| 995 | pub type Pio0 = PioInstanceBase<0>; | ||
| 996 | pub type Pio1 = PioInstanceBase<1>; | ||
| 997 | |||
| 998 | pub type Sm0 = SmInstanceBase<0>; | 972 | pub type Sm0 = SmInstanceBase<0>; |
| 999 | pub type Sm1 = SmInstanceBase<1>; | 973 | pub type Sm1 = SmInstanceBase<1>; |
| 1000 | pub type Sm2 = SmInstanceBase<2>; | 974 | pub type Sm2 = SmInstanceBase<2>; |
| 1001 | pub type Sm3 = SmInstanceBase<3>; | 975 | pub type Sm3 = SmInstanceBase<3>; |
| 1002 | 976 | ||
| 1003 | macro_rules! impl_pio_sm { | 977 | macro_rules! impl_pio { |
| 1004 | ($name:ident, $pio:expr) => { | 978 | ($name:ident, $pio:expr, $pac:ident, $funcsel:ident) => { |
| 1005 | impl sealed::PioPeripheral for peripherals::$name { | 979 | impl sealed::PioInstance for peripherals::$name { |
| 1006 | type Pio = PioInstanceBase<$pio>; | 980 | const PIO_NO: u8 = $pio; |
| 981 | const PIO: &'static pac::pio::Pio = &pac::$pac; | ||
| 982 | const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel; | ||
| 1007 | } | 983 | } |
| 1008 | impl PioPeripheral for peripherals::$name {} | 984 | impl PioInstance for peripherals::$name {} |
| 1009 | }; | 985 | }; |
| 1010 | } | 986 | } |
| 1011 | 987 | ||
| 1012 | impl_pio_sm!(PIO0, 0); | 988 | impl_pio!(PIO0, 0, PIO0, PIO0_0); |
| 1013 | impl_pio_sm!(PIO1, 1); | 989 | impl_pio!(PIO1, 1, PIO1, PIO1_0); |
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index 1b075b8fd..16a09327f 100644 --- a/examples/rp/src/bin/pio_async.rs +++ b/examples/rp/src/bin/pio_async.rs | |||
| @@ -4,15 +4,15 @@ | |||
| 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}; | 6 | use embassy_rp::gpio::{AnyPin, Pin}; |
| 7 | use embassy_rp::peripherals::PIO0; | ||
| 7 | use embassy_rp::pio::{ | 8 | use embassy_rp::pio::{ |
| 8 | Pio0, PioCommon, PioCommonInstance, PioPeripheral, PioStateMachine, PioStateMachineInstance, ShiftDirection, Sm0, | 9 | PioCommon, PioCommonInstance, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, Sm0, Sm1, Sm2, |
| 9 | Sm1, Sm2, | ||
| 10 | }; | 10 | }; |
| 11 | use embassy_rp::pio_instr_util; | 11 | use embassy_rp::pio_instr_util; |
| 12 | use embassy_rp::relocate::RelocatedProgram; | 12 | use embassy_rp::relocate::RelocatedProgram; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | fn setup_pio_task_sm0(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachineInstance<Pio0, Sm0>, pin: AnyPin) { | 15 | fn setup_pio_task_sm0(pio: &mut PioCommonInstance<PIO0>, sm: &mut PioStateMachineInstance<PIO0, Sm0>, pin: AnyPin) { |
| 16 | // Setup sm0 | 16 | // Setup sm0 |
| 17 | 17 | ||
| 18 | // Send data serially to pin | 18 | // Send data serially to pin |
| @@ -40,7 +40,7 @@ fn setup_pio_task_sm0(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachin | |||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | #[embassy_executor::task] | 42 | #[embassy_executor::task] |
| 43 | async fn pio_task_sm0(mut sm: PioStateMachineInstance<Pio0, Sm0>) { | 43 | async fn pio_task_sm0(mut sm: PioStateMachineInstance<PIO0, Sm0>) { |
| 44 | sm.set_enable(true); | 44 | sm.set_enable(true); |
| 45 | 45 | ||
| 46 | let mut v = 0x0f0caffa; | 46 | let mut v = 0x0f0caffa; |
| @@ -51,7 +51,7 @@ async fn pio_task_sm0(mut sm: PioStateMachineInstance<Pio0, Sm0>) { | |||
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | fn setup_pio_task_sm1(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachineInstance<Pio0, Sm1>) { | 54 | fn setup_pio_task_sm1(pio: &mut PioCommonInstance<PIO0>, sm: &mut PioStateMachineInstance<PIO0, Sm1>) { |
| 55 | // Setupm sm1 | 55 | // Setupm sm1 |
| 56 | 56 | ||
| 57 | // Read 0b10101 repeatedly until ISR is full | 57 | // Read 0b10101 repeatedly until ISR is full |
| @@ -70,7 +70,7 @@ fn setup_pio_task_sm1(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachin | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | #[embassy_executor::task] | 72 | #[embassy_executor::task] |
| 73 | async fn pio_task_sm1(mut sm: PioStateMachineInstance<Pio0, Sm1>) { | 73 | async fn pio_task_sm1(mut sm: PioStateMachineInstance<PIO0, Sm1>) { |
| 74 | sm.set_enable(true); | 74 | sm.set_enable(true); |
| 75 | loop { | 75 | loop { |
| 76 | let rx = sm.wait_pull().await; | 76 | let rx = sm.wait_pull().await; |
| @@ -78,7 +78,7 @@ async fn pio_task_sm1(mut sm: PioStateMachineInstance<Pio0, Sm1>) { | |||
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | fn setup_pio_task_sm2(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachineInstance<Pio0, Sm2>) { | 81 | fn setup_pio_task_sm2(pio: &mut PioCommonInstance<PIO0>, sm: &mut PioStateMachineInstance<PIO0, Sm2>) { |
| 82 | // Setup sm2 | 82 | // Setup sm2 |
| 83 | 83 | ||
| 84 | // Repeatedly trigger IRQ 3 | 84 | // Repeatedly trigger IRQ 3 |
| @@ -102,7 +102,7 @@ fn setup_pio_task_sm2(pio: &mut PioCommonInstance<Pio0>, sm: &mut PioStateMachin | |||
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | #[embassy_executor::task] | 104 | #[embassy_executor::task] |
| 105 | async fn pio_task_sm2(mut sm: PioStateMachineInstance<Pio0, Sm2>) { | 105 | async fn pio_task_sm2(mut sm: PioStateMachineInstance<PIO0, Sm2>) { |
| 106 | sm.set_enable(true); | 106 | sm.set_enable(true); |
| 107 | loop { | 107 | loop { |
| 108 | sm.wait_irq(3).await; | 108 | sm.wait_irq(3).await; |
diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs index 7d4919f75..ccbc70fe2 100644 --- a/examples/rp/src/bin/pio_dma.rs +++ b/examples/rp/src/bin/pio_dma.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_futures::join::join; | 6 | use embassy_futures::join::join; |
| 7 | use embassy_rp::pio::{PioCommon, PioPeripheral, PioStateMachine, ShiftDirection}; | 7 | use embassy_rp::pio::{PioCommon, PioInstance, PioStateMachine, ShiftDirection}; |
| 8 | use embassy_rp::relocate::RelocatedProgram; | 8 | use embassy_rp::relocate::RelocatedProgram; |
| 9 | use embassy_rp::{pio_instr_util, Peripheral}; | 9 | use embassy_rp::{pio_instr_util, Peripheral}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs index 6bcd0652b..1b24897b0 100644 --- a/examples/rp/src/bin/pio_hd44780.rs +++ b/examples/rp/src/bin/pio_hd44780.rs | |||
| @@ -9,8 +9,7 @@ use embassy_rp::dma::{AnyChannel, Channel}; | |||
| 9 | use embassy_rp::gpio::Pin; | 9 | use embassy_rp::gpio::Pin; |
| 10 | use embassy_rp::peripherals::PIO0; | 10 | use embassy_rp::peripherals::PIO0; |
| 11 | use embassy_rp::pio::{ | 11 | use embassy_rp::pio::{ |
| 12 | FifoJoin, PioCommon, PioInstanceBase, PioPeripheral, PioStateMachine, PioStateMachineInstance, ShiftDirection, | 12 | FifoJoin, PioCommon, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, SmInstanceBase, |
| 13 | SmInstanceBase, | ||
| 14 | }; | 13 | }; |
| 15 | use embassy_rp::pwm::{Config, Pwm}; | 14 | use embassy_rp::pwm::{Config, Pwm}; |
| 16 | use embassy_rp::relocate::RelocatedProgram; | 15 | use embassy_rp::relocate::RelocatedProgram; |
| @@ -68,7 +67,7 @@ async fn main(_spawner: Spawner) { | |||
| 68 | 67 | ||
| 69 | pub struct HD44780<'l> { | 68 | pub struct HD44780<'l> { |
| 70 | dma: PeripheralRef<'l, AnyChannel>, | 69 | dma: PeripheralRef<'l, AnyChannel>, |
| 71 | sm: PioStateMachineInstance<PioInstanceBase<0>, SmInstanceBase<0>>, | 70 | sm: PioStateMachineInstance<PIO0, SmInstanceBase<0>>, |
| 72 | 71 | ||
| 73 | buf: [u8; 40], | 72 | buf: [u8; 40], |
| 74 | } | 73 | } |
diff --git a/examples/rp/src/bin/ws2812-pio.rs b/examples/rp/src/bin/ws2812-pio.rs index 041e8ae11..592caf244 100644 --- a/examples/rp/src/bin/ws2812-pio.rs +++ b/examples/rp/src/bin/ws2812-pio.rs | |||
| @@ -6,8 +6,8 @@ use defmt::*; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_rp::gpio::{self, Pin}; | 7 | use embassy_rp::gpio::{self, Pin}; |
| 8 | use embassy_rp::pio::{ | 8 | use embassy_rp::pio::{ |
| 9 | FifoJoin, PioCommon, PioCommonInstance, PioInstance, PioPeripheral, PioStateMachine, PioStateMachineInstance, | 9 | FifoJoin, PioCommon, PioCommonInstance, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, |
| 10 | ShiftDirection, SmInstance, | 10 | SmInstance, |
| 11 | }; | 11 | }; |
| 12 | use embassy_rp::pio_instr_util; | 12 | use embassy_rp::pio_instr_util; |
| 13 | use embassy_rp::relocate::RelocatedProgram; | 13 | use embassy_rp::relocate::RelocatedProgram; |
