aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Work <[email protected]>2025-02-06 17:46:04 -0800
committerSteve Work <[email protected]>2025-02-06 17:46:04 -0800
commit9acbfc9c226bc56d4c135a4b3845765043c3429a (patch)
tree5b9a293e6652259fa3a8b16841c30bce5f4111c8
parent4e69e5b3c719ccd73e2dee47294c9f599525997d (diff)
Add PIO functions.
Add some (I think) needed functions: ConfigPins::set_sideset_pins (the other pin types are covered, why not this one?) Several runtime StateMachine manipulations: - addr() - tx_threshold() - set_tx_threshold - rx_threshold() - set_rx_threshold() - set_thresholds() - both at once, same value
-rw-r--r--embassy-rp/src/pio/mod.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs
index 7632d3168..51b526400 100644
--- a/embassy-rp/src/pio/mod.rs
+++ b/embassy-rp/src/pio/mod.rs
@@ -670,6 +670,16 @@ impl<'d, PIO: Instance> Config<'d, PIO> {
670 self.exec.jmp_pin = pin.pin(); 670 self.exec.jmp_pin = pin.pin();
671 } 671 }
672 672
673 /// Sets the range of pins affected by SIDE instructions. The range must be consecutive.
674 /// Set pins must configured as outputs using [`StateMachine::set_pin_dirs`] to be
675 /// effective.
676 pub fn set_sideset_pins(&mut self, pins: &[&Pin<'d, PIO>]) {
677 assert!(pins.len() <= 5);
678 assert_consecutive(pins);
679 self.pins.sideset_base = pins.first().map_or(0, |p| p.pin());
680 self.pins.sideset_count = pins.len() as u8;
681 }
682
673 /// Sets the range of pins affected by SET instructions. The range must be consecutive. 683 /// Sets the range of pins affected by SET instructions. The range must be consecutive.
674 /// Set pins must configured as outputs using [`StateMachine::set_pin_dirs`] to be 684 /// Set pins must configured as outputs using [`StateMachine::set_pin_dirs`] to be
675 /// effective. 685 /// effective.
@@ -816,6 +826,51 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
816 } 826 }
817 } 827 }
818 828
829 /// Read current instruction address for this state machine
830 pub fn addr(&self) -> u8 {
831 let addr = Self::this_sm().addr();
832 addr.read().addr()
833 }
834
835 /// Read TX FIFO threshold for this state machine.
836 pub fn tx_threshold(&self) -> u8 {
837 let shiftctrl = Self::this_sm().shiftctrl();
838 shiftctrl.read().pull_thresh()
839 }
840
841 /// Set/change the TX FIFO threshold for this state machine.
842 pub fn set_tx_threshold(&mut self, threshold: u8) {
843 assert!(threshold <= 31);
844 let shiftctrl = Self::this_sm().shiftctrl();
845 shiftctrl.modify(|w| {
846 w.set_pull_thresh(threshold);
847 });
848 }
849
850 /// Read TX FIFO threshold for this state machine.
851 pub fn rx_threshold(&self) -> u8 {
852 Self::this_sm().shiftctrl().read().push_thresh()
853 }
854
855 /// Set/change the RX FIFO threshold for this state machine.
856 pub fn set_rx_threshold(&mut self, threshold: u8) {
857 assert!(threshold <= 31);
858 let shiftctrl = Self::this_sm().shiftctrl();
859 shiftctrl.modify(|w| {
860 w.set_push_thresh(threshold);
861 });
862 }
863
864 /// Set/change both TX and RX FIFO thresholds for this state machine.
865 pub fn set_thresholds(&mut self, threshold: u8) {
866 assert!(threshold <= 31);
867 let shiftctrl = Self::this_sm().shiftctrl();
868 shiftctrl.modify(|w| {
869 w.set_push_thresh(threshold);
870 w.set_pull_thresh(threshold);
871 });
872 }
873
819 /// Set the clock divider for this state machine. 874 /// Set the clock divider for this state machine.
820 pub fn set_clock_divider(&mut self, clock_divider: FixedU32<U8>) { 875 pub fn set_clock_divider(&mut self, clock_divider: FixedU32<U8>) {
821 let sm = Self::this_sm(); 876 let sm = Self::this_sm();