Skip to content

Commit 2f4efa6

Browse files
author
Jonas Schievink
committed
Seal public PPI traits
1 parent a47e883 commit 2f4efa6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

nrf-hal-common/src/ppi/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ mod sealed {
6161
pub trait ChannelGroup {
6262
const CHG: usize;
6363
}
64+
65+
pub trait PpiSealed {}
66+
pub trait PpiChannelGroupSealed {}
6467
}
65-
use sealed::{Channel, ChannelGroup, Event, NotFixed, Task};
68+
use sealed::{Channel, ChannelGroup, Event, NotFixed, PpiChannelGroupSealed, PpiSealed, Task};
6669

6770
pub struct TaskAddr(pub(crate) u32);
6871
pub struct EventAddr(pub(crate) u32);
6972

7073
/// Trait to represent a Programmable Peripheral Interconnect channel.
71-
pub trait Ppi {
74+
pub trait Ppi: PpiSealed {
7275
/// Enables the channel.
7376
fn enable(&mut self);
7477

@@ -93,7 +96,7 @@ pub trait ConfigurablePpi: Ppi {
9396
}
9497

9598
/// Trait for a PPI channel group.
96-
pub trait PpiChannelGroup {
99+
pub trait PpiChannelGroup: PpiChannelGroupSealed {
97100
/// Returns reference to `tasks_chg[x].en` endpoint for enabling channel group.
98101
fn task_enable(&self) -> &Reg<u32, _EN>;
99102
/// Returns reference to `tasks_chg[x].dis` endpoint for disabling channel group.
@@ -108,6 +111,7 @@ pub trait PpiChannelGroup {
108111

109112
// All unsafe `ptr` calls only uses registers atomically, and only changes the resources owned by
110113
// the type (guaranteed by the abstraction).
114+
impl<P: Channel> PpiSealed for P {}
111115
impl<P: Channel> Ppi for P {
112116
#[inline(always)]
113117
fn enable(&mut self) {
@@ -151,6 +155,7 @@ impl<P: Channel + NotFixed> ConfigurablePpi for P {
151155
}
152156
}
153157

158+
impl<G: ChannelGroup> PpiChannelGroupSealed for G {}
154159
impl<G: ChannelGroup> PpiChannelGroup for G {
155160
#[inline(always)]
156161
fn task_enable(&self) -> &Reg<u32, _EN> {

0 commit comments

Comments
 (0)