embassy/embassy-nrf/src/timer.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

#![macro_use]
2021-03-28 20:40:41 +00:00
use embassy::interrupt::Interrupt;
use embassy::util::Unborrow;
2021-03-28 20:40:41 +00:00
use crate::pac;
2021-03-28 20:40:41 +00:00
pub(crate) mod sealed {
2021-03-28 20:40:41 +00:00
use super::*;
pub trait Instance {
fn regs(&self) -> &pac::timer0::RegisterBlock;
}
pub trait ExtendedInstance {}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
2021-03-28 20:40:41 +00:00
type Interrupt: Interrupt;
}
pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {}
macro_rules! impl_timer {
($type:ident, $pac_type:ident, $irq:ident) => {
impl crate::timer::sealed::Instance for peripherals::$type {
2021-03-28 20:40:41 +00:00
fn regs(&self) -> &pac::timer0::RegisterBlock {
unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) }
2021-03-28 20:40:41 +00:00
}
}
impl crate::timer::Instance for peripherals::$type {
type Interrupt = crate::interrupt::$irq;
2021-03-28 20:40:41 +00:00
}
};
($type:ident, $pac_type:ident, $irq:ident, extended) => {
impl_timer!($type, $pac_type, $irq);
impl crate::timer::sealed::ExtendedInstance for peripherals::$type {}
impl crate::timer::ExtendedInstance for peripherals::$type {}
2021-03-28 20:40:41 +00:00
};
}