diff options
| -rw-r--r-- | embassy-nrf/src/lib.rs | 10 | ||||
| -rw-r--r-- | embassy-nrf/src/timer.rs | 43 |
2 files changed, 53 insertions, 0 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 1bcaf5483..67ff9dc31 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -103,6 +103,7 @@ pub mod qspi; | |||
| 103 | pub mod rtc; | 103 | pub mod rtc; |
| 104 | pub mod saadc; | 104 | pub mod saadc; |
| 105 | pub mod spim; | 105 | pub mod spim; |
| 106 | pub mod timer; | ||
| 106 | pub mod uarte; | 107 | pub mod uarte; |
| 107 | 108 | ||
| 108 | embassy_extras::peripherals! { | 109 | embassy_extras::peripherals! { |
| @@ -135,6 +136,15 @@ embassy_extras::peripherals! { | |||
| 135 | // SAADC | 136 | // SAADC |
| 136 | SAADC, | 137 | SAADC, |
| 137 | 138 | ||
| 139 | // TIMER | ||
| 140 | TIMER0, | ||
| 141 | TIMER1, | ||
| 142 | TIMER2, | ||
| 143 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 144 | TIMER3, | ||
| 145 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 146 | TIMER4, | ||
| 147 | |||
| 138 | // GPIOTE | 148 | // GPIOTE |
| 139 | GPIOTE, | 149 | GPIOTE, |
| 140 | GPIOTE_CH0, | 150 | GPIOTE_CH0, |
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs new file mode 100644 index 000000000..6307a15ee --- /dev/null +++ b/embassy-nrf/src/timer.rs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | use embassy::interrupt::Interrupt; | ||
| 2 | |||
| 3 | use crate::{interrupt, pac, peripherals}; | ||
| 4 | |||
| 5 | mod sealed { | ||
| 6 | use super::*; | ||
| 7 | |||
| 8 | pub trait Instance { | ||
| 9 | fn regs(&self) -> &pac::timer0::RegisterBlock; | ||
| 10 | } | ||
| 11 | pub trait ExtendedInstance {} | ||
| 12 | } | ||
| 13 | |||
| 14 | pub trait Instance: sealed::Instance + 'static { | ||
| 15 | type Interrupt: Interrupt; | ||
| 16 | } | ||
| 17 | pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {} | ||
| 18 | |||
| 19 | macro_rules! make_impl { | ||
| 20 | ($type:ident, $irq:ident) => { | ||
| 21 | impl sealed::Instance for peripherals::$type { | ||
| 22 | fn regs(&self) -> &pac::timer0::RegisterBlock { | ||
| 23 | unsafe { &*(pac::$type::ptr() as *const pac::timer0::RegisterBlock) } | ||
| 24 | } | ||
| 25 | } | ||
| 26 | impl Instance for peripherals::$type { | ||
| 27 | type Interrupt = interrupt::$irq; | ||
| 28 | } | ||
| 29 | }; | ||
| 30 | ($type:ident, $irq:ident, extended) => { | ||
| 31 | make_impl!($type, $irq); | ||
| 32 | impl sealed::ExtendedInstance for peripherals::$type {} | ||
| 33 | impl ExtendedInstance for peripherals::$type {} | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | |||
| 37 | make_impl!(TIMER0, TIMER0); | ||
| 38 | make_impl!(TIMER1, TIMER1); | ||
| 39 | make_impl!(TIMER2, TIMER2); | ||
| 40 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 41 | make_impl!(TIMER3, TIMER3, extended); | ||
| 42 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 43 | make_impl!(TIMER4, TIMER4, extended); | ||
