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.
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::peripherals::PIO0;
|
||||
use embassy_rp::pio::{Pio, PioCommon, PioPin, PioStateMachine, ShiftDirection};
|
||||
use embassy_rp::pio::{Pio, PioCommon, PioIrq, PioPin, PioStateMachine, ShiftDirection};
|
||||
use embassy_rp::pio_instr_util;
|
||||
use embassy_rp::relocate::RelocatedProgram;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
@ -99,10 +99,10 @@ fn setup_pio_task_sm2(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0,
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn pio_task_sm2(mut sm: PioStateMachine<'static, PIO0, 2>) {
|
||||
async fn pio_task_sm2(mut irq: PioIrq<'static, PIO0, 3>, mut sm: PioStateMachine<'static, PIO0, 2>) {
|
||||
sm.set_enable(true);
|
||||
loop {
|
||||
sm.wait_irq(3).await;
|
||||
irq.wait().await;
|
||||
info!("IRQ trigged");
|
||||
}
|
||||
}
|
||||
@ -114,6 +114,7 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let Pio {
|
||||
mut common,
|
||||
irq3,
|
||||
mut sm0,
|
||||
mut sm1,
|
||||
mut sm2,
|
||||
@ -125,5 +126,5 @@ async fn main(spawner: Spawner) {
|
||||
setup_pio_task_sm2(&mut common, &mut sm2);
|
||||
spawner.spawn(pio_task_sm0(sm0)).unwrap();
|
||||
spawner.spawn(pio_task_sm1(sm1)).unwrap();
|
||||
spawner.spawn(pio_task_sm2(sm2)).unwrap();
|
||||
spawner.spawn(pio_task_sm2(irq3, sm2)).unwrap();
|
||||
}
|
||||
|
@ -85,7 +85,10 @@ impl<'l> HD44780<'l> {
|
||||
|
||||
let db7pin = db7.pin();
|
||||
let Pio {
|
||||
mut common, mut sm0, ..
|
||||
mut common,
|
||||
mut irq0,
|
||||
mut sm0,
|
||||
..
|
||||
} = Pio::new(pio);
|
||||
|
||||
// takes command words (<wait:24> <command:4> <0:4>)
|
||||
@ -145,7 +148,7 @@ impl<'l> HD44780<'l> {
|
||||
sm0.push_tx((50 << 8) | 0x20);
|
||||
sm0.push_tx(0b1100_0000);
|
||||
|
||||
sm0.wait_irq(0).await;
|
||||
irq0.wait().await;
|
||||
sm0.set_enable(false);
|
||||
|
||||
// takes command sequences (<rs:1> <count:7>, data...)
|
||||
|
Reference in New Issue
Block a user