Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Nov 25, 2024
1 parent 1fee2c3 commit 890a718
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 40 deletions.
1 change: 0 additions & 1 deletion esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The timer drivers `OneShotTimer` & `PeriodicTimer` now have a `Mode` parameter and type erase the underlying driver by default (#2586)
- `timer::Timer` has new trait requirements of `Into<AnyTimer>`, `'static` and `InterruptConfigurable` (#2586)
- `systimer::etm::Event` no longer borrows the alarm indefinitely (#2586)
- `DEFAULT_INTERRUPT_HANDLER` and `InterruptConfigurable` have moved from the the crate root to `interrupt` (#2586)

### Fixed

Expand Down
9 changes: 0 additions & 9 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,4 @@ is enabled. To retrieve the address and size of the initialized external memory,
+ config
+});
+let (start, size) = esp_hal::psram::psram_raw_parts(&peripherals.PSRAM, psram);
```

## Interrupt related reshuffle

```diff
- use esp_hal::InterruptConfigurable;
+ use esp_hal::interrupt::InterruptConfigurable;
- use esp_hal::DEFAULT_INTERRUPT_HANDLER;
+ use esp_hal::interrupt::DEFAULT_INTERRUPT_HANDLER;
```
2 changes: 1 addition & 1 deletion esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//!
//! The [`Io`] struct can also be used to configure the interrupt handler for
//! GPIO interrupts. For more information, see the
//! [`InterruptConfigurable::set_interrupt_handler`](interrupt::InterruptConfigurable::set_interrupt_handler).
//! [`InterruptConfigurable::set_interrupt_handler`](InterruptConfigurable::set_interrupt_handler).
//!
//! ## GPIO interconnect
//!
Expand Down
26 changes: 16 additions & 10 deletions esp-hal/src/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub enum Error {
}

/// Functionality provided by any timer peripheral.
pub trait Timer: Into<AnyTimer> + 'static + crate::private::Sealed {
pub trait Timer: Into<AnyTimer> + InterruptConfigurable + 'static + crate::private::Sealed {
/// Start the timer.
fn start(&self);

Expand Down Expand Up @@ -103,11 +103,6 @@ pub trait Timer: Into<AnyTimer> + 'static + crate::private::Sealed {
/// Clear the timer's interrupt.
fn clear_interrupt(&self);

/// Set the interrupt handler
///
/// Note that this will replace any previously set interrupt handler
fn set_interrupt_handler(&self, handler: InterruptHandler);

/// Has the timer triggered?
fn is_interrupt_set(&self) -> bool;

Expand Down Expand Up @@ -151,9 +146,9 @@ where
}

/// Converts the driver to [`Async`] mode.
pub fn into_async(self) -> OneShotTimer<'d, Async, T> {
self.inner
.set_interrupt_handler(self.inner.async_interrupt_handler());
pub fn into_async(mut self) -> OneShotTimer<'d, Async, T> {
let handler = self.inner.async_interrupt_handler();
self.inner.set_interrupt_handler(handler);
OneShotTimer {
inner: self.inner,
_ph: PhantomData,
Expand Down Expand Up @@ -502,11 +497,22 @@ impl Timer for AnyTimer {
fn enable_auto_reload(&self, auto_reload: bool);
fn enable_interrupt(&self, state: bool);
fn clear_interrupt(&self);
fn set_interrupt_handler(&self, handler: InterruptHandler);
fn is_interrupt_set(&self) -> bool;
async fn wait(&self);
fn async_interrupt_handler(&self) -> InterruptHandler;
fn peripheral_interrupt(&self) -> Interrupt;
}
}
}

impl InterruptConfigurable for AnyTimer {
delegate::delegate! {
to match &mut self.0 {
AnyTimerInner::TimgTimer(inner) => inner,
#[cfg(systimer)]
AnyTimerInner::SystimerAlarm(inner) => inner,
} {
fn set_interrupt_handler(&mut self, handler: InterruptHandler);
}
}
}
1 change: 1 addition & 0 deletions esp-hal/src/timer/systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
sync::{lock, Lock},
system::{Peripheral as PeripheralEnable, PeripheralClockControl},
Cpu,
InterruptConfigurable,
};

/// The configuration of a unit.
Expand Down
19 changes: 0 additions & 19 deletions esp-hal/src/timer/timg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,25 +316,6 @@ impl super::Timer for Timer {
self.clear_interrupt()
}

fn set_interrupt_handler(&self, handler: InterruptHandler) {
let interrupt = match (self.timer_group(), self.timer_number()) {
(0, 0) => Interrupt::TG0_T0_LEVEL,
#[cfg(timg_timer1)]
(0, 1) => Interrupt::TG0_T1_LEVEL,
#[cfg(timg1)]
(1, 0) => Interrupt::TG1_T0_LEVEL,
#[cfg(all(timg_timer1, timg1))]
(1, 1) => Interrupt::TG1_T1_LEVEL,
_ => unreachable!(),
};

for core in crate::Cpu::other() {
crate::interrupt::disable(core, interrupt);
}
unsafe { interrupt::bind_interrupt(interrupt, handler.handler()) };
unwrap!(interrupt::enable(interrupt, handler.priority()));
}

fn is_interrupt_set(&self) -> bool {
self.is_interrupt_set()
}
Expand Down

0 comments on commit 890a718

Please sign in to comment.