Skip to content

Commit 65e399f

Browse files
committed
Add task- and event endpoint getters for PPI usage
1 parent 47c478c commit 65e399f

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

nrf-hal-common/src/timer.rs

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
55
#[cfg(feature = "9160")]
66
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,
913
};
1014

1115
#[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+
};
1424
use cast::u32;
1525
use embedded_hal::{
1626
blocking::delay::{DelayMs, DelayUs},
@@ -135,6 +145,43 @@ where
135145
Err(x) => unreachable(x),
136146
}
137147
}
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+
}
138185
}
139186

140187
impl<T, U> timer::CountDown for Timer<T, U>
@@ -341,6 +388,15 @@ pub trait Instance: sealed::Sealed {
341388
}
342389
}
343390

391+
pub enum CC {
392+
CC0 = 0,
393+
CC1,
394+
CC2,
395+
CC3,
396+
CC4,
397+
CC5,
398+
}
399+
344400
impl Instance for TIMER0 {
345401
const INTERRUPT: Interrupt = Interrupt::TIMER0;
346402

0 commit comments

Comments
 (0)