Skip to content

Commit

Permalink
RP235x: First stab at support for new FIFO options
Browse files Browse the repository at this point in the history
  • Loading branch information
pferreir committed Sep 24, 2024
1 parent 0ede847 commit 9a215a4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions embassy-rp/src/pio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ pub enum FifoJoin {
RxOnly,
/// Tx fifo twice as deep. RX fifo disabled
TxOnly,
/// Enable random writes (`FJOIN_RX_PUT`) from the state machine (through ISR),
/// and random reads from the system (using [`StateMachine::get_rxf_entry`]).
#[cfg(feature = "_rp235x")]
RxAsStatus,
/// Enable random reads (`FJOIN_RX_GET`) from the state machine (through OSR),
/// and random writes from the system (using [`StateMachine::set_rxf_entry`]).
#[cfg(feature = "_rp235x")]
RxAsControl,
/// FJOIN_RX_PUT | FJOIN_RX_GET: RX can be used as a scratch register,
/// not accesible from the CPU
#[cfg(feature = "_rp235x")]
PioScratch,
}

/// Shift direction.
Expand Down Expand Up @@ -730,6 +742,17 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
w.set_in_shiftdir(config.shift_in.direction == ShiftDirection::Right);
w.set_autopull(config.shift_out.auto_fill);
w.set_autopush(config.shift_in.auto_fill);

#[cfg(feature = "_rp235x")]
{
w.set_fjoin_rx_get(
config.fifo_join == FifoJoin::RxAsControl || config.fifo_join == FifoJoin::PioScratch,
);
w.set_fjoin_rx_put(
config.fifo_join == FifoJoin::RxAsStatus || config.fifo_join == FifoJoin::PioScratch,
);
w.set_in_count(config.in_count);
}
});

#[cfg(feature = "rp2040")]
Expand Down Expand Up @@ -907,6 +930,20 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
pub fn rx_tx(&mut self) -> (&mut StateMachineRx<'d, PIO, SM>, &mut StateMachineTx<'d, PIO, SM>) {
(&mut self.rx, &mut self.tx)
}

/// Return the contents of the nth entry of the RX FIFO
/// (should be used only when the FIFO config is set to [`FifoJoin::RxAsStatus`])
#[cfg(feature = "_rp235x")]
pub fn get_rxf_entry(&self, n: usize) -> u32 {
PIO::PIO.rxf_putget(SM).putget(n).read()
}

/// Set the contents of the nth entry of the RX FIFO
/// (should be used only when the FIFO config is set to [`FifoJoin::RxAsControl`])
#[cfg(feature = "_rp235x")]
pub fn set_rxf_entry(&self, n: usize, val: u32) {
PIO::PIO.rxf_putget(SM).putget(n).write_value(val)
}
}

/// PIO handle.
Expand Down

0 comments on commit 9a215a4

Please sign in to comment.