Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ committed Nov 20, 2024
1 parent beddf0c commit 2cd70ec
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ impl<'d> Dma<'d> {
) -> Dma<'d> {
crate::into_ref!(dma);

if PeripheralClockControl::enable(Peripheral::Gdma, true) {
if PeripheralClockControl::enable(Peripheral::Gdma) {
PeripheralClockControl::reset(Peripheral::Gdma);
}
dma.misc_conf().modify(|_, w| w.ahbm_rst_inter().set_bit());
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ impl<'d> Dma<'d> {
pub fn new(
dma: impl crate::peripheral::Peripheral<P = crate::peripherals::DMA> + 'd,
) -> Dma<'d> {
if PeripheralClockControl::enable(Peripheral::Dma, true) {
if PeripheralClockControl::enable(Peripheral::Dma) {
PeripheralClockControl::reset(Peripheral::Dma);
}

Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ where
}

fn internal_recover(&self) {
PeripheralClockControl::enable(self.driver().info.peripheral, false);
PeripheralClockControl::enable(self.driver().info.peripheral, true);
PeripheralClockControl::disable(self.driver().info.peripheral);
PeripheralClockControl::enable(self.driver().info.peripheral);
PeripheralClockControl::reset(self.driver().info.peripheral);

// We know the configuration is valid, we can ignore the result.
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/ledc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'d> Ledc<'d> {
pub fn new(_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd) -> Self {
crate::into_ref!(_instance);

if PeripheralClockControl::enable(PeripheralEnable::Ledc, true) {
if PeripheralClockControl::enable(PeripheralEnable::Ledc) {
PeripheralClockControl::reset(PeripheralEnable::Ledc);
}

Expand Down
29 changes: 19 additions & 10 deletions esp-hal/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) struct PeripheralGuard {

impl PeripheralGuard {
pub(crate) fn new(p: Peripheral) -> Self {
if !KEEP_ENABLED.contains(&p) && PeripheralClockControl::enable(p, true) {
if !KEEP_ENABLED.contains(&p) && PeripheralClockControl::enable(p) {
PeripheralClockControl::reset(p);
}

Expand All @@ -178,7 +178,7 @@ impl PeripheralGuard {
impl Drop for PeripheralGuard {
fn drop(&mut self) {
if !KEEP_ENABLED.contains(&self.peripheral) {
PeripheralClockControl::enable(self.peripheral, false);
PeripheralClockControl::disable(self.peripheral);
}
}
}
Expand All @@ -189,7 +189,7 @@ pub(crate) struct GenericPeripheralGuard<const P: u8> {}
impl<const P: u8> GenericPeripheralGuard<P> {
pub(crate) fn new() -> Self {
let peripheral = unwrap!(Peripheral::try_from(P));
if !KEEP_ENABLED.contains(&peripheral) && PeripheralClockControl::enable(peripheral, true) {
if !KEEP_ENABLED.contains(&peripheral) && PeripheralClockControl::enable(peripheral) {
PeripheralClockControl::reset(peripheral);
}

Expand All @@ -201,7 +201,7 @@ impl<const P: u8> Drop for GenericPeripheralGuard<P> {
fn drop(&mut self) {
let peripheral = unwrap!(Peripheral::try_from(P));
if !KEEP_ENABLED.contains(&peripheral) {
PeripheralClockControl::enable(peripheral, false);
PeripheralClockControl::disable(peripheral);
}
}
}
Expand Down Expand Up @@ -961,17 +961,26 @@ impl PeripheralClockControl {
}

impl PeripheralClockControl {
/// Enables/disables the given peripheral.
/// Enables the given peripheral.
///
/// This keeps track of enabling/disabling a peripheral - i.e. a peripheral
/// is only enabled with the first call attempt to enable it. It only
/// This keeps track of enabling a peripheral - i.e. a peripheral
/// is only enabled with the first call attempt to enable it.
///
/// Returns `true` if it actually enabled the peripheral.
pub(crate) fn enable(peripheral: Peripheral) -> bool {
Self::enable_forced(peripheral, true, false)
}

/// Disables the given peripheral.
///
/// This keeps track of disabling a peripheral - i.e. it only
/// gets disabled when the number of enable/disable attempts is balanced.
///
/// Returns `true` if it actually enabled/disabled the peripheral.
/// Returns `true` if it actually disabled the peripheral.
///
/// Before disabling a peripheral it will also get reset
pub(crate) fn enable(peripheral: Peripheral, enable: bool) -> bool {
Self::enable_forced(peripheral, enable, false)
pub(crate) fn disable(peripheral: Peripheral) -> bool {
Self::enable_forced(peripheral, false, false)
}

pub(crate) fn enable_forced(peripheral: Peripheral, enable: bool, force: bool) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/timer/systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<'d> SystemTimer<'d> {
/// Create a new instance.
pub fn new(_systimer: impl Peripheral<P = SYSTIMER> + 'd) -> Self {
// Don't reset Systimer as it will break `time::now`, only enable it
PeripheralClockControl::enable(PeripheralEnable::Systimer, true);
PeripheralClockControl::enable(PeripheralEnable::Systimer);

#[cfg(soc_etm)]
etm::enable_etm();
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/timer/timg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl TimerGroupInstance for TIMG0 {
}

fn enable_peripheral() {
PeripheralClockControl::enable(crate::system::Peripheral::Timg0, true);
PeripheralClockControl::enable(crate::system::Peripheral::Timg0);
}

fn reset_peripheral() {
Expand Down Expand Up @@ -215,7 +215,7 @@ impl TimerGroupInstance for crate::peripherals::TIMG1 {
}

fn enable_peripheral() {
PeripheralClockControl::enable(crate::system::Peripheral::Timg1, true);
PeripheralClockControl::enable(crate::system::Peripheral::Timg1);
}

fn reset_peripheral() {
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/usb_serial_jtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ where
fn new_inner(usb_device: impl Peripheral<P = USB_DEVICE> + 'd) -> Self {
// Do NOT reset the peripheral. Doing so will result in a broken USB JTAG
// connection.
PeripheralClockControl::enable(crate::system::Peripheral::UsbDevice, true);
PeripheralClockControl::enable(crate::system::Peripheral::UsbDevice);

USB_DEVICE::disable_tx_interrupts();
USB_DEVICE::disable_rx_interrupts();
Expand Down

0 comments on commit 2cd70ec

Please sign in to comment.