diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp/src/bin/pio_async.rs | 26 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_dma.rs | 7 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_hd44780.rs | 42 | ||||
| -rw-r--r-- | examples/rp/src/bin/ws2812-pio.rs | 13 |
4 files changed, 44 insertions, 44 deletions
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index 5fea7034b..4e0ab5e3c 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, PioIrq, PioPin, PioStateMachine, 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 PioStateMachine<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 |
| @@ -38,18 +37,18 @@ fn setup_pio_task_sm0(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstanc | |||
| 38 | } | 37 | } |
| 39 | 38 | ||
| 40 | #[embassy_executor::task] | 39 | #[embassy_executor::task] |
| 41 | async fn pio_task_sm0(mut sm: PioStateMachineInstance<'static, PIO0, 0>) { | 40 | async fn pio_task_sm0(mut sm: PioStateMachine<'static, PIO0, 0>) { |
| 42 | sm.set_enable(true); | 41 | sm.set_enable(true); |
| 43 | 42 | ||
| 44 | let mut v = 0x0f0caffa; | 43 | let mut v = 0x0f0caffa; |
| 45 | loop { | 44 | loop { |
| 46 | sm.wait_push(v).await; | 45 | sm.tx().wait_push(v).await; |
| 47 | v ^= 0xffff; | 46 | v ^= 0xffff; |
| 48 | info!("Pushed {:032b} to FIFO", v); | 47 | info!("Pushed {:032b} to FIFO", v); |
| 49 | } | 48 | } |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | fn setup_pio_task_sm1(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstance<PIO0, 1>) { | 51 | fn setup_pio_task_sm1(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0, 1>) { |
| 53 | // Setupm sm1 | 52 | // Setupm sm1 |
| 54 | 53 | ||
| 55 | // Read 0b10101 repeatedly until ISR is full | 54 | // Read 0b10101 repeatedly until ISR is full |
| @@ -68,15 +67,15 @@ fn setup_pio_task_sm1(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstanc | |||
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | #[embassy_executor::task] | 69 | #[embassy_executor::task] |
| 71 | async fn pio_task_sm1(mut sm: PioStateMachineInstance<'static, PIO0, 1>) { | 70 | async fn pio_task_sm1(mut sm: PioStateMachine<'static, PIO0, 1>) { |
| 72 | sm.set_enable(true); | 71 | sm.set_enable(true); |
| 73 | loop { | 72 | loop { |
| 74 | let rx = sm.wait_pull().await; | 73 | let rx = sm.rx().wait_pull().await; |
| 75 | info!("Pulled {:032b} from FIFO", rx); | 74 | info!("Pulled {:032b} from FIFO", rx); |
| 76 | } | 75 | } |
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | fn setup_pio_task_sm2(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstance<PIO0, 2>) { | 78 | fn setup_pio_task_sm2(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0, 2>) { |
| 80 | // Setup sm2 | 79 | // Setup sm2 |
| 81 | 80 | ||
| 82 | // Repeatedly trigger IRQ 3 | 81 | // Repeatedly trigger IRQ 3 |
| @@ -100,10 +99,10 @@ fn setup_pio_task_sm2(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachineInstanc | |||
| 100 | } | 99 | } |
| 101 | 100 | ||
| 102 | #[embassy_executor::task] | 101 | #[embassy_executor::task] |
| 103 | async fn pio_task_sm2(mut sm: PioStateMachineInstance<'static, PIO0, 2>) { | 102 | async fn pio_task_sm2(mut irq: PioIrq<'static, PIO0, 3>, mut sm: PioStateMachine<'static, PIO0, 2>) { |
| 104 | sm.set_enable(true); | 103 | sm.set_enable(true); |
| 105 | loop { | 104 | loop { |
| 106 | sm.wait_irq(3).await; | 105 | irq.wait().await; |
| 107 | info!("IRQ trigged"); | 106 | info!("IRQ trigged"); |
| 108 | } | 107 | } |
| 109 | } | 108 | } |
| @@ -115,16 +114,17 @@ async fn main(spawner: Spawner) { | |||
| 115 | 114 | ||
| 116 | let Pio { | 115 | let Pio { |
| 117 | mut common, | 116 | mut common, |
| 117 | irq3, | ||
| 118 | mut sm0, | 118 | mut sm0, |
| 119 | mut sm1, | 119 | mut sm1, |
| 120 | mut sm2, | 120 | mut sm2, |
| 121 | .. | 121 | .. |
| 122 | } = Pio::new(pio); | 122 | } = Pio::new(pio); |
| 123 | 123 | ||
| 124 | setup_pio_task_sm0(&mut common, &mut sm0, p.PIN_0.degrade()); | 124 | setup_pio_task_sm0(&mut common, &mut sm0, p.PIN_0); |
| 125 | setup_pio_task_sm1(&mut common, &mut sm1); | 125 | setup_pio_task_sm1(&mut common, &mut sm1); |
| 126 | setup_pio_task_sm2(&mut common, &mut sm2); | 126 | setup_pio_task_sm2(&mut common, &mut sm2); |
| 127 | spawner.spawn(pio_task_sm0(sm0)).unwrap(); | 127 | spawner.spawn(pio_task_sm0(sm0)).unwrap(); |
| 128 | spawner.spawn(pio_task_sm1(sm1)).unwrap(); | 128 | spawner.spawn(pio_task_sm1(sm1)).unwrap(); |
| 129 | spawner.spawn(pio_task_sm2(sm2)).unwrap(); | 129 | spawner.spawn(pio_task_sm2(irq3, sm2)).unwrap(); |
| 130 | } | 130 | } |
diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs index 0f1f6df12..c664482e5 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::{Pio, PioStateMachine, ShiftDirection}; | 7 | use embassy_rp::pio::{Pio, 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 _}; |
| @@ -60,9 +60,10 @@ async fn main(_spawner: Spawner) { | |||
| 60 | } | 60 | } |
| 61 | let mut din = [0u32; 29]; | 61 | let mut din = [0u32; 29]; |
| 62 | loop { | 62 | loop { |
| 63 | let (rx, tx) = sm.rx_tx(); | ||
| 63 | join( | 64 | join( |
| 64 | sm.dma_push(dma_out_ref.reborrow(), &dout), | 65 | tx.dma_push(dma_out_ref.reborrow(), &dout), |
| 65 | sm.dma_pull(dma_in_ref.reborrow(), &mut din), | 66 | rx.dma_pull(dma_in_ref.reborrow(), &mut din), |
| 66 | ) | 67 | ) |
| 67 | .await; | 68 | .await; |
| 68 | for i in 0..din.len() { | 69 | for i in 0..din.len() { |
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs index 59b4c1f52..f76d334e7 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, 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}; |
| @@ -65,7 +64,7 @@ async fn main(_spawner: Spawner) { | |||
| 65 | 64 | ||
| 66 | pub struct HD44780<'l> { | 65 | pub struct HD44780<'l> { |
| 67 | dma: PeripheralRef<'l, AnyChannel>, | 66 | dma: PeripheralRef<'l, AnyChannel>, |
| 68 | sm: PioStateMachineInstance<'l, PIO0, 0>, | 67 | sm: PioStateMachine<'l, PIO0, 0>, |
| 69 | 68 | ||
| 70 | buf: [u8; 40], | 69 | buf: [u8; 40], |
| 71 | } | 70 | } |
| @@ -74,19 +73,22 @@ 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 | ||
| 87 | let db7pin = db7.pin(); | 86 | let db7pin = db7.pin(); |
| 88 | let Pio { | 87 | let Pio { |
| 89 | mut common, mut sm0, .. | 88 | mut common, |
| 89 | mut irq0, | ||
| 90 | mut sm0, | ||
| 91 | .. | ||
| 90 | } = Pio::new(pio); | 92 | } = Pio::new(pio); |
| 91 | 93 | ||
| 92 | // takes command words (<wait:24> <command:4> <0:4>) | 94 | // takes command words (<wait:24> <command:4> <0:4>) |
| @@ -137,16 +139,16 @@ impl<'l> HD44780<'l> { | |||
| 137 | 139 | ||
| 138 | sm0.set_enable(true); | 140 | sm0.set_enable(true); |
| 139 | // init to 8 bit thrice | 141 | // init to 8 bit thrice |
| 140 | sm0.push_tx((50000 << 8) | 0x30); | 142 | sm0.tx().push((50000 << 8) | 0x30); |
| 141 | sm0.push_tx((5000 << 8) | 0x30); | 143 | sm0.tx().push((5000 << 8) | 0x30); |
| 142 | sm0.push_tx((200 << 8) | 0x30); | 144 | sm0.tx().push((200 << 8) | 0x30); |
| 143 | // init 4 bit | 145 | // init 4 bit |
| 144 | sm0.push_tx((200 << 8) | 0x20); | 146 | sm0.tx().push((200 << 8) | 0x20); |
| 145 | // set font and lines | 147 | // set font and lines |
| 146 | sm0.push_tx((50 << 8) | 0x20); | 148 | sm0.tx().push((50 << 8) | 0x20); |
| 147 | sm0.push_tx(0b1100_0000); | 149 | sm0.tx().push(0b1100_0000); |
| 148 | 150 | ||
| 149 | sm0.wait_irq(0).await; | 151 | irq0.wait().await; |
| 150 | sm0.set_enable(false); | 152 | sm0.set_enable(false); |
| 151 | 153 | ||
| 152 | // takes command sequences (<rs:1> <count:7>, data...) | 154 | // takes command sequences (<rs:1> <count:7>, data...) |
| @@ -214,7 +216,7 @@ impl<'l> HD44780<'l> { | |||
| 214 | sm0.set_enable(true); | 216 | sm0.set_enable(true); |
| 215 | 217 | ||
| 216 | // display on and cursor on and blinking, reset display | 218 | // display on and cursor on and blinking, reset display |
| 217 | sm0.dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1]).await; | 219 | sm0.tx().dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1]).await; |
| 218 | 220 | ||
| 219 | Self { | 221 | Self { |
| 220 | dma: dma.map_into(), | 222 | dma: dma.map_into(), |
| @@ -238,6 +240,6 @@ impl<'l> HD44780<'l> { | |||
| 238 | // set cursor to 1:15 | 240 | // set cursor to 1:15 |
| 239 | self.buf[38..].copy_from_slice(&[0x80, 0xcf]); | 241 | self.buf[38..].copy_from_slice(&[0x80, 0xcf]); |
| 240 | 242 | ||
| 241 | self.sm.dma_push(self.dma.reborrow(), &self.buf).await; | 243 | self.sm.tx().dma_push(self.dma.reborrow(), &self.buf).await; |
| 242 | } | 244 | } |
| 243 | } | 245 | } |
diff --git a/examples/rp/src/bin/ws2812-pio.rs b/examples/rp/src/bin/ws2812-pio.rs index 0975559d7..c9c701a70 100644 --- a/examples/rp/src/bin/ws2812-pio.rs +++ b/examples/rp/src/bin/ws2812-pio.rs | |||
| @@ -4,21 +4,18 @@ | |||
| 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}; | 7 | use embassy_rp::pio::{FifoJoin, Pio, PioCommon, PioInstance, PioPin, PioStateMachine, ShiftDirection}; |
| 8 | use embassy_rp::pio::{ | ||
| 9 | FifoJoin, Pio, PioCommon, PioInstance, PioStateMachine, PioStateMachineInstance, ShiftDirection, | ||
| 10 | }; | ||
| 11 | use embassy_rp::pio_instr_util; | 8 | use embassy_rp::pio_instr_util; |
| 12 | use embassy_rp::relocate::RelocatedProgram; | 9 | use embassy_rp::relocate::RelocatedProgram; |
| 13 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 14 | use smart_leds::RGB8; | 11 | use smart_leds::RGB8; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | pub struct Ws2812<'d, P: PioInstance, const S: usize> { | 13 | pub struct Ws2812<'d, P: PioInstance, const S: usize> { |
| 17 | sm: PioStateMachineInstance<'d, P, S>, | 14 | sm: PioStateMachine<'d, P, S>, |
| 18 | } | 15 | } |
| 19 | 16 | ||
| 20 | impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> { | 17 | 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 { | 18 | pub fn new(mut pio: PioCommon<'d, P>, mut sm: PioStateMachine<'d, P, S>, pin: impl PioPin) -> Self { |
| 22 | // Setup sm0 | 19 | // Setup sm0 |
| 23 | 20 | ||
| 24 | // prepare the PIO program | 21 | // prepare the PIO program |
| @@ -90,7 +87,7 @@ impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> { | |||
| 90 | pub async fn write(&mut self, colors: &[RGB8]) { | 87 | pub async fn write(&mut self, colors: &[RGB8]) { |
| 91 | for color in colors { | 88 | for color in colors { |
| 92 | let word = (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8); | 89 | let word = (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8); |
| 93 | self.sm.wait_push(word).await; | 90 | self.sm.tx().wait_push(word).await; |
| 94 | } | 91 | } |
| 95 | } | 92 | } |
| 96 | } | 93 | } |
| @@ -124,7 +121,7 @@ async fn main(_spawner: Spawner) { | |||
| 124 | 121 | ||
| 125 | // For the thing plus, use pin 8 | 122 | // For the thing plus, use pin 8 |
| 126 | // For the feather, use pin 16 | 123 | // For the feather, use pin 16 |
| 127 | let mut ws2812 = Ws2812::new(common, sm0, p.PIN_8.degrade()); | 124 | let mut ws2812 = Ws2812::new(common, sm0, p.PIN_8); |
| 128 | 125 | ||
| 129 | // Loop forever making RGB values and pushing them out to the WS2812. | 126 | // Loop forever making RGB values and pushing them out to the WS2812. |
| 130 | loop { | 127 | loop { |
