|
4 | 4 |
|
5 | 5 | #[cfg(feature = "9160")]
|
6 | 6 | use crate::pac::{
|
7 |
| - timer0_ns::RegisterBlock as RegBlock0, Interrupt, TIMER0_NS as TIMER0, TIMER1_NS as TIMER1, |
8 |
| - TIMER2_NS as TIMER2, |
| 7 | + generic::Reg, |
| 8 | + timer0_ns::{ |
| 9 | + RegisterBlock as RegBlock0, _EVENTS_COMPARE, _TASKS_CAPTURE, _TASKS_CLEAR, _TASKS_COUNT, |
| 10 | + _TASKS_START, _TASKS_STOP, |
| 11 | + }, |
| 12 | + Interrupt, TIMER0_NS as TIMER0, TIMER1_NS as TIMER1, TIMER2_NS as TIMER2, |
9 | 13 | };
|
10 | 14 |
|
11 | 15 | #[cfg(not(feature = "9160"))]
|
12 |
| -use crate::pac::{timer0::RegisterBlock as RegBlock0, Interrupt, TIMER0, TIMER1, TIMER2}; |
13 |
| - |
| 16 | +use crate::pac::{ |
| 17 | + generic::Reg, |
| 18 | + timer0::{ |
| 19 | + RegisterBlock as RegBlock0, _EVENTS_COMPARE, _TASKS_CAPTURE, _TASKS_CLEAR, _TASKS_COUNT, |
| 20 | + _TASKS_START, _TASKS_STOP, |
| 21 | + }, |
| 22 | + Interrupt, TIMER0, TIMER1, TIMER2, |
| 23 | +}; |
14 | 24 | use cast::u32;
|
15 | 25 | use embedded_hal::{
|
16 | 26 | blocking::delay::{DelayMs, DelayUs},
|
@@ -135,6 +145,43 @@ where
|
135 | 145 | Err(x) => unreachable(x),
|
136 | 146 | }
|
137 | 147 | }
|
| 148 | + |
| 149 | + /// Returns reference to the `START` task endpoint for PPI. |
| 150 | + /// Starts timer. |
| 151 | + pub fn task_start(&self) -> &Reg<u32, _TASKS_START> { |
| 152 | + &self.0.as_timer0().tasks_start |
| 153 | + } |
| 154 | + |
| 155 | + /// Returns reference to the `STOP` task endpoint for PPI. |
| 156 | + /// Stops timer. |
| 157 | + pub fn task_stop(&self) -> &Reg<u32, _TASKS_STOP> { |
| 158 | + &self.0.as_timer0().tasks_stop |
| 159 | + } |
| 160 | + |
| 161 | + /// Returns reference to the `COUNT` task endpoint for PPI. |
| 162 | + /// Increments timer (counter mode only). |
| 163 | + pub fn task_count(&self) -> &Reg<u32, _TASKS_COUNT> { |
| 164 | + &self.0.as_timer0().tasks_count |
| 165 | + } |
| 166 | + |
| 167 | + /// Returns reference to the `CLEAR` task endpoint for PPI. |
| 168 | + /// Clears timer. |
| 169 | + pub fn task_clear(&self) -> &Reg<u32, _TASKS_CLEAR> { |
| 170 | + &self.0.as_timer0().tasks_clear |
| 171 | + } |
| 172 | + |
| 173 | + /// Returns reference to the `CAPTURE` task endpoint for PPI. |
| 174 | + /// Captures timer value to the given CC register. |
| 175 | + pub fn task_capture(&self, cc: CC) -> &Reg<u32, _TASKS_CAPTURE> { |
| 176 | + &self.0.as_timer0().tasks_capture[cc as usize] |
| 177 | + } |
| 178 | + |
| 179 | + /// Returns reference to `COMPARE` event endpoint for PPI. |
| 180 | + /// Generated when the counter is incremented and then matches the value |
| 181 | + /// specified in the given CC register |
| 182 | + pub fn event_compare(&self, cc: CC) -> &Reg<u32, _EVENTS_COMPARE> { |
| 183 | + &self.0.as_timer0().events_compare[cc as usize] |
| 184 | + } |
138 | 185 | }
|
139 | 186 |
|
140 | 187 | impl<T, U> timer::CountDown for Timer<T, U>
|
@@ -341,6 +388,15 @@ pub trait Instance: sealed::Sealed {
|
341 | 388 | }
|
342 | 389 | }
|
343 | 390 |
|
| 391 | +pub enum CC { |
| 392 | + CC0 = 0, |
| 393 | + CC1, |
| 394 | + CC2, |
| 395 | + CC3, |
| 396 | + CC4, |
| 397 | + CC5, |
| 398 | +} |
| 399 | + |
344 | 400 | impl Instance for TIMER0 {
|
345 | 401 | const INTERRUPT: Interrupt = Interrupt::TIMER0;
|
346 | 402 |
|
|
0 commit comments