From 2aa2b843ce6b96aacd72e52fe29b550e7ebc55b3 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 29 Jun 2023 17:11:36 +0200 Subject: [PATCH 1/3] feature(1355): Add trigger to task, triggered + clear to Event --- embassy-nrf/src/ppi/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index 7c18da6e..ba95849e 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs @@ -137,6 +137,11 @@ impl Task { Self(ptr) } + // Triggers this task. + pub unsafe fn trigger(&mut self) { + self.0.write(|w| unsafe { w.bits(1) }); + } + pub(crate) fn from_reg(reg: &T) -> Self { Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) } @@ -173,6 +178,16 @@ impl Event { Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) } + // Describes whether this Event is currently in a triggered state. + pub unsafe fn is_triggered(&self) -> bool { + self.0.read().bits() == 1 + } + + // Clear the current register's triggered state, reverting it to 0. + pub unsafe fn clear(&mut self) { + self.0.write(|w| unsafe { w.bits(0) }); + } + /// Address of publish register for this event. #[cfg(feature = "_dppi")] pub fn publish_reg(&self) -> *mut u32 { From e90f47aba31be9d99935c758d87941c7106cbece Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 29 Jun 2023 17:37:51 +0200 Subject: [PATCH 2/3] Fixed Pointer Updates --- embassy-nrf/src/ppi/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index ba95849e..0789e269 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs @@ -137,9 +137,9 @@ impl Task { Self(ptr) } - // Triggers this task. + /// Triggers this task. pub unsafe fn trigger(&mut self) { - self.0.write(|w| unsafe { w.bits(1) }); + *self.0.as_ptr() = 1; } pub(crate) fn from_reg(reg: &T) -> Self { @@ -178,14 +178,14 @@ impl Event { Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) } - // Describes whether this Event is currently in a triggered state. + /// Describes whether this Event is currently in a triggered state. pub unsafe fn is_triggered(&self) -> bool { - self.0.read().bits() == 1 + *self.0.as_ptr() == 1 } - // Clear the current register's triggered state, reverting it to 0. + /// Clear the current register's triggered state, reverting it to 0. pub unsafe fn clear(&mut self) { - self.0.write(|w| unsafe { w.bits(0) }); + *self.0.as_ptr() = 0; } /// Address of publish register for this event. From 3f19879f41e8c39c5c38e7905a180160b24807fc Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 29 Jun 2023 17:44:46 +0200 Subject: [PATCH 3/3] PR Fixes --- embassy-nrf/src/ppi/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index 0789e269..76757a24 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs @@ -138,8 +138,8 @@ impl Task { } /// Triggers this task. - pub unsafe fn trigger(&mut self) { - *self.0.as_ptr() = 1; + pub fn trigger(&mut self) { + unsafe { self.0.as_ptr().write_volatile(1) }; } pub(crate) fn from_reg(reg: &T) -> Self { @@ -179,13 +179,13 @@ impl Event { } /// Describes whether this Event is currently in a triggered state. - pub unsafe fn is_triggered(&self) -> bool { - *self.0.as_ptr() == 1 + pub fn is_triggered(&self) -> bool { + unsafe { self.0.as_ptr().read_volatile() == 1 } } /// Clear the current register's triggered state, reverting it to 0. - pub unsafe fn clear(&mut self) { - *self.0.as_ptr() = 0; + pub fn clear(&mut self) { + unsafe { self.0.as_ptr().write_volatile(0) }; } /// Address of publish register for this event.