aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorCameron <[email protected]>2023-06-29 18:09:26 +0200
committerCameron <[email protected]>2023-06-29 18:09:26 +0200
commit24e186e6849223ee076e0fabdfed07d2cd7f7baf (patch)
tree0d52ab5639e8bd5d1e7200c8076baa4a8500078c /embassy-nrf
parent3f19879f41e8c39c5c38e7905a180160b24807fc (diff)
feature(1354): Added lifetimes to Event +
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/ppi/mod.rs29
-rw-r--r--embassy-nrf/src/ppi/ppi.rs4
2 files changed, 20 insertions, 13 deletions
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index 76757a248..f6771c2a3 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -15,6 +15,7 @@
15//! many tasks and events, but any single task or event can only be coupled with one channel. 15//! many tasks and events, but any single task or event can only be coupled with one channel.
16//! 16//!
17 17
18use core::marker::PhantomData;
18use core::ptr::NonNull; 19use core::ptr::NonNull;
19 20
20use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; 21use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef};
@@ -125,16 +126,16 @@ const REGISTER_DPPI_CONFIG_OFFSET: usize = 0x80 / core::mem::size_of::<u32>();
125/// When a task is subscribed to a PPI channel, it will run when the channel is triggered by 126/// When a task is subscribed to a PPI channel, it will run when the channel is triggered by
126/// a published event. 127/// a published event.
127#[derive(PartialEq, Eq, Clone, Copy)] 128#[derive(PartialEq, Eq, Clone, Copy)]
128pub struct Task(NonNull<u32>); 129pub struct Task<'d>(NonNull<u32>, PhantomData<&'d ()>);
129 130
130impl Task { 131impl<'d> Task<'_> {
131 /// Create a new `Task` from a task register pointer 132 /// Create a new `Task` from a task register pointer
132 /// 133 ///
133 /// # Safety 134 /// # Safety
134 /// 135 ///
135 /// `ptr` must be a pointer to a valid `TASKS_*` register from an nRF peripheral. 136 /// `ptr` must be a pointer to a valid `TASKS_*` register from an nRF peripheral.
136 pub unsafe fn new_unchecked(ptr: NonNull<u32>) -> Self { 137 pub unsafe fn new_unchecked(ptr: NonNull<u32>) -> Self {
137 Self(ptr) 138 Self(ptr, PhantomData)
138 } 139 }
139 140
140 /// Triggers this task. 141 /// Triggers this task.
@@ -143,7 +144,10 @@ impl Task {
143 } 144 }
144 145
145 pub(crate) fn from_reg<T>(reg: &T) -> Self { 146 pub(crate) fn from_reg<T>(reg: &T) -> Self {
146 Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) 147 Self(
148 unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) },
149 PhantomData,
150 )
147 } 151 }
148 152
149 /// Address of subscription register for this task. 153 /// Address of subscription register for this task.
@@ -156,26 +160,29 @@ impl Task {
156/// # Safety 160/// # Safety
157/// 161///
158/// NonNull is not send, but this event is only allowed to point at registers and those exist in any context on the same core. 162/// NonNull is not send, but this event is only allowed to point at registers and those exist in any context on the same core.
159unsafe impl Send for Task {} 163unsafe impl Send for Task<'_> {}
160 164
161/// Represents an event that a peripheral can publish. 165/// Represents an event that a peripheral can publish.
162/// 166///
163/// An event can be set to publish on a PPI channel when the event happens. 167/// An event can be set to publish on a PPI channel when the event happens.
164#[derive(PartialEq, Eq, Clone, Copy)] 168#[derive(PartialEq, Eq, Clone, Copy)]
165pub struct Event(NonNull<u32>); 169pub struct Event<'d>(NonNull<u32>, PhantomData<&'d ()>);
166 170
167impl Event { 171impl<'d> Event<'_> {
168 /// Create a new `Event` from an event register pointer 172 /// Create a new `Event` from an event register pointer
169 /// 173 ///
170 /// # Safety 174 /// # Safety
171 /// 175 ///
172 /// `ptr` must be a pointer to a valid `EVENTS_*` register from an nRF peripheral. 176 /// `ptr` must be a pointer to a valid `EVENTS_*` register from an nRF peripheral.
173 pub unsafe fn new_unchecked(ptr: NonNull<u32>) -> Self { 177 pub unsafe fn new_unchecked(ptr: NonNull<u32>) -> Self {
174 Self(ptr) 178 Self(ptr, PhantomData)
175 } 179 }
176 180
177 pub(crate) fn from_reg<T>(reg: &T) -> Self { 181 pub(crate) fn from_reg<T>(reg: &'d T) -> Self {
178 Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) 182 Self(
183 unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) },
184 PhantomData,
185 )
179 } 186 }
180 187
181 /// Describes whether this Event is currently in a triggered state. 188 /// Describes whether this Event is currently in a triggered state.
@@ -198,7 +205,7 @@ impl Event {
198/// # Safety 205/// # Safety
199/// 206///
200/// NonNull is not send, but this event is only allowed to point at registers and those exist in any context on the same core. 207/// NonNull is not send, but this event is only allowed to point at registers and those exist in any context on the same core.
201unsafe impl Send for Event {} 208unsafe impl Send for Event<'_> {}
202 209
203// ====================== 210// ======================
204// traits 211// traits
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs
index f1eeaee1e..6e8a669d3 100644
--- a/embassy-nrf/src/ppi/ppi.rs
+++ b/embassy-nrf/src/ppi/ppi.rs
@@ -3,12 +3,12 @@ use embassy_hal_common::into_ref;
3use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; 3use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task};
4use crate::{pac, Peripheral}; 4use crate::{pac, Peripheral};
5 5
6impl Task { 6impl<'d> Task<'_> {
7 fn reg_val(&self) -> u32 { 7 fn reg_val(&self) -> u32 {
8 self.0.as_ptr() as _ 8 self.0.as_ptr() as _
9 } 9 }
10} 10}
11impl Event { 11impl<'d> Event<'_> {
12 fn reg_val(&self) -> u32 { 12 fn reg_val(&self) -> u32 {
13 self.0.as_ptr() as _ 13 self.0.as_ptr() as _
14 } 14 }