Skip to content

Commit a9661e6

Browse files
Peripheral ref/rng (#306) (#307)
* Add RNG to list of peripherals to be created * Refactor RNG driver to use PeripheralRef Co-authored-by: Jesse Braham <[email protected]>
1 parent f2b5953 commit a9661e6

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

esp-hal-common/src/ledc/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ use self::{
7171
use crate::{
7272
clock::Clocks,
7373
gpio::OutputPin,
74-
system::{Peripheral, PeripheralClockControl},
74+
peripheral::{Peripheral, PeripheralRef},
75+
system::{Peripheral as PeripheralEnable, PeripheralClockControl},
7576
};
7677

7778
pub mod channel;
@@ -84,10 +85,10 @@ pub enum LSGlobalClkSource {
8485
}
8586

8687
/// LEDC (LED PWM Controller)
87-
pub struct LEDC<'a> {
88-
_instance: crate::pac::LEDC,
89-
ledc: &'a crate::pac::ledc::RegisterBlock,
90-
clock_control_config: &'a Clocks,
88+
pub struct LEDC<'d> {
89+
_instance: PeripheralRef<'d, crate::peripherals::LEDC>,
90+
ledc: &'d crate::pac::ledc::RegisterBlock,
91+
clock_control_config: &'d Clocks,
9192
}
9293

9394
#[cfg(esp32)]
@@ -104,14 +105,15 @@ impl Speed for HighSpeed {}
104105

105106
impl Speed for LowSpeed {}
106107

107-
impl<'a> LEDC<'a> {
108+
impl<'d> LEDC<'d> {
108109
/// Return a new LEDC
109110
pub fn new(
110-
_instance: crate::pac::LEDC,
111-
clock_control_config: &'a Clocks,
111+
_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd,
112+
clock_control_config: &'d Clocks,
112113
system: &mut PeripheralClockControl,
113114
) -> Self {
114-
system.enable(Peripheral::Ledc);
115+
crate::into_ref!(_instance);
116+
system.enable(PeripheralEnable::Ledc);
115117

116118
let ledc = unsafe { &*crate::pac::LEDC::ptr() };
117119
LEDC {

esp-hal-common/src/peripherals/esp32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ mod peripherals {
6363
UART1,
6464
UART2,
6565
DPORT,
66+
LEDC,
6667
}
6768
}

esp-hal-common/src/peripherals/esp32c2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ mod peripherals {
4343
UART0,
4444
UART1,
4545
SYSTEM,
46+
LEDC,
4647
}
4748
}

esp-hal-common/src/peripherals/esp32c3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ mod peripherals {
5555
UART1,
5656
USB_DEVICE,
5757
SYSTEM,
58+
LEDC,
5859
}
5960
}

esp-hal-common/src/peripherals/esp32s2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ mod peripherals {
6262
UART0,
6363
UART1,
6464
SYSTEM,
65+
LEDC,
6566
}
6667
}

esp-hal-common/src/peripherals/esp32s3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ mod peripherals {
7474
UART2,
7575
USB_DEVICE,
7676
SYSTEM,
77+
LEDC,
7778
}
7879
}

0 commit comments

Comments
 (0)