embassy/embassy-nrf/src/timer.rs

44 lines
1.3 KiB
Rust
Raw Normal View History

2021-03-28 22:40:41 +02:00
use embassy::interrupt::Interrupt;
use crate::{interrupt, pac, peripherals};
mod sealed {
use super::*;
pub trait Instance {
fn regs(&self) -> &pac::timer0::RegisterBlock;
}
pub trait ExtendedInstance {}
}
pub trait Instance: sealed::Instance + 'static {
type Interrupt: Interrupt;
}
pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {}
2021-03-29 00:44:11 +02:00
macro_rules! impl_instance {
2021-03-28 22:40:41 +02:00
($type:ident, $irq:ident) => {
impl sealed::Instance for peripherals::$type {
fn regs(&self) -> &pac::timer0::RegisterBlock {
unsafe { &*(pac::$type::ptr() as *const pac::timer0::RegisterBlock) }
}
}
impl Instance for peripherals::$type {
type Interrupt = interrupt::$irq;
}
};
($type:ident, $irq:ident, extended) => {
2021-03-29 00:44:11 +02:00
impl_instance!($type, $irq);
2021-03-28 22:40:41 +02:00
impl sealed::ExtendedInstance for peripherals::$type {}
impl ExtendedInstance for peripherals::$type {}
};
}
2021-03-29 00:44:11 +02:00
impl_instance!(TIMER0, TIMER0);
impl_instance!(TIMER1, TIMER1);
impl_instance!(TIMER2, TIMER2);
2021-03-28 22:40:41 +02:00
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
2021-03-29 00:44:11 +02:00
impl_instance!(TIMER3, TIMER3, extended);
2021-03-28 22:40:41 +02:00
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
2021-03-29 00:44:11 +02:00
impl_instance!(TIMER4, TIMER4, extended);