Skip to content

Commit

Permalink
Peripheral ref/rng (#306) (#307)
Browse files Browse the repository at this point in the history
* Add RNG to list of peripherals to be created

* Refactor RNG driver to use PeripheralRef

Co-authored-by: Jesse Braham <jessebraham@users.noreply.github.com>
  • Loading branch information
MabezDev and jessebraham authored Dec 14, 2022
1 parent f2b5953 commit a9661e6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
20 changes: 11 additions & 9 deletions esp-hal-common/src/ledc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand All @@ -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<P = crate::peripherals::LEDC> + '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 {
Expand Down
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ mod peripherals {
UART1,
UART2,
DPORT,
LEDC,
}
}
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ mod peripherals {
UART0,
UART1,
SYSTEM,
LEDC,
}
}
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ mod peripherals {
UART1,
USB_DEVICE,
SYSTEM,
LEDC,
}
}
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ mod peripherals {
UART0,
UART1,
SYSTEM,
LEDC,
}
}
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ mod peripherals {
UART2,
USB_DEVICE,
SYSTEM,
LEDC,
}
}

0 comments on commit a9661e6

Please sign in to comment.