Skip to content

Commit

Permalink
PeripheralRef: RMT
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajSadel committed Dec 14, 2022
1 parent 54e8eaf commit 3fed087
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
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 @@ -64,5 +64,6 @@ mod peripherals {
UART2,
DPORT,
LEDC,
RMT,
}
}
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 @@ -56,5 +56,6 @@ mod peripherals {
USB_DEVICE,
SYSTEM,
LEDC,
RMT,
}
}
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 @@ -63,5 +63,6 @@ mod peripherals {
UART1,
SYSTEM,
LEDC,
RMT,
}
}
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 @@ -75,5 +75,6 @@ mod peripherals {
USB_DEVICE,
SYSTEM,
LEDC,
RMT,
}
}
20 changes: 9 additions & 11 deletions esp-hal-common/src/pulse_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ pub use paste::paste;

use crate::{
gpio::{types::OutputSignal, OutputPin},
pac::RMT,
peripheral::{Peripheral, PeripheralRef},
peripherals::RMT,
system::PeripheralClockControl,
};

Expand Down Expand Up @@ -822,27 +823,28 @@ macro_rules! rmt {
)
=> {
/// RMT peripheral (RMT)
pub struct PulseControl {
pub struct PulseControl<'d> {
/// The underlying register block
reg: RMT,
reg: PeripheralRef<'d, RMT>,
$(
/// RMT channel $cxi
pub $obj_name: $cxi,
)+
}

impl PulseControl {
impl<'d> PulseControl<'d> {
/// Create a new pulse controller instance
#[cfg(any(esp32c3, esp32s3))]
pub fn new(
instance: RMT,
instance: impl Peripheral<P = RMT> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
clk_source: ClockSource,
div_abs: u8,
div_frac_a: u8,
div_frac_b: u8,
) -> Result<Self, SetupError> {

crate::into_ref!(instance);
let pc = PulseControl {
reg: instance,
$(
Expand All @@ -859,10 +861,11 @@ macro_rules! rmt {
/// Create a new pulse controller instance
#[cfg(any(esp32, esp32s2))]
pub fn new(
instance: RMT,
instance: impl Peripheral<P = RMT> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Result<Self, SetupError> {

crate::into_ref!(instance);
let pc = PulseControl {
reg: instance,
$(
Expand All @@ -876,11 +879,6 @@ macro_rules! rmt {
Ok(pc)
}

/// Return the raw interface to the underlying RMT peripheral
pub fn free(self) -> RMT {
self.reg
}

// Enable the RMT peripherals clock in the system peripheral
fn enable_peripheral(&self, peripheral_clock_control: &mut PeripheralClockControl) {
peripheral_clock_control.enable(crate::system::Peripheral::Rmt);
Expand Down

0 comments on commit 3fed087

Please sign in to comment.