diff --git a/esp-hal-common/src/ledc/mod.rs b/esp-hal-common/src/ledc/mod.rs index bcdacbd858a..0e04b36cffe 100644 --- a/esp-hal-common/src/ledc/mod.rs +++ b/esp-hal-common/src/ledc/mod.rs @@ -71,7 +71,8 @@ use self::{ use crate::{ clock::Clocks, gpio::OutputPin, - system::{Peripheral, PeripheralClockControl}, + peripheral::{Peripheral, PeripheralRef}, + system::{Peripheral as PeripheralEnable, PeripheralClockControl}, }; pub mod channel; @@ -84,10 +85,10 @@ pub enum LSGlobalClkSource { } /// LEDC (LED PWM Controller) -pub struct LEDC<'a> { - _instance: crate::pac::LEDC, - ledc: &'a crate::pac::ledc::RegisterBlock, - clock_control_config: &'a Clocks, +pub struct LEDC<'d> { + _instance: PeripheralRef<'d, crate::peripherals::LEDC>, + ledc: &'d crate::pac::ledc::RegisterBlock, + clock_control_config: &'d Clocks, } #[cfg(esp32)] @@ -104,14 +105,15 @@ impl Speed for HighSpeed {} impl Speed for LowSpeed {} -impl<'a> LEDC<'a> { +impl<'d> LEDC<'d> { /// Return a new LEDC pub fn new( - _instance: crate::pac::LEDC, - clock_control_config: &'a Clocks, + _instance: impl Peripheral

+ 'd, + clock_control_config: &'d Clocks, system: &mut PeripheralClockControl, ) -> Self { - system.enable(Peripheral::Ledc); + crate::into_ref!(_instance); + system.enable(PeripheralEnable::Ledc); let ledc = unsafe { &*crate::pac::LEDC::ptr() }; LEDC { diff --git a/esp-hal-common/src/peripherals/esp32.rs b/esp-hal-common/src/peripherals/esp32.rs index b2799e750ef..80eecb42a50 100644 --- a/esp-hal-common/src/peripherals/esp32.rs +++ b/esp-hal-common/src/peripherals/esp32.rs @@ -63,5 +63,6 @@ mod peripherals { UART1, UART2, DPORT, + LEDC, } } diff --git a/esp-hal-common/src/peripherals/esp32c2.rs b/esp-hal-common/src/peripherals/esp32c2.rs index 94e0737c36b..3d833a462db 100644 --- a/esp-hal-common/src/peripherals/esp32c2.rs +++ b/esp-hal-common/src/peripherals/esp32c2.rs @@ -43,5 +43,6 @@ mod peripherals { UART0, UART1, SYSTEM, + LEDC, } } diff --git a/esp-hal-common/src/peripherals/esp32c3.rs b/esp-hal-common/src/peripherals/esp32c3.rs index dda1177c07b..7e904dee5e2 100644 --- a/esp-hal-common/src/peripherals/esp32c3.rs +++ b/esp-hal-common/src/peripherals/esp32c3.rs @@ -55,5 +55,6 @@ mod peripherals { UART1, USB_DEVICE, SYSTEM, + LEDC, } } diff --git a/esp-hal-common/src/peripherals/esp32s2.rs b/esp-hal-common/src/peripherals/esp32s2.rs index e39317f61a4..e7355b962b3 100644 --- a/esp-hal-common/src/peripherals/esp32s2.rs +++ b/esp-hal-common/src/peripherals/esp32s2.rs @@ -62,5 +62,6 @@ mod peripherals { UART0, UART1, SYSTEM, + LEDC, } } diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs index 9f5e10b86be..354bf27e739 100644 --- a/esp-hal-common/src/peripherals/esp32s3.rs +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -74,5 +74,6 @@ mod peripherals { UART2, USB_DEVICE, SYSTEM, + LEDC, } }