aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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> {