2021-05-11 01:04:59 +00:00
|
|
|
#![macro_use]
|
|
|
|
|
2021-03-28 20:40:41 +00:00
|
|
|
use embassy::interrupt::Interrupt;
|
|
|
|
|
2021-05-11 01:04:59 +00:00
|
|
|
use crate::pac;
|
2021-03-28 20:40:41 +00:00
|
|
|
|
2021-05-11 01:04:59 +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: sealed::Instance + 'static {
|
|
|
|
type Interrupt: Interrupt;
|
|
|
|
}
|
|
|
|
pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {}
|
|
|
|
|
2021-05-11 01:04:59 +00:00
|
|
|
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 {
|
2021-05-11 01:04:59 +00:00
|
|
|
unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) }
|
2021-03-28 20:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-11 01:04:59 +00:00
|
|
|
impl crate::timer::Instance for peripherals::$type {
|
|
|
|
type Interrupt = crate::interrupt::$irq;
|
2021-03-28 20:40:41 +00:00
|
|
|
}
|
|
|
|
};
|
2021-05-11 01:04:59 +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
|
|
|
};
|
|
|
|
}
|