aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-09-21 14:38:07 +0000
committerGitHub <[email protected]>2025-09-21 14:38:07 +0000
commit483a9ad53ae949f7f78cdf8764c990ab434f25e4 (patch)
tree9d4a1a7c6054ce3efa81f17bf9d47721717c3d3d
parent034210249419e1fd87f0b68a2b02925ce7a48083 (diff)
parent6e1d6be315957e587051df7bf96f4a87fc748117 (diff)
Merge pull request #4687 from 0e4ef622/persist
nrf: add persist() method for gpio and ppi
-rw-r--r--embassy-nrf/CHANGELOG.md1
-rw-r--r--embassy-nrf/src/gpio.rs27
-rw-r--r--embassy-nrf/src/ppi/dppi.rs9
-rw-r--r--embassy-nrf/src/ppi/mod.rs8
-rw-r--r--embassy-nrf/src/ppi/ppi.rs9
-rw-r--r--embassy-nrf/src/timer.rs4
6 files changed, 56 insertions, 2 deletions
diff --git a/embassy-nrf/CHANGELOG.md b/embassy-nrf/CHANGELOG.md
index befa34ecf..de8dfd391 100644
--- a/embassy-nrf/CHANGELOG.md
+++ b/embassy-nrf/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10 10
11- changed: nrf54l: Disable glitch detection and enable DC/DC in init. 11- changed: nrf54l: Disable glitch detection and enable DC/DC in init.
12- changed: Add embassy-net-driver-channel implementation for IEEE 802.15.4 12- changed: Add embassy-net-driver-channel implementation for IEEE 802.15.4
13- changed: add persist() method for gpio and ppi
13 14
14## 0.7.0 - 2025-08-26 15## 0.7.0 - 2025-08-26
15 16
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index 65f2d99f7..0cea38777 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -75,6 +75,15 @@ impl<'d> Input<'d> {
75 } 75 }
76} 76}
77 77
78impl Input<'static> {
79 /// Persist the pin's configuration for the rest of the program's lifetime. This method should
80 /// be preferred over [`core::mem::forget()`] because the `'static` bound prevents accidental
81 /// reuse of the underlying peripheral.
82 pub fn persist(self) {
83 self.pin.persist()
84 }
85}
86
78/// Digital input or output level. 87/// Digital input or output level.
79#[derive(Clone, Copy, Debug, Eq, PartialEq)] 88#[derive(Clone, Copy, Debug, Eq, PartialEq)]
80#[cfg_attr(feature = "defmt", derive(defmt::Format))] 89#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -264,6 +273,15 @@ impl<'d> Output<'d> {
264 } 273 }
265} 274}
266 275
276impl Output<'static> {
277 /// Persist the pin's configuration for the rest of the program's lifetime. This method should
278 /// be preferred over [`core::mem::forget()`] because the `'static` bound prevents accidental
279 /// reuse of the underlying peripheral.
280 pub fn persist(self) {
281 self.pin.persist()
282 }
283}
284
267pub(crate) fn convert_drive(w: &mut pac::gpio::regs::PinCnf, drive: OutputDrive) { 285pub(crate) fn convert_drive(w: &mut pac::gpio::regs::PinCnf, drive: OutputDrive) {
268 #[cfg(not(feature = "_nrf54l"))] 286 #[cfg(not(feature = "_nrf54l"))]
269 { 287 {
@@ -447,6 +465,15 @@ impl<'d> Flex<'d> {
447 } 465 }
448} 466}
449 467
468impl Flex<'static> {
469 /// Persist the pin's configuration for the rest of the program's lifetime. This method should
470 /// be preferred over [`core::mem::forget()`] because the `'static` bound prevents accidental
471 /// reuse of the underlying peripheral.
472 pub fn persist(self) {
473 core::mem::forget(self);
474 }
475}
476
450impl<'d> Drop for Flex<'d> { 477impl<'d> Drop for Flex<'d> {
451 fn drop(&mut self) { 478 fn drop(&mut self) {
452 self.set_as_disconnected(); 479 self.set_as_disconnected();
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs
index 686f66987..078d2fd1c 100644
--- a/embassy-nrf/src/ppi/dppi.rs
+++ b/embassy-nrf/src/ppi/dppi.rs
@@ -59,6 +59,15 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d,
59 } 59 }
60} 60}
61 61
62impl<C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'static, C, EVENT_COUNT, TASK_COUNT> {
63 /// Persist the channel's configuration for the rest of the program's lifetime. This method
64 /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents
65 /// accidental reuse of the underlying peripheral.
66 pub fn persist(self) {
67 core::mem::forget(self);
68 }
69}
70
62impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { 71impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> {
63 fn drop(&mut self) { 72 fn drop(&mut self) {
64 self.disable(); 73 self.disable();
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index 531777205..2bcf72e9c 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -108,6 +108,14 @@ impl<'d, G: Group> PpiGroup<'d, G> {
108 Task::from_reg(regs().tasks_chg(n).dis()) 108 Task::from_reg(regs().tasks_chg(n).dis())
109 } 109 }
110} 110}
111impl<G: Group> PpiGroup<'static, G> {
112 /// Persist this group's configuration for the rest of the program's lifetime. This method
113 /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents
114 /// accidental reuse of the underlying peripheral.
115 pub fn persist(self) {
116 core::mem::forget(self);
117 }
118}
111 119
112impl<'d, G: Group> Drop for PpiGroup<'d, G> { 120impl<'d, G: Group> Drop for PpiGroup<'d, G> {
113 fn drop(&mut self) { 121 fn drop(&mut self) {
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs
index e04dacbc0..531c25444 100644
--- a/embassy-nrf/src/ppi/ppi.rs
+++ b/embassy-nrf/src/ppi/ppi.rs
@@ -68,6 +68,15 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d,
68 } 68 }
69} 69}
70 70
71impl<C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'static, C, EVENT_COUNT, TASK_COUNT> {
72 /// Persist the channel's configuration for the rest of the program's lifetime. This method
73 /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents
74 /// accidental reuse of the underlying peripheral.
75 pub fn persist(self) {
76 core::mem::forget(self);
77 }
78}
79
71impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { 80impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> {
72 fn drop(&mut self) { 81 fn drop(&mut self) {
73 self.disable(); 82 self.disable();
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index 5b58b0a50..de2875765 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -90,7 +90,7 @@ pub struct Timer<'d, T: Instance> {
90impl<'d, T: Instance> Timer<'d, T> { 90impl<'d, T: Instance> Timer<'d, T> {
91 /// Create a new `Timer` driver. 91 /// Create a new `Timer` driver.
92 /// 92 ///
93 /// This can be useful for triggering tasks via PPI 93 /// This can be useful for triggering tasks via PPI.
94 /// `Uarte` uses this internally. 94 /// `Uarte` uses this internally.
95 pub fn new(timer: Peri<'d, T>) -> Self { 95 pub fn new(timer: Peri<'d, T>) -> Self {
96 Self::new_inner(timer, false) 96 Self::new_inner(timer, false)
@@ -98,7 +98,7 @@ impl<'d, T: Instance> Timer<'d, T> {
98 98
99 /// Create a new `Timer` driver in counter mode. 99 /// Create a new `Timer` driver in counter mode.
100 /// 100 ///
101 /// This can be useful for triggering tasks via PPI 101 /// This can be useful for triggering tasks via PPI.
102 /// `Uarte` uses this internally. 102 /// `Uarte` uses this internally.
103 pub fn new_counter(timer: Peri<'d, T>) -> Self { 103 pub fn new_counter(timer: Peri<'d, T>) -> Self {
104 Self::new_inner(timer, true) 104 Self::new_inner(timer, true)