Skip to content

Commit

Permalink
Peripheral ref/systimer (#302)
Browse files Browse the repository at this point in the history
* impl Peripheral for SYSTIMER

* PeripheralRef the Systimer driver
  • Loading branch information
MabezDev authored Dec 13, 2022
1 parent dc8963c commit c7f4201
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion esp-hal-common/src/embassy/time_driver_systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{

pub const ALARM_COUNT: usize = 3;

pub type TimerType = SystemTimer;
pub type TimerType = SystemTimer<'static>;

pub struct EmbassyTimer {
pub(crate) alarms: Mutex<[AlarmState; ALARM_COUNT]>,
Expand Down
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ mod peripherals {
SPI0,
SPI1,
SPI2,
SYSTIMER,
}
}
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 @@ -50,5 +50,6 @@ mod peripherals {
SPI0,
SPI1,
SPI2,
SYSTIMER,
}
}
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 @@ -57,5 +57,6 @@ mod peripherals {
SPI2,
SPI3,
SPI4,
SYSTIMER,
}
}
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 @@ -68,5 +68,6 @@ mod peripherals {
SPI1,
SPI2,
SPI3,
SYSTIMER,
}
}
27 changes: 15 additions & 12 deletions esp-hal-common/src/systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ use core::{intrinsics::transmute, marker::PhantomData};

use fugit::MillisDurationU32;

use crate::pac::{
generic::Reg,
systimer::{
target0_conf::TARGET0_CONF_SPEC,
target0_hi::TARGET0_HI_SPEC,
target0_lo::TARGET0_LO_SPEC,
use crate::{
pac::{
generic::Reg,
systimer::{
target0_conf::TARGET0_CONF_SPEC,
target0_hi::TARGET0_HI_SPEC,
target0_lo::TARGET0_LO_SPEC,
},
},
SYSTIMER,
peripheral::{Peripheral, PeripheralRef},
peripherals::SYSTIMER,
};

// TODO this only handles unit0 of the systimer

#[derive(Debug)]
pub struct SystemTimer {
_inner: SYSTIMER,
pub struct SystemTimer<'d> {
_inner: PeripheralRef<'d, SYSTIMER>,
pub alarm0: Alarm<Target, 0>,
pub alarm1: Alarm<Target, 1>,
pub alarm2: Alarm<Target, 2>,
}

impl SystemTimer {
impl<'d> SystemTimer<'d> {
#[cfg(esp32s2)]
pub const BIT_MASK: u64 = u64::MAX;
#[cfg(any(esp32c2, esp32c3, esp32s3))]
Expand All @@ -33,7 +35,8 @@ impl SystemTimer {
#[cfg(any(esp32c2, esp32c3, esp32s3))]
pub const TICKS_PER_SECOND: u64 = 16_000_000;

pub fn new(p: SYSTIMER) -> Self {
pub fn new(p: impl Peripheral<P = SYSTIMER> + 'd) -> Self {
crate::into_ref!(p);
Self {
_inner: p,
alarm0: Alarm::new(),
Expand Down

0 comments on commit c7f4201

Please sign in to comment.