Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeripheralRef: RMT #310

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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