diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-nrf/src/ppi | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-nrf/src/ppi')
| -rw-r--r-- | embassy-nrf/src/ppi/dppi.rs | 16 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/mod.rs | 76 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/ppi.rs | 16 |
3 files changed, 30 insertions, 78 deletions
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs index 3c7b96df7..686f66987 100644 --- a/embassy-nrf/src/ppi/dppi.rs +++ b/embassy-nrf/src/ppi/dppi.rs | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | use embassy_hal_internal::into_ref; | ||
| 2 | |||
| 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; | 1 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; |
| 4 | use crate::{pac, Peripheral}; | 2 | use crate::{pac, Peri}; |
| 5 | 3 | ||
| 6 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; | 4 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; |
| 7 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; | 5 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; |
| @@ -12,14 +10,14 @@ pub(crate) fn regs() -> pac::dppic::Dppic { | |||
| 12 | 10 | ||
| 13 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 11 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { |
| 14 | /// Configure PPI channel to trigger `task` on `event`. | 12 | /// Configure PPI channel to trigger `task` on `event`. |
| 15 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task: Task<'d>) -> Self { | 13 | pub fn new_one_to_one(ch: Peri<'d, C>, event: Event<'d>, task: Task<'d>) -> Self { |
| 16 | Ppi::new_many_to_many(ch, [event], [task]) | 14 | Ppi::new_many_to_many(ch, [event], [task]) |
| 17 | } | 15 | } |
| 18 | } | 16 | } |
| 19 | 17 | ||
| 20 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 18 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 21 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. | 19 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. |
| 22 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { | 20 | pub fn new_one_to_two(ch: Peri<'d, C>, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { |
| 23 | Ppi::new_many_to_many(ch, [event], [task1, task2]) | 21 | Ppi::new_many_to_many(ch, [event], [task1, task2]) |
| 24 | } | 22 | } |
| 25 | } | 23 | } |
| @@ -28,13 +26,7 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi | |||
| 28 | Ppi<'d, C, EVENT_COUNT, TASK_COUNT> | 26 | Ppi<'d, C, EVENT_COUNT, TASK_COUNT> |
| 29 | { | 27 | { |
| 30 | /// Configure a DPPI channel to trigger all `tasks` when any of the `events` fires. | 28 | /// Configure a DPPI channel to trigger all `tasks` when any of the `events` fires. |
| 31 | pub fn new_many_to_many( | 29 | pub fn new_many_to_many(ch: Peri<'d, C>, events: [Event<'d>; EVENT_COUNT], tasks: [Task<'d>; TASK_COUNT]) -> Self { |
| 32 | ch: impl Peripheral<P = C> + 'd, | ||
| 33 | events: [Event<'d>; EVENT_COUNT], | ||
| 34 | tasks: [Task<'d>; TASK_COUNT], | ||
| 35 | ) -> Self { | ||
| 36 | into_ref!(ch); | ||
| 37 | |||
| 38 | let val = DPPI_ENABLE_BIT | (ch.number() as u32 & DPPI_CHANNEL_MASK); | 30 | let val = DPPI_ENABLE_BIT | (ch.number() as u32 & DPPI_CHANNEL_MASK); |
| 39 | for task in tasks { | 31 | for task in tasks { |
| 40 | if unsafe { task.subscribe_reg().read_volatile() } != 0 { | 32 | if unsafe { task.subscribe_reg().read_volatile() } != 0 { |
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index 325e4ce00..531777205 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs | |||
| @@ -18,10 +18,10 @@ | |||
| 18 | use core::marker::PhantomData; | 18 | use core::marker::PhantomData; |
| 19 | use core::ptr::NonNull; | 19 | use core::ptr::NonNull; |
| 20 | 20 | ||
| 21 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 21 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; |
| 22 | 22 | ||
| 23 | use crate::pac::common::{Reg, RW, W}; | 23 | use crate::pac::common::{Reg, RW, W}; |
| 24 | use crate::{peripherals, Peripheral}; | 24 | use crate::peripherals; |
| 25 | 25 | ||
| 26 | #[cfg_attr(feature = "_dppi", path = "dppi.rs")] | 26 | #[cfg_attr(feature = "_dppi", path = "dppi.rs")] |
| 27 | #[cfg_attr(feature = "_ppi", path = "ppi.rs")] | 27 | #[cfg_attr(feature = "_ppi", path = "ppi.rs")] |
| @@ -30,7 +30,7 @@ pub(crate) use _version::*; | |||
| 30 | 30 | ||
| 31 | /// PPI channel driver. | 31 | /// PPI channel driver. |
| 32 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { | 32 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { |
| 33 | ch: PeripheralRef<'d, C>, | 33 | ch: Peri<'d, C>, |
| 34 | #[cfg(feature = "_dppi")] | 34 | #[cfg(feature = "_dppi")] |
| 35 | events: [Event<'d>; EVENT_COUNT], | 35 | events: [Event<'d>; EVENT_COUNT], |
| 36 | #[cfg(feature = "_dppi")] | 36 | #[cfg(feature = "_dppi")] |
| @@ -39,16 +39,14 @@ pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize | |||
| 39 | 39 | ||
| 40 | /// PPI channel group driver. | 40 | /// PPI channel group driver. |
| 41 | pub struct PpiGroup<'d, G: Group> { | 41 | pub struct PpiGroup<'d, G: Group> { |
| 42 | g: PeripheralRef<'d, G>, | 42 | g: Peri<'d, G>, |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | impl<'d, G: Group> PpiGroup<'d, G> { | 45 | impl<'d, G: Group> PpiGroup<'d, G> { |
| 46 | /// Create a new PPI group driver. | 46 | /// Create a new PPI group driver. |
| 47 | /// | 47 | /// |
| 48 | /// The group is initialized as containing no channels. | 48 | /// The group is initialized as containing no channels. |
| 49 | pub fn new(g: impl Peripheral<P = G> + 'd) -> Self { | 49 | pub fn new(g: Peri<'d, G>) -> Self { |
| 50 | into_ref!(g); | ||
| 51 | |||
| 52 | let r = regs(); | 50 | let r = regs(); |
| 53 | let n = g.number(); | 51 | let n = g.number(); |
| 54 | r.chg(n).write(|_| ()); | 52 | r.chg(n).write(|_| ()); |
| @@ -210,34 +208,22 @@ pub(crate) trait SealedGroup {} | |||
| 210 | 208 | ||
| 211 | /// Interface for PPI channels. | 209 | /// Interface for PPI channels. |
| 212 | #[allow(private_bounds)] | 210 | #[allow(private_bounds)] |
| 213 | pub trait Channel: SealedChannel + Peripheral<P = Self> + Sized + 'static { | 211 | pub trait Channel: SealedChannel + PeripheralType + Sized + 'static { |
| 214 | /// Returns the number of the channel | 212 | /// Returns the number of the channel |
| 215 | fn number(&self) -> usize; | 213 | fn number(&self) -> usize; |
| 216 | } | 214 | } |
| 217 | 215 | ||
| 218 | /// Interface for PPI channels that can be configured. | 216 | /// Interface for PPI channels that can be configured. |
| 219 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> { | 217 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> {} |
| 220 | /// Convert into a type erased configurable channel. | ||
| 221 | fn degrade(self) -> AnyConfigurableChannel; | ||
| 222 | } | ||
| 223 | 218 | ||
| 224 | /// Interface for PPI channels that cannot be configured. | 219 | /// Interface for PPI channels that cannot be configured. |
| 225 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> { | 220 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> {} |
| 226 | /// Convert into a type erased static channel. | ||
| 227 | fn degrade(self) -> AnyStaticChannel; | ||
| 228 | } | ||
| 229 | 221 | ||
| 230 | /// Interface for a group of PPI channels. | 222 | /// Interface for a group of PPI channels. |
| 231 | #[allow(private_bounds)] | 223 | #[allow(private_bounds)] |
| 232 | pub trait Group: SealedGroup + Peripheral<P = Self> + Into<AnyGroup> + Sized + 'static { | 224 | pub trait Group: SealedGroup + PeripheralType + Into<AnyGroup> + Sized + 'static { |
| 233 | /// Returns the number of the group. | 225 | /// Returns the number of the group. |
| 234 | fn number(&self) -> usize; | 226 | fn number(&self) -> usize; |
| 235 | /// Convert into a type erased group. | ||
| 236 | fn degrade(self) -> AnyGroup { | ||
| 237 | AnyGroup { | ||
| 238 | number: self.number() as u8, | ||
| 239 | } | ||
| 240 | } | ||
| 241 | } | 227 | } |
| 242 | 228 | ||
| 243 | // ====================== | 229 | // ====================== |
| @@ -255,11 +241,7 @@ impl Channel for AnyStaticChannel { | |||
| 255 | self.number as usize | 241 | self.number as usize |
| 256 | } | 242 | } |
| 257 | } | 243 | } |
| 258 | impl StaticChannel for AnyStaticChannel { | 244 | impl StaticChannel for AnyStaticChannel {} |
| 259 | fn degrade(self) -> AnyStaticChannel { | ||
| 260 | self | ||
| 261 | } | ||
| 262 | } | ||
| 263 | 245 | ||
| 264 | /// The any configurable channel can represent any configurable channel at runtime. | 246 | /// The any configurable channel can represent any configurable channel at runtime. |
| 265 | /// This can be used to have fewer generic parameters in some places. | 247 | /// This can be used to have fewer generic parameters in some places. |
| @@ -273,11 +255,7 @@ impl Channel for AnyConfigurableChannel { | |||
| 273 | self.number as usize | 255 | self.number as usize |
| 274 | } | 256 | } |
| 275 | } | 257 | } |
| 276 | impl ConfigurableChannel for AnyConfigurableChannel { | 258 | impl ConfigurableChannel for AnyConfigurableChannel {} |
| 277 | fn degrade(self) -> AnyConfigurableChannel { | ||
| 278 | self | ||
| 279 | } | ||
| 280 | } | ||
| 281 | 259 | ||
| 282 | #[cfg(not(feature = "_nrf51"))] | 260 | #[cfg(not(feature = "_nrf51"))] |
| 283 | macro_rules! impl_ppi_channel { | 261 | macro_rules! impl_ppi_channel { |
| @@ -291,35 +269,23 @@ macro_rules! impl_ppi_channel { | |||
| 291 | }; | 269 | }; |
| 292 | ($type:ident, $number:expr => static) => { | 270 | ($type:ident, $number:expr => static) => { |
| 293 | impl_ppi_channel!($type, $number); | 271 | impl_ppi_channel!($type, $number); |
| 294 | impl crate::ppi::StaticChannel for peripherals::$type { | 272 | impl crate::ppi::StaticChannel for peripherals::$type {} |
| 295 | fn degrade(self) -> crate::ppi::AnyStaticChannel { | ||
| 296 | use crate::ppi::Channel; | ||
| 297 | crate::ppi::AnyStaticChannel { | ||
| 298 | number: self.number() as u8, | ||
| 299 | } | ||
| 300 | } | ||
| 301 | } | ||
| 302 | |||
| 303 | impl From<peripherals::$type> for crate::ppi::AnyStaticChannel { | 273 | impl From<peripherals::$type> for crate::ppi::AnyStaticChannel { |
| 304 | fn from(val: peripherals::$type) -> Self { | 274 | fn from(val: peripherals::$type) -> Self { |
| 305 | crate::ppi::StaticChannel::degrade(val) | 275 | Self { |
| 276 | number: crate::ppi::Channel::number(&val) as u8, | ||
| 277 | } | ||
| 306 | } | 278 | } |
| 307 | } | 279 | } |
| 308 | }; | 280 | }; |
| 309 | ($type:ident, $number:expr => configurable) => { | 281 | ($type:ident, $number:expr => configurable) => { |
| 310 | impl_ppi_channel!($type, $number); | 282 | impl_ppi_channel!($type, $number); |
| 311 | impl crate::ppi::ConfigurableChannel for peripherals::$type { | 283 | impl crate::ppi::ConfigurableChannel for peripherals::$type {} |
| 312 | fn degrade(self) -> crate::ppi::AnyConfigurableChannel { | ||
| 313 | use crate::ppi::Channel; | ||
| 314 | crate::ppi::AnyConfigurableChannel { | ||
| 315 | number: self.number() as u8, | ||
| 316 | } | ||
| 317 | } | ||
| 318 | } | ||
| 319 | |||
| 320 | impl From<peripherals::$type> for crate::ppi::AnyConfigurableChannel { | 284 | impl From<peripherals::$type> for crate::ppi::AnyConfigurableChannel { |
| 321 | fn from(val: peripherals::$type) -> Self { | 285 | fn from(val: peripherals::$type) -> Self { |
| 322 | crate::ppi::ConfigurableChannel::degrade(val) | 286 | Self { |
| 287 | number: crate::ppi::Channel::number(&val) as u8, | ||
| 288 | } | ||
| 323 | } | 289 | } |
| 324 | } | 290 | } |
| 325 | }; | 291 | }; |
| @@ -351,7 +317,9 @@ macro_rules! impl_group { | |||
| 351 | 317 | ||
| 352 | impl From<peripherals::$type> for crate::ppi::AnyGroup { | 318 | impl From<peripherals::$type> for crate::ppi::AnyGroup { |
| 353 | fn from(val: peripherals::$type) -> Self { | 319 | fn from(val: peripherals::$type) -> Self { |
| 354 | crate::ppi::Group::degrade(val) | 320 | Self { |
| 321 | number: crate::ppi::Group::number(&val) as u8, | ||
| 322 | } | ||
| 355 | } | 323 | } |
| 356 | } | 324 | } |
| 357 | }; | 325 | }; |
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index a1beb9dcd..e04dacbc0 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | use embassy_hal_internal::into_ref; | ||
| 2 | |||
| 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; | 1 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; |
| 4 | use crate::{pac, Peripheral}; | 2 | use crate::{pac, Peri}; |
| 5 | 3 | ||
| 6 | impl<'d> Task<'d> { | 4 | impl<'d> Task<'d> { |
| 7 | fn reg_val(&self) -> u32 { | 5 | fn reg_val(&self) -> u32 { |
| @@ -21,9 +19,7 @@ pub(crate) fn regs() -> pac::ppi::Ppi { | |||
| 21 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task | 19 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task |
| 22 | impl<'d, C: super::StaticChannel> Ppi<'d, C, 0, 1> { | 20 | impl<'d, C: super::StaticChannel> Ppi<'d, C, 0, 1> { |
| 23 | /// Configure PPI channel to trigger `task`. | 21 | /// Configure PPI channel to trigger `task`. |
| 24 | pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self { | 22 | pub fn new_zero_to_one(ch: Peri<'d, C>, task: Task) -> Self { |
| 25 | into_ref!(ch); | ||
| 26 | |||
| 27 | let r = regs(); | 23 | let r = regs(); |
| 28 | let n = ch.number(); | 24 | let n = ch.number(); |
| 29 | r.fork(n).tep().write_value(task.reg_val()); | 25 | r.fork(n).tep().write_value(task.reg_val()); |
| @@ -34,9 +30,7 @@ impl<'d, C: super::StaticChannel> Ppi<'d, C, 0, 1> { | |||
| 34 | 30 | ||
| 35 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 31 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { |
| 36 | /// Configure PPI channel to trigger `task` on `event`. | 32 | /// Configure PPI channel to trigger `task` on `event`. |
| 37 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task: Task<'d>) -> Self { | 33 | pub fn new_one_to_one(ch: Peri<'d, C>, event: Event<'d>, task: Task<'d>) -> Self { |
| 38 | into_ref!(ch); | ||
| 39 | |||
| 40 | let r = regs(); | 34 | let r = regs(); |
| 41 | let n = ch.number(); | 35 | let n = ch.number(); |
| 42 | r.ch(n).eep().write_value(event.reg_val()); | 36 | r.ch(n).eep().write_value(event.reg_val()); |
| @@ -49,9 +43,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | |||
| 49 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task | 43 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task |
| 50 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 44 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 51 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. | 45 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. |
| 52 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { | 46 | pub fn new_one_to_two(ch: Peri<'d, C>, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { |
| 53 | into_ref!(ch); | ||
| 54 | |||
| 55 | let r = regs(); | 47 | let r = regs(); |
| 56 | let n = ch.number(); | 48 | let n = ch.number(); |
| 57 | r.ch(n).eep().write_value(event.reg_val()); | 49 | r.ch(n).eep().write_value(event.reg_val()); |
