rp/pio: wrap sm rx, tx in structs and allow splitting
this *finally* allows sound implementions of bidirectional transfers without blocking. the futures previously allowed only a single direction to be active at any given time, and the dma transfers didn't take a mutable reference and were thus unsound.
This commit is contained in:
parent
77f7830da3
commit
c44c108db5
6 changed files with 204 additions and 169 deletions
examples/rp/src/bin
|
@ -42,7 +42,7 @@ async fn pio_task_sm0(mut sm: PioStateMachine<'static, PIO0, 0>) {
|
|||
|
||||
let mut v = 0x0f0caffa;
|
||||
loop {
|
||||
sm.wait_push(v).await;
|
||||
sm.tx().wait_push(v).await;
|
||||
v ^= 0xffff;
|
||||
info!("Pushed {:032b} to FIFO", v);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ fn setup_pio_task_sm1(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0,
|
|||
async fn pio_task_sm1(mut sm: PioStateMachine<'static, PIO0, 1>) {
|
||||
sm.set_enable(true);
|
||||
loop {
|
||||
let rx = sm.wait_pull().await;
|
||||
let rx = sm.rx().wait_pull().await;
|
||||
info!("Pulled {:032b} from FIFO", rx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,9 +60,10 @@ async fn main(_spawner: Spawner) {
|
|||
}
|
||||
let mut din = [0u32; 29];
|
||||
loop {
|
||||
let (rx, tx) = sm.rx_tx();
|
||||
join(
|
||||
sm.dma_push(dma_out_ref.reborrow(), &dout),
|
||||
sm.dma_pull(dma_in_ref.reborrow(), &mut din),
|
||||
tx.dma_push(dma_out_ref.reborrow(), &dout),
|
||||
rx.dma_pull(dma_in_ref.reborrow(), &mut din),
|
||||
)
|
||||
.await;
|
||||
for i in 0..din.len() {
|
||||
|
|
|
@ -139,14 +139,14 @@ impl<'l> HD44780<'l> {
|
|||
|
||||
sm0.set_enable(true);
|
||||
// init to 8 bit thrice
|
||||
sm0.push_tx((50000 << 8) | 0x30);
|
||||
sm0.push_tx((5000 << 8) | 0x30);
|
||||
sm0.push_tx((200 << 8) | 0x30);
|
||||
sm0.tx().push((50000 << 8) | 0x30);
|
||||
sm0.tx().push((5000 << 8) | 0x30);
|
||||
sm0.tx().push((200 << 8) | 0x30);
|
||||
// init 4 bit
|
||||
sm0.push_tx((200 << 8) | 0x20);
|
||||
sm0.tx().push((200 << 8) | 0x20);
|
||||
// set font and lines
|
||||
sm0.push_tx((50 << 8) | 0x20);
|
||||
sm0.push_tx(0b1100_0000);
|
||||
sm0.tx().push((50 << 8) | 0x20);
|
||||
sm0.tx().push(0b1100_0000);
|
||||
|
||||
irq0.wait().await;
|
||||
sm0.set_enable(false);
|
||||
|
@ -216,7 +216,7 @@ impl<'l> HD44780<'l> {
|
|||
sm0.set_enable(true);
|
||||
|
||||
// display on and cursor on and blinking, reset display
|
||||
sm0.dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1]).await;
|
||||
sm0.tx().dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1]).await;
|
||||
|
||||
Self {
|
||||
dma: dma.map_into(),
|
||||
|
@ -240,6 +240,6 @@ impl<'l> HD44780<'l> {
|
|||
// set cursor to 1:15
|
||||
self.buf[38..].copy_from_slice(&[0x80, 0xcf]);
|
||||
|
||||
self.sm.dma_push(self.dma.reborrow(), &self.buf).await;
|
||||
self.sm.tx().dma_push(self.dma.reborrow(), &self.buf).await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> {
|
|||
pub async fn write(&mut self, colors: &[RGB8]) {
|
||||
for color in colors {
|
||||
let word = (u32::from(color.g) << 24) | (u32::from(color.r) << 16) | (u32::from(color.b) << 8);
|
||||
self.sm.wait_push(word).await;
|
||||
self.sm.tx().wait_push(word).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue