aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp
diff options
context:
space:
mode:
authorpennae <[email protected]>2023-05-06 12:23:53 +0200
committerpennae <[email protected]>2023-05-06 17:23:41 +0200
commitbdcea84ca106a0bd3a131fa1de4fb35218e9149a (patch)
treefe620ec6a717f9e7b025eb205622ca1ef7338d8a /embassy-rp
parent8e4d65e163bd484efc4fb31d20b14e6ac4a88de7 (diff)
rp/pio: add sm batch operations
sometimes state machines need to be started, restarted, or synchronized at exactly the same time. the current interface does not allow this but the hardware does, so let's expose that.
Diffstat (limited to 'embassy-rp')
-rw-r--r--embassy-rp/src/pio.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/embassy-rp/src/pio.rs b/embassy-rp/src/pio.rs
index a1b7cf1c5..7cf605d8e 100644
--- a/embassy-rp/src/pio.rs
+++ b/embassy-rp/src/pio.rs
@@ -912,6 +912,47 @@ impl<'d, PIO: Instance> Common<'d, PIO> {
912 pio: PhantomData::default(), 912 pio: PhantomData::default(),
913 } 913 }
914 } 914 }
915
916 pub fn apply_sm_batch(&mut self, f: impl FnOnce(&mut PioBatch<'d, PIO>)) {
917 let mut batch = PioBatch {
918 clkdiv_restart: 0,
919 sm_restart: 0,
920 sm_enable_mask: 0,
921 sm_enable: 0,
922 _pio: PhantomData,
923 };
924 f(&mut batch);
925 unsafe {
926 PIO::PIO.ctrl().modify(|w| {
927 w.set_clkdiv_restart(batch.clkdiv_restart);
928 w.set_sm_restart(batch.sm_restart);
929 w.set_sm_enable((w.sm_enable() & !batch.sm_enable_mask) | batch.sm_enable);
930 });
931 }
932 }
933}
934
935pub struct PioBatch<'a, PIO: Instance> {
936 clkdiv_restart: u8,
937 sm_restart: u8,
938 sm_enable_mask: u8,
939 sm_enable: u8,
940 _pio: PhantomData<&'a PIO>,
941}
942
943impl<'a, PIO: Instance> PioBatch<'a, PIO> {
944 pub fn restart_clockdiv<const SM: usize>(&mut self, _sm: &mut StateMachine<'a, PIO, SM>) {
945 self.clkdiv_restart |= 1 << SM;
946 }
947
948 pub fn restart<const SM: usize>(&mut self, _sm: &mut StateMachine<'a, PIO, SM>) {
949 self.clkdiv_restart |= 1 << SM;
950 }
951
952 pub fn set_enable<const SM: usize>(&mut self, _sm: &mut StateMachine<'a, PIO, SM>, enable: bool) {
953 self.sm_enable_mask |= 1 << SM;
954 self.sm_enable |= (enable as u8) << SM;
955 }
915} 956}
916 957
917pub struct Irq<'d, PIO: Instance, const N: usize> { 958pub struct Irq<'d, PIO: Instance, const N: usize> {