Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to clear PIO fifos #670

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions rp2040-hal/src/pio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,22 @@ impl<SM: ValidStateMachine, State> StateMachine<SM, State> {
unsafe { self.sm.sm().sm_execctrl.read().exec_stalled().bit() }
}

/// Clear both TX and RX FIFOs
pub fn clear_fifos(&mut self) {
// Safety: all accesses to these registers are controlled by this instance
unsafe {
let sm = &self.sm.sm();
let sm_shiftctrl = &sm.sm_shiftctrl;
let mut current = false;
// Toggling the FIFO join state clears the fifo
sm_shiftctrl.modify(|r, w| {
current = r.fjoin_rx().bit();
w.fjoin_rx().bit(!current)
});
sm_shiftctrl.modify(|_, w| w.fjoin_rx().bit(current));
}
}

/// Drain Tx fifo.
pub fn drain_tx_fifo(&mut self) {
// According to the datasheet 3.5.4.2 Page 358:
Expand Down
Loading