diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index e3ac45d7..8f5ed14c 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs @@ -39,13 +39,22 @@ pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize const REGISTER_DPPI_CONFIG_OFFSET: usize = 0x80 / core::mem::size_of::(); /// Represents a task that a peripheral can do. -/// When a task is subscribed to a PPI channel it will run when the channel is triggered by -/// a published event. /// -/// The pointer is to a task register +/// When a task is subscribed to a PPI channel, it will run when the channel is triggered by +/// a published event. #[derive(PartialEq, Eq, Clone, Copy)] -pub struct Task(pub NonNull); +pub struct Task(NonNull); + impl Task { + /// Create a new `Task` from a task register pointer + /// + /// # Safety + /// + /// `ptr` must be a pointer to a valid `TASKS_*` register from an nRF peripheral. + pub unsafe fn new_unchecked(ptr: NonNull) -> Self { + Self(ptr) + } + pub(crate) fn from_reg(reg: &T) -> Self { Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) } @@ -63,12 +72,21 @@ impl Task { unsafe impl Send for Task {} /// Represents an event that a peripheral can publish. -/// An event can be set to publish on a PPI channel when the event happens. /// -/// The pointer is to an event register +/// An event can be set to publish on a PPI channel when the event happens. #[derive(PartialEq, Eq, Clone, Copy)] -pub struct Event(pub NonNull); +pub struct Event(NonNull); + impl Event { + /// Create a new `Event` from an event register pointer + /// + /// # Safety + /// + /// `ptr` must be a pointer to a valid `EVENTS_*` register from an nRF peripheral. + pub unsafe fn new_unchecked(ptr: NonNull) -> Self { + Self(ptr) + } + pub(crate) fn from_reg(reg: &T) -> Self { Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) }