Skip to content

Commit

Permalink
The PwmPeripheral trait is no longer unsafe, and is instead now s…
Browse files Browse the repository at this point in the history
…ealed
  • Loading branch information
jessebraham committed Feb 2, 2024
1 parent 154a136 commit a07be02
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions esp-hal/src/mcpwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,7 @@ impl<'a> PeripheralClockConfig<'a> {
pub struct FrequencyError;

/// A MCPWM peripheral
///
/// # Safety
///
/// ???
pub unsafe trait PwmPeripheral: Deref<Target = RegisterBlock> {
pub trait PwmPeripheral: Deref<Target = RegisterBlock> + private::Sealed {
/// Enable peripheral
fn enable();
/// Get a pointer to the peripheral RegisterBlock
Expand All @@ -296,7 +292,7 @@ pub unsafe trait PwmPeripheral: Deref<Target = RegisterBlock> {
}

#[cfg(mcpwm0)]
unsafe impl PwmPeripheral for crate::peripherals::MCPWM0 {
impl PwmPeripheral for crate::peripherals::MCPWM0 {
fn enable() {
PeripheralClockControl::enable(PeripheralEnable::Mcpwm0)
}
Expand All @@ -319,7 +315,7 @@ unsafe impl PwmPeripheral for crate::peripherals::MCPWM0 {
}

#[cfg(mcpwm1)]
unsafe impl PwmPeripheral for crate::peripherals::MCPWM1 {
impl PwmPeripheral for crate::peripherals::MCPWM1 {
fn enable() {
PeripheralClockControl::enable(PeripheralEnable::Mcpwm1)
}
Expand All @@ -340,3 +336,13 @@ unsafe impl PwmPeripheral for crate::peripherals::MCPWM1 {
}
}
}

mod private {
pub trait Sealed {}
}

#[cfg(mcpwm0)]
impl private::Sealed for crate::peripherals::MCPWM0 {}

#[cfg(mcpwm1)]
impl private::Sealed for crate::peripherals::MCPWM1 {}

0 comments on commit a07be02

Please sign in to comment.