diff options
| author | Matthew Tran <[email protected]> | 2025-09-20 11:55:59 -0500 |
|---|---|---|
| committer | Matthew Tran <[email protected]> | 2025-09-20 11:56:27 -0500 |
| commit | 6e1d6be315957e587051df7bf96f4a87fc748117 (patch) | |
| tree | 304dd33febc7bd985f0139e2bed3703a12a29a63 /embassy-nrf | |
| parent | 8394e1320844f6a1342f1bff10215cfd4643fe3a (diff) | |
nrf: add persist() method for gpio and ppi
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/CHANGELOG.md | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/gpio.rs | 27 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/dppi.rs | 9 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/mod.rs | 8 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/ppi.rs | 9 | ||||
| -rw-r--r-- | embassy-nrf/src/timer.rs | 4 |
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 | ||
| 78 | impl 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 | ||
| 276 | impl 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 | |||
| 267 | pub(crate) fn convert_drive(w: &mut pac::gpio::regs::PinCnf, drive: OutputDrive) { | 285 | pub(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 | ||
| 468 | impl 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 | |||
| 450 | impl<'d> Drop for Flex<'d> { | 477 | impl<'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 | ||
| 62 | impl<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 | |||
| 62 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { | 71 | impl<'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 | } |
| 111 | impl<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 | ||
| 112 | impl<'d, G: Group> Drop for PpiGroup<'d, G> { | 120 | impl<'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 | ||
| 71 | impl<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 | |||
| 71 | impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { | 80 | impl<'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> { | |||
| 90 | impl<'d, T: Instance> Timer<'d, T> { | 90 | impl<'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) |
