aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpennae <[email protected]>2023-04-27 02:12:49 +0200
committerpennae <[email protected]>2023-05-03 12:57:21 +0200
commit909a5fe2e513ef91129a29ccdd8772824879383c (patch)
tree849028b8188df60507f05acb562d8c607dc76bd8 /examples
parent486fe9e59da7474c5162f56d89d5b6c279d02753 (diff)
rp/pio: split irqs from state machines
we can only have one active waiter for any given irq at any given time. allowing waits for irqs on state machines bypasses this limitation and causes lost events for all but the latest waiter for a given irq. splitting this out also allows us to signal from state machines to other parts of the application without monopolizing state machine access for the irq wait, as would be necessary to make irq waiting sound.
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/src/bin/pio_async.rs9
-rw-r--r--examples/rp/src/bin/pio_hd44780.rs7
2 files changed, 10 insertions, 6 deletions
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs
index 11b290869..3d76a7d7b 100644
--- a/examples/rp/src/bin/pio_async.rs
+++ b/examples/rp/src/bin/pio_async.rs
@@ -4,7 +4,7 @@
4use defmt::info; 4use defmt::info;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_rp::peripherals::PIO0; 6use embassy_rp::peripherals::PIO0;
7use embassy_rp::pio::{Pio, PioCommon, PioPin, PioStateMachine, ShiftDirection}; 7use embassy_rp::pio::{Pio, PioCommon, PioIrq, PioPin, PioStateMachine, ShiftDirection};
8use embassy_rp::pio_instr_util; 8use embassy_rp::pio_instr_util;
9use embassy_rp::relocate::RelocatedProgram; 9use embassy_rp::relocate::RelocatedProgram;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
@@ -99,10 +99,10 @@ fn setup_pio_task_sm2(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0,
99} 99}
100 100
101#[embassy_executor::task] 101#[embassy_executor::task]
102async fn pio_task_sm2(mut sm: PioStateMachine<'static, PIO0, 2>) { 102async fn pio_task_sm2(mut irq: PioIrq<'static, PIO0, 3>, mut sm: PioStateMachine<'static, PIO0, 2>) {
103 sm.set_enable(true); 103 sm.set_enable(true);
104 loop { 104 loop {
105 sm.wait_irq(3).await; 105 irq.wait().await;
106 info!("IRQ trigged"); 106 info!("IRQ trigged");
107 } 107 }
108} 108}
@@ -114,6 +114,7 @@ async fn main(spawner: Spawner) {
114 114
115 let Pio { 115 let Pio {
116 mut common, 116 mut common,
117 irq3,
117 mut sm0, 118 mut sm0,
118 mut sm1, 119 mut sm1,
119 mut sm2, 120 mut sm2,
@@ -125,5 +126,5 @@ async fn main(spawner: Spawner) {
125 setup_pio_task_sm2(&mut common, &mut sm2); 126 setup_pio_task_sm2(&mut common, &mut sm2);
126 spawner.spawn(pio_task_sm0(sm0)).unwrap(); 127 spawner.spawn(pio_task_sm0(sm0)).unwrap();
127 spawner.spawn(pio_task_sm1(sm1)).unwrap(); 128 spawner.spawn(pio_task_sm1(sm1)).unwrap();
128 spawner.spawn(pio_task_sm2(sm2)).unwrap(); 129 spawner.spawn(pio_task_sm2(irq3, sm2)).unwrap();
129} 130}
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs
index bc51d43c4..7c1d7acfe 100644
--- a/examples/rp/src/bin/pio_hd44780.rs
+++ b/examples/rp/src/bin/pio_hd44780.rs
@@ -85,7 +85,10 @@ impl<'l> HD44780<'l> {
85 85
86 let db7pin = db7.pin(); 86 let db7pin = db7.pin();
87 let Pio { 87 let Pio {
88 mut common, mut sm0, .. 88 mut common,
89 mut irq0,
90 mut sm0,
91 ..
89 } = Pio::new(pio); 92 } = Pio::new(pio);
90 93
91 // takes command words (<wait:24> <command:4> <0:4>) 94 // takes command words (<wait:24> <command:4> <0:4>)
@@ -145,7 +148,7 @@ impl<'l> HD44780<'l> {
145 sm0.push_tx((50 << 8) | 0x20); 148 sm0.push_tx((50 << 8) | 0x20);
146 sm0.push_tx(0b1100_0000); 149 sm0.push_tx(0b1100_0000);
147 150
148 sm0.wait_irq(0).await; 151 irq0.wait().await;
149 sm0.set_enable(false); 152 sm0.set_enable(false);
150 153
151 // takes command sequences (<rs:1> <count:7>, data...) 154 // takes command sequences (<rs:1> <count:7>, data...)