nrf/timer: add instance traits
This commit is contained in:
parent
aa0341056e
commit
31b817ed27
@ -103,6 +103,7 @@ pub mod qspi;
|
|||||||
pub mod rtc;
|
pub mod rtc;
|
||||||
pub mod saadc;
|
pub mod saadc;
|
||||||
pub mod spim;
|
pub mod spim;
|
||||||
|
pub mod timer;
|
||||||
pub mod uarte;
|
pub mod uarte;
|
||||||
|
|
||||||
embassy_extras::peripherals! {
|
embassy_extras::peripherals! {
|
||||||
@ -135,6 +136,15 @@ embassy_extras::peripherals! {
|
|||||||
// SAADC
|
// SAADC
|
||||||
SAADC,
|
SAADC,
|
||||||
|
|
||||||
|
// TIMER
|
||||||
|
TIMER0,
|
||||||
|
TIMER1,
|
||||||
|
TIMER2,
|
||||||
|
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
|
||||||
|
TIMER3,
|
||||||
|
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
|
||||||
|
TIMER4,
|
||||||
|
|
||||||
// GPIOTE
|
// GPIOTE
|
||||||
GPIOTE,
|
GPIOTE,
|
||||||
GPIOTE_CH0,
|
GPIOTE_CH0,
|
||||||
|
43
embassy-nrf/src/timer.rs
Normal file
43
embassy-nrf/src/timer.rs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
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 {}
|
||||||
|
|
||||||
|
macro_rules! make_impl {
|
||||||
|
($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) => {
|
||||||
|
make_impl!($type, $irq);
|
||||||
|
impl sealed::ExtendedInstance for peripherals::$type {}
|
||||||
|
impl ExtendedInstance for peripherals::$type {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_impl!(TIMER0, TIMER0);
|
||||||
|
make_impl!(TIMER1, TIMER1);
|
||||||
|
make_impl!(TIMER2, TIMER2);
|
||||||
|
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
|
||||||
|
make_impl!(TIMER3, TIMER3, extended);
|
||||||
|
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
|
||||||
|
make_impl!(TIMER4, TIMER4, extended);
|
Loading…
Reference in New Issue
Block a user