diff --git a/esp-hal/src/dma/gdma.rs b/esp-hal/src/dma/gdma.rs index 581a8f9564f..c53a5f5a9ee 100644 --- a/esp-hal/src/dma/gdma.rs +++ b/esp-hal/src/dma/gdma.rs @@ -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()); diff --git a/esp-hal/src/dma/pdma.rs b/esp-hal/src/dma/pdma.rs index 0023f007b98..738e486d945 100644 --- a/esp-hal/src/dma/pdma.rs +++ b/esp-hal/src/dma/pdma.rs @@ -942,7 +942,7 @@ impl<'d> Dma<'d> { pub fn new( dma: impl crate::peripheral::Peripheral
+ 'd, ) -> Dma<'d> { - if PeripheralClockControl::enable(Peripheral::Dma, true) { + if PeripheralClockControl::enable(Peripheral::Dma) { PeripheralClockControl::reset(Peripheral::Dma); } diff --git a/esp-hal/src/i2c/master/mod.rs b/esp-hal/src/i2c/master/mod.rs index dff8d9f1832..bfb102af5d7 100644 --- a/esp-hal/src/i2c/master/mod.rs +++ b/esp-hal/src/i2c/master/mod.rs @@ -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. diff --git a/esp-hal/src/ledc/mod.rs b/esp-hal/src/ledc/mod.rs index 83e90a6e11b..1c4b5c58c3d 100644 --- a/esp-hal/src/ledc/mod.rs +++ b/esp-hal/src/ledc/mod.rs @@ -111,7 +111,7 @@ impl<'d> Ledc<'d> { pub fn new(_instance: impl Peripheral
+ 'd) -> Self {
crate::into_ref!(_instance);
- if PeripheralClockControl::enable(PeripheralEnable::Ledc, true) {
+ if PeripheralClockControl::enable(PeripheralEnable::Ledc) {
PeripheralClockControl::reset(PeripheralEnable::Ledc);
}
diff --git a/esp-hal/src/system.rs b/esp-hal/src/system.rs
index 1c677df4dcf..40f0a69b31b 100755
--- a/esp-hal/src/system.rs
+++ b/esp-hal/src/system.rs
@@ -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);
}
@@ -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);
}
}
}
@@ -189,7 +189,7 @@ pub(crate) struct GenericPeripheralGuard {
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);
}
@@ -201,7 +201,7 @@ impl {
fn drop(&mut self) {
let peripheral = unwrap!(Peripheral::try_from(P));
if !KEEP_ENABLED.contains(&peripheral) {
- PeripheralClockControl::enable(peripheral, false);
+ PeripheralClockControl::disable(peripheral);
}
}
}
@@ -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 {
diff --git a/esp-hal/src/timer/systimer.rs b/esp-hal/src/timer/systimer.rs
index f54aeb44eab..d640502041e 100644
--- a/esp-hal/src/timer/systimer.rs
+++ b/esp-hal/src/timer/systimer.rs
@@ -148,7 +148,7 @@ impl<'d> SystemTimer<'d> {
/// Create a new instance.
pub fn new(_systimer: impl Peripheral + '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();
diff --git a/esp-hal/src/timer/timg.rs b/esp-hal/src/timer/timg.rs
index 77924fb87bb..bcbfc619391 100644
--- a/esp-hal/src/timer/timg.rs
+++ b/esp-hal/src/timer/timg.rs
@@ -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() {
@@ -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() {
diff --git a/esp-hal/src/usb_serial_jtag.rs b/esp-hal/src/usb_serial_jtag.rs
index c76d714a828..c94c2be6c93 100644
--- a/esp-hal/src/usb_serial_jtag.rs
+++ b/esp-hal/src/usb_serial_jtag.rs
@@ -314,7 +314,7 @@ where
fn new_inner(usb_device: impl Peripheral + '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();