Skip to content

Commit

Permalink
Merge pull request #259 from jonas-schievink/sealant
Browse files Browse the repository at this point in the history
Seal public PPI traits
  • Loading branch information
jonas-schievink authored Oct 26, 2020
2 parents a47e883 + c160e1a commit 56cbdac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Seal the `timer::Instance` trait ([#214]).
- Make GPIOs start in a `Disconnected` state instead of `Input<Floating>` ([#220] [#245]).
- 🦭 all `Instance` traits ([#255]).
- 🦭 PPI traits ([#259]).
- Various TWIM fixes and improvements - removes automatic transfer splitting ([#242]).
- Remove typestate from RTC to make it easier to use ([#252]).

Expand Down Expand Up @@ -79,6 +80,7 @@
[#250]: https://github.com/nrf-rs/nrf-hal/pull/250
[#252]: https://github.com/nrf-rs/nrf-hal/pull/252
[#255]: https://github.com/nrf-rs/nrf-hal/pull/255
[#259]: https://github.com/nrf-rs/nrf-hal/pull/259
[`cargo-xtask`]: https://github.com/matklad/cargo-xtask

## [0.11.1]
Expand Down
11 changes: 8 additions & 3 deletions nrf-hal-common/src/ppi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ mod sealed {
pub trait ChannelGroup {
const CHG: usize;
}

pub trait PpiSealed {}
pub trait PpiChannelGroupSealed {}
}
use sealed::{Channel, ChannelGroup, Event, NotFixed, Task};
use sealed::{Channel, ChannelGroup, Event, NotFixed, PpiChannelGroupSealed, PpiSealed, Task};

pub struct TaskAddr(pub(crate) u32);
pub struct EventAddr(pub(crate) u32);

/// Trait to represent a Programmable Peripheral Interconnect channel.
pub trait Ppi {
pub trait Ppi: PpiSealed {
/// Enables the channel.
fn enable(&mut self);

Expand All @@ -93,7 +96,7 @@ pub trait ConfigurablePpi: Ppi {
}

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

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

impl<G: ChannelGroup> PpiChannelGroupSealed for G {}
impl<G: ChannelGroup> PpiChannelGroup for G {
#[inline(always)]
fn task_enable(&self) -> &Reg<u32, _EN> {
Expand Down

0 comments on commit 56cbdac

Please sign in to comment.