diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-02-07 20:28:07 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-02-07 20:28:07 +0100 |
| commit | 3b734a7d0819c1e92f16b358dfc57bacf162f265 (patch) | |
| tree | 7d1e3b5b9bfaeac1fbd91cb42e1965b02b39d7b3 | |
| parent | f2a6014cd36152a791c0c27b6dd3f6565f5e1a4c (diff) | |
| parent | 3b74732f40c8fa65e3bdfc1d3ee65c59e9b01a71 (diff) | |
Merge pull request #3857 from swork/swork-add-pio-functions
Add PIO functions.
| -rw-r--r-- | embassy-rp/src/pio/mod.rs | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs index 7632d3168..2776f9e3c 100644 --- a/embassy-rp/src/pio/mod.rs +++ b/embassy-rp/src/pio/mod.rs | |||
| @@ -651,7 +651,7 @@ impl<'d, PIO: Instance> Config<'d, PIO> { | |||
| 651 | /// of the program. The state machine is not started. | 651 | /// of the program. The state machine is not started. |
| 652 | /// | 652 | /// |
| 653 | /// `side_set` sets the range of pins affected by side-sets. The range must be consecutive. | 653 | /// `side_set` sets the range of pins affected by side-sets. The range must be consecutive. |
| 654 | /// Side-set pins must configured as outputs using [`StateMachine::set_pin_dirs`] to be | 654 | /// Sideset pins must configured as outputs using [`StateMachine::set_pin_dirs`] to be |
| 655 | /// effective. | 655 | /// effective. |
| 656 | pub fn use_program(&mut self, prog: &LoadedProgram<'d, PIO>, side_set: &[&Pin<'d, PIO>]) { | 656 | pub fn use_program(&mut self, prog: &LoadedProgram<'d, PIO>, side_set: &[&Pin<'d, PIO>]) { |
| 657 | assert!((prog.side_set.bits() - prog.side_set.optional() as u8) as usize == side_set.len()); | 657 | assert!((prog.side_set.bits() - prog.side_set.optional() as u8) as usize == side_set.len()); |
| @@ -816,6 +816,51 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { | |||
| 816 | } | 816 | } |
| 817 | } | 817 | } |
| 818 | 818 | ||
| 819 | /// Read current instruction address for this state machine | ||
| 820 | pub fn get_addr(&self) -> u8 { | ||
| 821 | let addr = Self::this_sm().addr(); | ||
| 822 | addr.read().addr() | ||
| 823 | } | ||
| 824 | |||
| 825 | /// Read TX FIFO threshold for this state machine. | ||
| 826 | pub fn get_tx_threshold(&self) -> u8 { | ||
| 827 | let shiftctrl = Self::this_sm().shiftctrl(); | ||
| 828 | shiftctrl.read().pull_thresh() | ||
| 829 | } | ||
| 830 | |||
| 831 | /// Set/change the TX FIFO threshold for this state machine. | ||
| 832 | pub fn set_tx_threshold(&mut self, threshold: u8) { | ||
| 833 | assert!(threshold <= 31); | ||
| 834 | let shiftctrl = Self::this_sm().shiftctrl(); | ||
| 835 | shiftctrl.modify(|w| { | ||
| 836 | w.set_pull_thresh(threshold); | ||
| 837 | }); | ||
| 838 | } | ||
| 839 | |||
| 840 | /// Read TX FIFO threshold for this state machine. | ||
| 841 | pub fn get_rx_threshold(&self) -> u8 { | ||
| 842 | Self::this_sm().shiftctrl().read().push_thresh() | ||
| 843 | } | ||
| 844 | |||
| 845 | /// Set/change the RX FIFO threshold for this state machine. | ||
| 846 | pub fn set_rx_threshold(&mut self, threshold: u8) { | ||
| 847 | assert!(threshold <= 31); | ||
| 848 | let shiftctrl = Self::this_sm().shiftctrl(); | ||
| 849 | shiftctrl.modify(|w| { | ||
| 850 | w.set_push_thresh(threshold); | ||
| 851 | }); | ||
| 852 | } | ||
| 853 | |||
| 854 | /// Set/change both TX and RX FIFO thresholds for this state machine. | ||
| 855 | pub fn set_thresholds(&mut self, threshold: u8) { | ||
| 856 | assert!(threshold <= 31); | ||
| 857 | let shiftctrl = Self::this_sm().shiftctrl(); | ||
| 858 | shiftctrl.modify(|w| { | ||
| 859 | w.set_push_thresh(threshold); | ||
| 860 | w.set_pull_thresh(threshold); | ||
| 861 | }); | ||
| 862 | } | ||
| 863 | |||
| 819 | /// Set the clock divider for this state machine. | 864 | /// Set the clock divider for this state machine. |
| 820 | pub fn set_clock_divider(&mut self, clock_divider: FixedU32<U8>) { | 865 | pub fn set_clock_divider(&mut self, clock_divider: FixedU32<U8>) { |
| 821 | let sm = Self::this_sm(); | 866 | let sm = Self::this_sm(); |
