diff options
| author | Dion Dokter <[email protected]> | 2021-10-14 14:45:57 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-10-26 14:46:39 +0200 |
| commit | 4950682a50c8561124462cd7d774a72626271294 (patch) | |
| tree | d3b8b1d2662e939aeebe275f516145fd81361b03 | |
| parent | 65628e1f1538f003c114d97c98970631953e7d6e (diff) | |
Some extra docs and better naming
| -rw-r--r-- | embassy-nrf/src/ppi.rs | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/embassy-nrf/src/ppi.rs b/embassy-nrf/src/ppi.rs index 822663ea2..1f825bf47 100644 --- a/embassy-nrf/src/ppi.rs +++ b/embassy-nrf/src/ppi.rs | |||
| @@ -20,14 +20,16 @@ use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | |||
| 20 | // ====================== | 20 | // ====================== |
| 21 | // driver | 21 | // driver |
| 22 | 22 | ||
| 23 | /// Error type of the PPI driver | ||
| 23 | #[non_exhaustive] | 24 | #[non_exhaustive] |
| 24 | #[derive(Clone, Debug)] | 25 | #[derive(Clone, Debug)] |
| 25 | pub enum Error { | 26 | pub enum Error { |
| 27 | /// There is no capacity to enable this task or event (nRF51 & nRF52 only) | ||
| 26 | NoCapacityLeft, | 28 | NoCapacityLeft, |
| 27 | UnknownTask, | 29 | /// This task or event is not in use by the current channel |
| 28 | TaskAlreadyInUse, | 30 | NotInUseByChannel, |
| 29 | UnknownEvent, | 31 | /// This task or event is already enabled on another channel (nRF53 & nRF91 only) |
| 30 | EventAlreadyInUse, | 32 | AlreadyInUse, |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | pub struct Ppi<'d, C: Channel> { | 35 | pub struct Ppi<'d, C: Channel> { |
| @@ -93,7 +95,7 @@ impl<'d, C: Channel> Ppi<'d, C> { | |||
| 93 | self.set_fork_task(None); | 95 | self.set_fork_task(None); |
| 94 | Ok(()) | 96 | Ok(()) |
| 95 | } else { | 97 | } else { |
| 96 | Err(Error::UnknownTask) | 98 | Err(Error::NotInUseByChannel) |
| 97 | } | 99 | } |
| 98 | } | 100 | } |
| 99 | 101 | ||
| @@ -113,7 +115,7 @@ impl<'d, C: Channel> Ppi<'d, C> { | |||
| 113 | self.set_event(None); | 115 | self.set_event(None); |
| 114 | Ok(()) | 116 | Ok(()) |
| 115 | } else { | 117 | } else { |
| 116 | Err(Error::UnknownEvent) | 118 | Err(Error::NotInUseByChannel) |
| 117 | } | 119 | } |
| 118 | } | 120 | } |
| 119 | 121 | ||
| @@ -249,7 +251,7 @@ impl<'d, C: Channel> Ppi<'d, C> { | |||
| 249 | pub fn subscribe(&mut self, task: Task) -> Result<(), Error> { | 251 | pub fn subscribe(&mut self, task: Task) -> Result<(), Error> { |
| 250 | unsafe { | 252 | unsafe { |
| 251 | if Self::is_register_enabled(task.0) { | 253 | if Self::is_register_enabled(task.0) { |
| 252 | Err(Error::TaskAlreadyInUse) | 254 | Err(Error::AlreadyInUse) |
| 253 | } else { | 255 | } else { |
| 254 | Self::set_register_active(task.0, self.ch.number() as u8); | 256 | Self::set_register_active(task.0, self.ch.number() as u8); |
| 255 | Ok(()) | 257 | Ok(()) |
| @@ -261,7 +263,7 @@ impl<'d, C: Channel> Ppi<'d, C> { | |||
| 261 | pub fn unsubscribe(&mut self, task: Task) -> Result<(), Error> { | 263 | pub fn unsubscribe(&mut self, task: Task) -> Result<(), Error> { |
| 262 | unsafe { | 264 | unsafe { |
| 263 | if Self::get_register_channel(task.0) != self.ch.number() as u8 { | 265 | if Self::get_register_channel(task.0) != self.ch.number() as u8 { |
| 264 | Err(Error::UnknownTask) | 266 | Err(Error::NotInUseByChannel) |
| 265 | } else { | 267 | } else { |
| 266 | Self::set_register_inactive(task.0); | 268 | Self::set_register_inactive(task.0); |
| 267 | Ok(()) | 269 | Ok(()) |
| @@ -273,7 +275,7 @@ impl<'d, C: Channel> Ppi<'d, C> { | |||
| 273 | pub fn publish(&mut self, event: Event) -> Result<(), Error> { | 275 | pub fn publish(&mut self, event: Event) -> Result<(), Error> { |
| 274 | unsafe { | 276 | unsafe { |
| 275 | if Self::is_register_enabled(event.0) { | 277 | if Self::is_register_enabled(event.0) { |
| 276 | Err(Error::TaskAlreadyInUse) | 278 | Err(Error::AlreadyInUse) |
| 277 | } else { | 279 | } else { |
| 278 | Self::set_register_active(event.0, self.ch.number() as u8); | 280 | Self::set_register_active(event.0, self.ch.number() as u8); |
| 279 | Ok(()) | 281 | Ok(()) |
| @@ -285,7 +287,7 @@ impl<'d, C: Channel> Ppi<'d, C> { | |||
| 285 | pub fn unpublish(&mut self, event: Event) -> Result<(), Error> { | 287 | pub fn unpublish(&mut self, event: Event) -> Result<(), Error> { |
| 286 | unsafe { | 288 | unsafe { |
| 287 | if Self::get_register_channel(event.0) != self.ch.number() as u8 { | 289 | if Self::get_register_channel(event.0) != self.ch.number() as u8 { |
| 288 | Err(Error::UnknownTask) | 290 | Err(Error::NotInUseByChannel) |
| 289 | } else { | 291 | } else { |
| 290 | Self::set_register_inactive(event.0); | 292 | Self::set_register_inactive(event.0); |
| 291 | Ok(()) | 293 | Ok(()) |
| @@ -382,8 +384,22 @@ pub(crate) mod sealed { | |||
| 382 | } | 384 | } |
| 383 | 385 | ||
| 384 | pub trait Channel: sealed::Channel + Sized { | 386 | pub trait Channel: sealed::Channel + Sized { |
| 387 | /// Returns the number of the channel | ||
| 385 | fn number(&self) -> usize; | 388 | fn number(&self) -> usize; |
| 389 | |||
| 390 | /// Returns the amount of configurable tasks this channel has. | ||
| 391 | /// | ||
| 392 | /// - MAX for DPPI with unlimited capacity (nRF53 & nRF91) | ||
| 393 | /// - 0 for static channel without fork (nRF51) | ||
| 394 | /// - 1 for static channel with fork (nRF52) or for configurable channel (nRF51) | ||
| 395 | /// - 2 for configurable channel with fork (nRF52) | ||
| 386 | fn task_capacity(&self) -> usize; | 396 | fn task_capacity(&self) -> usize; |
| 397 | |||
| 398 | /// Returns the amount of configurable events this channels has | ||
| 399 | /// | ||
| 400 | /// - MAX for DPPI with unlimited capacity (nRF53 & nRF91) | ||
| 401 | /// - 0 for static channel (nRF51 & nRF52) | ||
| 402 | /// - 1 for configurable channel (nRF51 & nRF52) | ||
| 387 | fn event_capacity(&self) -> usize; | 403 | fn event_capacity(&self) -> usize; |
| 388 | 404 | ||
| 389 | fn degrade(self) -> AnyChannel { | 405 | fn degrade(self) -> AnyChannel { |
