Skip to content

Commit 6af79f0

Browse files
authored
Merge pull request #3935 from edenbarby/main
embassy-rp: pio: Add access to DMA engine byte swapping
2 parents 0edd45e + 2494121 commit 6af79f0

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

cyw43-pio/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ where
169169

170170
self.sm.set_enable(true);
171171

172-
self.sm.tx().dma_push(self.dma.reborrow(), write).await;
172+
self.sm.tx().dma_push(self.dma.reborrow(), write, false).await;
173173

174174
let mut status = 0;
175175
self.sm
176176
.rx()
177-
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status))
177+
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status), false)
178178
.await;
179179
status
180180
}
@@ -201,13 +201,16 @@ where
201201
// self.cs.set_low();
202202
self.sm.set_enable(true);
203203

204-
self.sm.tx().dma_push(self.dma.reborrow(), slice::from_ref(&cmd)).await;
205-
self.sm.rx().dma_pull(self.dma.reborrow(), read).await;
204+
self.sm
205+
.tx()
206+
.dma_push(self.dma.reborrow(), slice::from_ref(&cmd), false)
207+
.await;
208+
self.sm.rx().dma_pull(self.dma.reborrow(), read, false).await;
206209

207210
let mut status = 0;
208211
self.sm
209212
.rx()
210-
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status))
213+
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status), false)
211214
.await;
212215

213216
#[cfg(feature = "defmt")]

embassy-rp/src/pio/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> {
362362
&'a mut self,
363363
ch: PeripheralRef<'a, C>,
364364
data: &'a mut [W],
365+
bswap: bool,
365366
) -> Transfer<'a, C> {
366367
let pio_no = PIO::PIO_NO;
367368
let p = ch.regs();
@@ -379,6 +380,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> {
379380
w.set_chain_to(ch.number());
380381
w.set_incr_read(false);
381382
w.set_incr_write(true);
383+
w.set_bswap(bswap);
382384
w.set_en(true);
383385
});
384386
compiler_fence(Ordering::SeqCst);
@@ -447,7 +449,12 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> {
447449
}
448450

449451
/// Prepare a DMA transfer to TX FIFO.
450-
pub fn dma_push<'a, C: Channel, W: Word>(&'a mut self, ch: PeripheralRef<'a, C>, data: &'a [W]) -> Transfer<'a, C> {
452+
pub fn dma_push<'a, C: Channel, W: Word>(
453+
&'a mut self,
454+
ch: PeripheralRef<'a, C>,
455+
data: &'a [W],
456+
bswap: bool,
457+
) -> Transfer<'a, C> {
451458
let pio_no = PIO::PIO_NO;
452459
let p = ch.regs();
453460
p.read_addr().write_value(data.as_ptr() as u32);
@@ -464,6 +471,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> {
464471
w.set_chain_to(ch.number());
465472
w.set_incr_read(true);
466473
w.set_incr_write(false);
474+
w.set_bswap(bswap);
467475
w.set_en(true);
468476
});
469477
compiler_fence(Ordering::SeqCst);

embassy-rp/src/pio_programs/hd44780.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'l, P: Instance, const S: usize> PioHD44780<'l, P, S> {
173173
sm.set_enable(true);
174174

175175
// display on and cursor on and blinking, reset display
176-
sm.tx().dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1]).await;
176+
sm.tx().dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1], false).await;
177177

178178
Self {
179179
dma: dma.map_into(),
@@ -198,6 +198,6 @@ impl<'l, P: Instance, const S: usize> PioHD44780<'l, P, S> {
198198
// set cursor to 1:15
199199
self.buf[38..].copy_from_slice(&[0x80, 0xcf]);
200200

201-
self.sm.tx().dma_push(self.dma.reborrow(), &self.buf).await;
201+
self.sm.tx().dma_push(self.dma.reborrow(), &self.buf, false).await;
202202
}
203203
}

embassy-rp/src/pio_programs/i2s.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ impl<'a, P: Instance, const S: usize> PioI2sOut<'a, P, S> {
9090

9191
/// Return an in-prograss dma transfer future. Awaiting it will guarentee a complete transfer.
9292
pub fn write<'b>(&'b mut self, buff: &'b [u32]) -> Transfer<'b, AnyChannel> {
93-
self.sm.tx().dma_push(self.dma.reborrow(), buff)
93+
self.sm.tx().dma_push(self.dma.reborrow(), buff, false)
9494
}
9595
}

embassy-rp/src/pio_programs/ws2812.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N> {
111111
}
112112

113113
// DMA transfer
114-
self.sm.tx().dma_push(self.dma.reborrow(), &words).await;
114+
self.sm.tx().dma_push(self.dma.reborrow(), &words, false).await;
115115

116116
Timer::after_micros(55).await;
117117
}

examples/rp/src/bin/pio_dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ async fn main(_spawner: Spawner) {
7272
loop {
7373
let (rx, tx) = sm.rx_tx();
7474
join(
75-
tx.dma_push(dma_out_ref.reborrow(), &dout),
76-
rx.dma_pull(dma_in_ref.reborrow(), &mut din),
75+
tx.dma_push(dma_out_ref.reborrow(), &dout, false),
76+
rx.dma_pull(dma_in_ref.reborrow(), &mut din, false),
7777
)
7878
.await;
7979
for i in 0..din.len() {

examples/rp235x/src/bin/pio_dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ async fn main(_spawner: Spawner) {
7272
loop {
7373
let (rx, tx) = sm.rx_tx();
7474
join(
75-
tx.dma_push(dma_out_ref.reborrow(), &dout),
76-
rx.dma_pull(dma_in_ref.reborrow(), &mut din),
75+
tx.dma_push(dma_out_ref.reborrow(), &dout, false),
76+
rx.dma_pull(dma_in_ref.reborrow(), &mut din, false),
7777
)
7878
.await;
7979
for i in 0..din.len() {

0 commit comments

Comments
 (0)