Use peripheral ref pattern for OneShotTimer and PeriodicTimer` (#1855)

* Use the peripheral ref pattern for `OneShotTimer` and `PeriodicTimer`

* Update tests and examples to reflect changes in timer API

* Update `CHANGELOG.md`
This commit is contained in:
Jesse Braham 2024-07-25 12:52:34 +00:00 committed by GitHub
parent c7218fba2b
commit 3215d93f53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 309 additions and 339 deletions

View File

@ -12,7 +12,7 @@ use esp_hal::{
pub const MAX_SUPPORTED_ALARM_COUNT: usize = 7;
pub type Timer = OneShotTimer<ErasedTimer>;
pub type Timer = OneShotTimer<'static, ErasedTimer>;
static TIMERS: Mutex<RefCell<Option<&'static mut [Timer]>>> = Mutex::new(RefCell::new(None));

View File

@ -10,13 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
### Changed
- Peripheral driver constructors don't take `InterruptHandler`s anymore. Use `set_interrupt_handler` to explicitly set the interrupt handler now. (#1819)
- Use the peripheral ref pattern for `OneShotTimer` and `PeriodicTimer` (#1855)
- Allow DMA to/from psram for esp32s3 (#1827)
### Fixed
- Improve error detection in the I2C driver (#1847)
- Improve error detection in the I2C driver (#1847)
- Fix I2S async-tx (#1833)
- Fix PARL_IO async-rx (#1851)

View File

@ -42,7 +42,12 @@
use fugit::{ExtU64, Instant, MicrosDurationU64};
use crate::{interrupt::InterruptHandler, private, InterruptConfigurable};
use crate::{
interrupt::InterruptHandler,
peripheral::{Peripheral, PeripheralRef},
Blocking,
InterruptConfigurable,
};
#[cfg(systimer)]
pub mod systimer;
@ -106,16 +111,18 @@ pub trait Timer: crate::private::Sealed {
}
/// A one-shot timer.
pub struct OneShotTimer<T> {
inner: T,
pub struct OneShotTimer<'d, T> {
inner: PeripheralRef<'d, T>,
}
impl<T> OneShotTimer<T>
impl<'d, T> OneShotTimer<'d, T>
where
T: Timer,
{
/// Construct a new instance of [`OneShotTimer`].
pub fn new(inner: T) -> Self {
pub fn new(inner: impl Peripheral<P = T> + 'd) -> Self {
crate::into_ref!(inner);
Self { inner }
}
@ -194,9 +201,9 @@ where
}
}
impl<T> crate::private::Sealed for OneShotTimer<T> where T: Timer {}
impl<'d, T> crate::private::Sealed for OneShotTimer<'d, T> where T: Timer {}
impl<T> InterruptConfigurable for OneShotTimer<T>
impl<'d, T> InterruptConfigurable for OneShotTimer<'d, T>
where
T: Timer,
{
@ -206,7 +213,7 @@ where
}
#[cfg(feature = "embedded-hal-02")]
impl<T, UXX> embedded_hal_02::blocking::delay::DelayMs<UXX> for OneShotTimer<T>
impl<'d, T, UXX> embedded_hal_02::blocking::delay::DelayMs<UXX> for OneShotTimer<'d, T>
where
T: Timer,
UXX: Into<u32>,
@ -217,7 +224,7 @@ where
}
#[cfg(feature = "embedded-hal-02")]
impl<T, UXX> embedded_hal_02::blocking::delay::DelayUs<UXX> for OneShotTimer<T>
impl<'d, T, UXX> embedded_hal_02::blocking::delay::DelayUs<UXX> for OneShotTimer<'d, T>
where
T: Timer,
UXX: Into<u32>,
@ -228,7 +235,7 @@ where
}
#[cfg(feature = "embedded-hal")]
impl<T> embedded_hal::delay::DelayNs for OneShotTimer<T>
impl<'d, T> embedded_hal::delay::DelayNs for OneShotTimer<'d, T>
where
T: Timer,
{
@ -238,16 +245,18 @@ where
}
/// A periodic timer.
pub struct PeriodicTimer<T> {
inner: T,
pub struct PeriodicTimer<'d, T> {
inner: PeripheralRef<'d, T>,
}
impl<T> PeriodicTimer<T>
impl<'d, T> PeriodicTimer<'d, T>
where
T: Timer,
{
/// Construct a new instance of [`PeriodicTimer`].
pub fn new(inner: T) -> Self {
pub fn new(inner: impl Peripheral<P = T> + 'd) -> Self {
crate::into_ref!(inner);
Self { inner }
}
@ -309,9 +318,9 @@ where
}
}
impl<T> crate::private::Sealed for PeriodicTimer<T> where T: Timer {}
impl<'d, T> crate::private::Sealed for PeriodicTimer<'d, T> where T: Timer {}
impl<T> InterruptConfigurable for PeriodicTimer<T>
impl<'d, T> InterruptConfigurable for PeriodicTimer<'d, T>
where
T: Timer,
{
@ -320,104 +329,142 @@ where
}
}
#[cfg(feature = "embedded-hal-02")]
impl<'d, T> embedded_hal_02::timer::CountDown for PeriodicTimer<'d, T>
where
T: Timer,
{
type Time = MicrosDurationU64;
fn start<Time>(&mut self, timeout: Time)
where
Time: Into<Self::Time>,
{
self.start(timeout.into()).unwrap();
}
fn wait(&mut self) -> nb::Result<(), void::Void> {
self.wait()
}
}
#[cfg(feature = "embedded-hal-02")]
impl<'d, T> embedded_hal_02::timer::Cancel for PeriodicTimer<'d, T>
where
T: Timer,
{
type Error = Error;
fn cancel(&mut self) -> Result<(), Self::Error> {
self.cancel()
}
}
#[cfg(feature = "embedded-hal-02")]
impl<'d, T> embedded_hal_02::timer::Periodic for PeriodicTimer<'d, T> where T: Timer {}
/// A type-erased timer
///
/// You can create an instance of this by just calling `.into()` on a timer.
#[allow(missing_docs)]
pub enum ErasedTimer {
Timg0Timer0(timg::Timer<timg::Timer0<crate::peripherals::TIMG0>, crate::Blocking>),
Timg0Timer0(timg::Timer<timg::Timer0<crate::peripherals::TIMG0>, Blocking>),
#[cfg(timg_timer1)]
Timg0Timer1(timg::Timer<timg::Timer1<crate::peripherals::TIMG0>, crate::Blocking>),
Timg0Timer1(timg::Timer<timg::Timer1<crate::peripherals::TIMG0>, Blocking>),
#[cfg(timg1)]
Timg1Timer0(timg::Timer<timg::Timer0<crate::peripherals::TIMG1>, crate::Blocking>),
Timg1Timer0(timg::Timer<timg::Timer0<crate::peripherals::TIMG1>, Blocking>),
#[cfg(all(timg1, timg_timer1))]
Timg1Timer1(timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, crate::Blocking>),
Timg1Timer1(timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, Blocking>),
#[cfg(systimer)]
SystimerAlarm0Periodic(systimer::Alarm<systimer::Periodic, crate::Blocking, 0>),
SystimerAlarm0Periodic(systimer::Alarm<systimer::Periodic, Blocking, 0>),
#[cfg(systimer)]
SystimerAlarm1Periodic(systimer::Alarm<systimer::Periodic, crate::Blocking, 1>),
SystimerAlarm1Periodic(systimer::Alarm<systimer::Periodic, Blocking, 1>),
#[cfg(systimer)]
SystimerAlarm2Periodic(systimer::Alarm<systimer::Periodic, crate::Blocking, 2>),
SystimerAlarm2Periodic(systimer::Alarm<systimer::Periodic, Blocking, 2>),
#[cfg(systimer)]
SystimerAlarm0Target(systimer::Alarm<systimer::Target, crate::Blocking, 0>),
SystimerAlarm0Target(systimer::Alarm<systimer::Target, Blocking, 0>),
#[cfg(systimer)]
SystimerAlarm1Target(systimer::Alarm<systimer::Target, crate::Blocking, 1>),
SystimerAlarm1Target(systimer::Alarm<systimer::Target, Blocking, 1>),
#[cfg(systimer)]
SystimerAlarm2Target(systimer::Alarm<systimer::Target, crate::Blocking, 2>),
SystimerAlarm2Target(systimer::Alarm<systimer::Target, Blocking, 2>),
}
impl private::Sealed for ErasedTimer {}
impl crate::private::Sealed for ErasedTimer {}
impl From<timg::Timer<timg::Timer0<crate::peripherals::TIMG0>, crate::Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer0<crate::peripherals::TIMG0>, crate::Blocking>) -> Self {
impl From<timg::Timer<timg::Timer0<crate::peripherals::TIMG0>, Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer0<crate::peripherals::TIMG0>, Blocking>) -> Self {
Self::Timg0Timer0(value)
}
}
#[cfg(timg_timer1)]
impl From<timg::Timer<timg::Timer1<crate::peripherals::TIMG0>, crate::Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer1<crate::peripherals::TIMG0>, crate::Blocking>) -> Self {
impl From<timg::Timer<timg::Timer1<crate::peripherals::TIMG0>, Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer1<crate::peripherals::TIMG0>, Blocking>) -> Self {
Self::Timg0Timer1(value)
}
}
#[cfg(timg1)]
impl From<timg::Timer<timg::Timer0<crate::peripherals::TIMG1>, crate::Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer0<crate::peripherals::TIMG1>, crate::Blocking>) -> Self {
impl From<timg::Timer<timg::Timer0<crate::peripherals::TIMG1>, Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer0<crate::peripherals::TIMG1>, Blocking>) -> Self {
Self::Timg1Timer0(value)
}
}
#[cfg(all(timg1, timg_timer1))]
impl From<timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, crate::Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, crate::Blocking>) -> Self {
impl From<timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, Blocking>> for ErasedTimer {
fn from(value: timg::Timer<timg::Timer1<crate::peripherals::TIMG1>, Blocking>) -> Self {
Self::Timg1Timer1(value)
}
}
#[cfg(systimer)]
impl From<systimer::Alarm<systimer::Periodic, crate::Blocking, 0>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Periodic, crate::Blocking, 0>) -> Self {
impl From<systimer::Alarm<systimer::Periodic, Blocking, 0>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Periodic, Blocking, 0>) -> Self {
Self::SystimerAlarm0Periodic(value)
}
}
#[cfg(systimer)]
impl From<systimer::Alarm<systimer::Periodic, crate::Blocking, 1>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Periodic, crate::Blocking, 1>) -> Self {
impl From<systimer::Alarm<systimer::Periodic, Blocking, 1>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Periodic, Blocking, 1>) -> Self {
Self::SystimerAlarm1Periodic(value)
}
}
#[cfg(systimer)]
impl From<systimer::Alarm<systimer::Periodic, crate::Blocking, 2>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Periodic, crate::Blocking, 2>) -> Self {
impl From<systimer::Alarm<systimer::Periodic, Blocking, 2>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Periodic, Blocking, 2>) -> Self {
Self::SystimerAlarm2Periodic(value)
}
}
#[cfg(systimer)]
impl From<systimer::Alarm<systimer::Target, crate::Blocking, 0>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Target, crate::Blocking, 0>) -> Self {
impl From<systimer::Alarm<systimer::Target, Blocking, 0>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Target, Blocking, 0>) -> Self {
Self::SystimerAlarm0Target(value)
}
}
#[cfg(systimer)]
impl From<systimer::Alarm<systimer::Target, crate::Blocking, 1>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Target, crate::Blocking, 1>) -> Self {
impl From<systimer::Alarm<systimer::Target, Blocking, 1>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Target, Blocking, 1>) -> Self {
Self::SystimerAlarm1Target(value)
}
}
#[cfg(systimer)]
impl From<systimer::Alarm<systimer::Target, crate::Blocking, 2>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Target, crate::Blocking, 2>) -> Self {
impl From<systimer::Alarm<systimer::Target, Blocking, 2>> for ErasedTimer {
fn from(value: systimer::Alarm<systimer::Target, Blocking, 2>) -> Self {
Self::SystimerAlarm2Target(value)
}
}
impl Timer for ErasedTimer {
// Rather than manually implementing `Timer` for each variant of `ErasedTimer`,
// we use `delegate::delegate!{}` to do this for us. Otherwise, each function
// implementation would require its own `match` block for each enum variant,
// which would very quickly result in a large amount of duplicated code.
delegate::delegate! {
to match self {
ErasedTimer::Timg0Timer0(inner) => inner,
@ -456,36 +503,11 @@ impl Timer for ErasedTimer {
}
}
#[cfg(feature = "embedded-hal-02")]
impl<T> embedded_hal_02::timer::CountDown for PeriodicTimer<T>
where
T: Timer,
{
type Time = MicrosDurationU64;
impl Peripheral for ErasedTimer {
type P = Self;
fn start<Time>(&mut self, timeout: Time)
where
Time: Into<Self::Time>,
{
self.start(timeout.into()).unwrap();
}
fn wait(&mut self) -> nb::Result<(), void::Void> {
self.wait()
#[inline]
unsafe fn clone_unchecked(&mut self) -> Self::P {
core::ptr::read(self as *const _)
}
}
#[cfg(feature = "embedded-hal-02")]
impl<T> embedded_hal_02::timer::Cancel for PeriodicTimer<T>
where
T: Timer,
{
type Error = Error;
fn cancel(&mut self) -> Result<(), Self::Error> {
self.cancel()
}
}
#[cfg(feature = "embedded-hal-02")]
impl<T> embedded_hal_02::timer::Periodic for PeriodicTimer<T> where T: Timer {}

View File

@ -586,6 +586,18 @@ where
}
}
impl<T, DM, const CHANNEL: u8> Peripheral for Alarm<T, DM, CHANNEL>
where
DM: Mode,
{
type P = Self;
#[inline]
unsafe fn clone_unchecked(&mut self) -> Self::P {
core::ptr::read(self as *const _)
}
}
// Async functionality of the system timer.
#[cfg(feature = "async")]
mod asynch {

View File

@ -522,6 +522,19 @@ where
}
}
impl<T, DM> Peripheral for Timer<T, DM>
where
T: Instance,
DM: Mode,
{
type P = Self;
#[inline]
unsafe fn clone_unchecked(&mut self) -> Self::P {
core::ptr::read(self as *const _)
}
}
#[doc(hidden)]
pub trait Instance: Sealed + Enable {
fn register_block(&self) -> &RegisterBlock;

View File

@ -20,7 +20,7 @@ use crate::{
};
/// The timer responsible for time slicing.
pub type TimeBase = PeriodicTimer<ErasedTimer>;
pub type TimeBase = PeriodicTimer<'static, ErasedTimer>;
static ALARM0: Mutex<RefCell<Option<TimeBase>>> = Mutex::new(RefCell::new(None));
const TIMESLICE_FREQUENCY: fugit::HertzU64 =
fugit::HertzU64::from_raw(crate::CONFIG.tick_rate_hz as u64);

View File

@ -12,7 +12,7 @@ use crate::{
};
/// The timer responsible for time slicing.
pub type TimeBase = PeriodicTimer<ErasedTimer>;
pub type TimeBase = PeriodicTimer<'static, ErasedTimer>;
static TIMER1: Mutex<RefCell<Option<TimeBase>>> = Mutex::new(RefCell::new(None));
const TIMESLICE_FREQUENCY: fugit::HertzU64 =
fugit::HertzU64::from_raw(crate::CONFIG.tick_rate_hz as u64);

View File

@ -47,8 +47,8 @@ async fn main(spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -47,8 +47,8 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -47,8 +47,8 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -50,8 +50,8 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -72,8 +72,8 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -71,9 +71,9 @@ async fn main(_spawner: Spawner) {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timer1 = OneShotTimer::new(timg0.timer1.into());
let timers = [timer0, timer1];
let timer0: ErasedTimer = timg0.timer0.into();
let timer1: ErasedTimer = timg0.timer1.into();
let timers = [OneShotTimer::new(timer0), OneShotTimer::new(timer1)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 2], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -91,9 +91,9 @@ fn main() -> ! {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timer1 = OneShotTimer::new(timg0.timer1.into());
let timers = [timer0, timer1];
let timer0: ErasedTimer = timg0.timer0.into();
let timer1: ErasedTimer = timg0.timer1.into();
let timers = [OneShotTimer::new(timer0), OneShotTimer::new(timer1)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 2], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -88,17 +88,22 @@ async fn main(low_prio_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timer0: ErasedTimer = timg0.timer0.into();
let timer0 = OneShotTimer::new(timer0);
#[cfg(not(feature = "esp32c2"))]
let timer1 = {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
OneShotTimer::new(timg1.timer0.into())
let timer0: ErasedTimer = timg1.timer0.into();
OneShotTimer::new(timer0)
};
#[cfg(feature = "esp32c2")]
let timer1 = {
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
OneShotTimer::new(systimer.alarm0.into())
let alarm0: ErasedTimer = systimer.alarm0.into();
OneShotTimer::new(alarm0)
};
let timers = [timer0, timer1];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 2], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -44,7 +44,8 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let systimer = SystemTimer::new(peripherals.SYSTIMER);
let timers = [OneShotTimer::new(systimer.alarm0.into())];
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -55,7 +55,8 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let systimer = SystemTimer::new(peripherals.SYSTIMER);
let timers = [OneShotTimer::new(systimer.alarm0.into())];
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -57,8 +57,8 @@ async fn main(spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -43,8 +43,8 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -95,8 +95,8 @@ async fn main(spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0 = OneShotTimer::new(timg0.timer0.into());
let timers = [timer0];
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);

View File

@ -54,10 +54,9 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timers = mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg0.timer0.into())]
);
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

View File

@ -99,10 +99,9 @@ async fn main(spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timers = mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg0.timer0.into())]
);
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

View File

@ -50,13 +50,10 @@ async fn main(_spawner: Spawner) -> () {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg0.timer0.into())]
),
);
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

View File

@ -80,13 +80,10 @@ async fn main(spawner: Spawner) -> () {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg0.timer0.into())]
),
);
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
let (tx, rx) = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split();

View File

@ -37,13 +37,10 @@ async fn main(_spawner: Spawner) {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg0.timer0.into())]
),
);
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))]

View File

@ -21,7 +21,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::{print, println};
use esp_wifi::{
@ -47,11 +47,9 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,

View File

@ -22,7 +22,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::{print, println};
use esp_wifi::{
@ -54,11 +54,9 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,

View File

@ -22,7 +22,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{
@ -67,11 +67,9 @@ fn main() -> ! {
let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address");
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,

View File

@ -30,7 +30,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor};
@ -44,11 +44,9 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Ble,

View File

@ -32,7 +32,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::{print, println};
use esp_wifi::{
@ -60,11 +60,9 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::WifiBle,

View File

@ -19,7 +19,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::{print, println};
use esp_wifi::{
@ -53,11 +53,9 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,

View File

@ -32,7 +32,7 @@ use esp_hal::{
peripherals::Peripherals,
rng::Rng,
system::SystemControl,
timer::{ErasedTimer, OneShotTimer, PeriodicTimer},
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
};
use esp_println::{print, println};
use esp_wifi::{
@ -68,11 +68,9 @@ async fn main(spawner: Spawner) -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,
@ -89,26 +87,20 @@ async fn main(spawner: Spawner) -> ! {
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg1.timer0.into())]
),
);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let timer0: ErasedTimer = timg1.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(systimer.alarm0.into())]
),
);
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
let config = Config::ipv4_static(StaticConfigV4 {

View File

@ -35,7 +35,7 @@ use esp_hal::{
peripherals::Peripherals,
rng::Rng,
system::SystemControl,
timer::{ErasedTimer, OneShotTimer, PeriodicTimer},
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
};
use esp_println::{print, println};
use esp_wifi::{
@ -76,11 +76,9 @@ async fn main(spawner: Spawner) -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,
@ -97,26 +95,20 @@ async fn main(spawner: Spawner) -> ! {
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg1.timer0.into())]
),
);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let timer0: ErasedTimer = timg1.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(systimer.alarm0.into())]
),
);
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
let ap_config = Config::ipv4_static(StaticConfigV4 {

View File

@ -26,7 +26,7 @@ use esp_hal::{
peripherals::Peripherals,
rng::Rng,
system::SystemControl,
timer::{ErasedTimer, OneShotTimer, PeriodicTimer},
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{
@ -80,11 +80,9 @@ async fn main(spawner: Spawner) -> ! {
let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address");
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,
@ -101,26 +99,20 @@ async fn main(spawner: Spawner) -> ! {
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg1.timer0.into())]
),
);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let timer0: ErasedTimer = timg1.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(systimer.alarm0.into())]
),
);
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
let config = Config::dhcpv4(Default::default());

View File

@ -32,7 +32,7 @@ use esp_hal::{
peripherals::*,
rng::Rng,
system::SystemControl,
timer::{ErasedTimer, OneShotTimer, PeriodicTimer},
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{ble::controller::asynch::BleConnector, initialize, EspWifiInitFor};
@ -56,11 +56,9 @@ async fn main(_spawner: Spawner) -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Ble,
@ -84,26 +82,20 @@ async fn main(_spawner: Spawner) -> ! {
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg1.timer0.into())]
),
);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let timer0: ErasedTimer = timg1.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(systimer.alarm0.into())]
),
);
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
let mut bluetooth = peripherals.BT;

View File

@ -22,7 +22,7 @@ use esp_hal::{
peripherals::Peripherals,
rng::Rng,
system::SystemControl,
timer::{ErasedTimer, OneShotTimer, PeriodicTimer},
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{
@ -61,11 +61,9 @@ async fn main(spawner: Spawner) -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,
@ -82,26 +80,20 @@ async fn main(spawner: Spawner) -> ! {
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg1.timer0.into())]
),
);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let timer0: ErasedTimer = timg1.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(systimer.alarm0.into())]
),
);
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
let config = Config::dhcpv4(Default::default());

View File

@ -19,7 +19,7 @@ use esp_hal::{
peripherals::Peripherals,
rng::Rng,
system::SystemControl,
timer::{ErasedTimer, OneShotTimer, PeriodicTimer},
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{
@ -47,11 +47,9 @@ async fn main(_spawner: Spawner) -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,
@ -68,26 +66,20 @@ async fn main(_spawner: Spawner) -> ! {
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg1.timer0.into())]
),
);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let timer0: ErasedTimer = timg1.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(systimer.alarm0.into())]
),
);
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
let mut ticker = Ticker::every(Duration::from_secs(5));

View File

@ -19,7 +19,7 @@ use esp_hal::{
peripherals::Peripherals,
rng::Rng,
system::SystemControl,
timer::{ErasedTimer, OneShotTimer, PeriodicTimer},
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{
@ -47,11 +47,9 @@ async fn main(spawner: Spawner) -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,
@ -68,26 +66,20 @@ async fn main(spawner: Spawner) -> ! {
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg1.timer0.into())]
),
);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let timer0: ErasedTimer = timg1.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(systimer.alarm0.into())]
),
);
let alarm0: ErasedTimer = systimer.alarm0.into();
let timers = [OneShotTimer::new(alarm0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
}
let (manager, sender, receiver) = esp_now.split();

View File

@ -15,7 +15,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::println;
use esp_wifi::{
@ -34,11 +34,9 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,

View File

@ -20,7 +20,7 @@ use esp_hal::{
prelude::*,
rng::Rng,
system::SystemControl,
timer::PeriodicTimer,
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
};
use esp_println::{print, println};
use esp_wifi::{
@ -53,11 +53,9 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks)
.timer0
.into(),
);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer0: ErasedTimer = timg0.timer0.into();
let timer = PeriodicTimer::new(timer0);
let init = initialize(
EspWifiInitFor::Wifi,

View File

@ -55,13 +55,10 @@ impl<'d> Context<'d> {
let delay = Delay::new(&clocks);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
esp_hal_embassy::init(
&clocks,
mk_static!(
[OneShotTimer<ErasedTimer>; 1],
[OneShotTimer::new(timg0.timer0.into())]
),
);
let timer0: ErasedTimer = timg0.timer0.into();
let timers = [OneShotTimer::new(timer0)];
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
esp_hal_embassy::init(&clocks, timers);
Context {
io2: Input::new(io.pins.gpio2, Pull::Down),