embassy/embassy-nrf/src/timer.rs

38 lines
1.1 KiB
Rust
Raw Normal View History

#![macro_use]
2021-03-28 22:40:41 +02:00
use embassy::interrupt::Interrupt;
use crate::pac;
2021-03-28 22:40:41 +02:00
pub(crate) mod sealed {
2021-03-28 22:40:41 +02:00
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 {}
macro_rules! impl_timer {
($type:ident, $pac_type:ident, $irq:ident) => {
impl crate::timer::sealed::Instance for peripherals::$type {
2021-03-28 22:40:41 +02:00
fn regs(&self) -> &pac::timer0::RegisterBlock {
unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) }
2021-03-28 22:40:41 +02:00
}
}
impl crate::timer::Instance for peripherals::$type {
type Interrupt = crate::interrupt::$irq;
2021-03-28 22:40:41 +02: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 22:40:41 +02:00
};
}