Skip to content

Commit 8d49b5e

Browse files
committed
Change task_capture and event_compare to separate functions per CC
1 parent 4d49de4 commit 8d49b5e

File tree

1 file changed

+122
-19
lines changed

1 file changed

+122
-19
lines changed

nrf-hal-common/src/timer.rs

Lines changed: 122 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ use crate::pac::{TIMER3, TIMER4};
3535

3636
// The 832 and 840 expose TIMER3 and TIMER for as timer3::RegisterBlock...
3737
#[cfg(any(feature = "52832", feature = "52840"))]
38-
use crate::pac::timer3::RegisterBlock as RegBlock3;
38+
use crate::pac::timer3::{
39+
RegisterBlock as RegBlock3, _EVENTS_COMPARE as EventsCompare3, _TASKS_CAPTURE as TasksCapture3,
40+
};
3941

4042
// ...but the 833 exposes them as timer0::RegisterBlock. This might be a bug
4143
// in the PAC, and could be fixed later. For now, it is equivalent anyway.
4244
#[cfg(feature = "52833")]
43-
use crate::pac::timer0::RegisterBlock as RegBlock3;
45+
use crate::pac::timer0::{
46+
RegisterBlock as RegBlock3, _EVENTS_COMPARE as EventsCompare3, _TASKS_CAPTURE as TasksCapture3,
47+
};
4448

4549
use core::marker::PhantomData;
4650

@@ -174,19 +178,64 @@ where
174178
&self.0.as_timer0().tasks_clear
175179
}
176180

177-
/// Returns reference to the `CAPTURE` task endpoint for PPI.
178-
/// Captures timer value to the given CC register.
181+
/// Returns reference to the CC[0] `CAPTURE` task endpoint for PPI.
182+
/// Captures timer value to the CC[0] register.
183+
#[inline(always)]
184+
pub fn task_capture_cc0(&self) -> &Reg<u32, _TASKS_CAPTURE> {
185+
&self.0.as_timer0().tasks_capture[0]
186+
}
187+
188+
/// Returns reference to the CC[1] `CAPTURE` task endpoint for PPI.
189+
/// Captures timer value to the CC[1] register.
190+
#[inline(always)]
191+
pub fn task_capture_cc1(&self) -> &Reg<u32, _TASKS_CAPTURE> {
192+
&self.0.as_timer0().tasks_capture[1]
193+
}
194+
195+
/// Returns reference to the CC[2] `CAPTURE` task endpoint for PPI.
196+
/// Captures timer value to the CC[2] register.
197+
#[inline(always)]
198+
pub fn task_capture_cc2(&self) -> &Reg<u32, _TASKS_CAPTURE> {
199+
&self.0.as_timer0().tasks_capture[2]
200+
}
201+
202+
/// Returns reference to the CC[3] `CAPTURE` task endpoint for PPI.
203+
/// Captures timer value to the CC[3] register.
204+
#[inline(always)]
205+
pub fn task_capture_cc3(&self) -> &Reg<u32, _TASKS_CAPTURE> {
206+
&self.0.as_timer0().tasks_capture[3]
207+
}
208+
209+
/// Returns reference to the CC[0] `COMPARE` event endpoint for PPI.
210+
/// Generated when the counter is incremented and then matches the value
211+
/// specified in the CC[0] register.
212+
#[inline(always)]
213+
pub fn event_compare_cc0(&self) -> &Reg<u32, _EVENTS_COMPARE> {
214+
&self.0.as_timer0().events_compare[0]
215+
}
216+
217+
/// Returns reference to the CC[1] `COMPARE` event endpoint for PPI.
218+
/// Generated when the counter is incremented and then matches the value
219+
/// specified in the CC[1] register.
220+
#[inline(always)]
221+
pub fn event_compare_cc1(&self) -> &Reg<u32, _EVENTS_COMPARE> {
222+
&self.0.as_timer0().events_compare[1]
223+
}
224+
225+
/// Returns reference to the CC[2] `COMPARE` event endpoint for PPI.
226+
/// Generated when the counter is incremented and then matches the value
227+
/// specified in the CC[2] register.
179228
#[inline(always)]
180-
pub fn task_capture(&self, cc: CC) -> &Reg<u32, _TASKS_CAPTURE> {
181-
&self.0.as_timer0().tasks_capture[cc as usize]
229+
pub fn event_compare_cc2(&self) -> &Reg<u32, _EVENTS_COMPARE> {
230+
&self.0.as_timer0().events_compare[2]
182231
}
183232

184-
/// Returns reference to `COMPARE` event endpoint for PPI.
233+
/// Returns reference to the CC[3] `COMPARE` event endpoint for PPI.
185234
/// Generated when the counter is incremented and then matches the value
186-
/// specified in the given CC register
235+
/// specified in the CC[3] register.
187236
#[inline(always)]
188-
pub fn event_compare(&self, cc: CC) -> &Reg<u32, _EVENTS_COMPARE> {
189-
&self.0.as_timer0().events_compare[cc as usize]
237+
pub fn event_compare_cc3(&self) -> &Reg<u32, _EVENTS_COMPARE> {
238+
&self.0.as_timer0().events_compare[3]
190239
}
191240
}
192241

@@ -394,15 +443,6 @@ pub trait Instance: sealed::Sealed {
394443
}
395444
}
396445

397-
pub enum CC {
398-
CC0 = 0,
399-
CC1,
400-
CC2,
401-
CC3,
402-
CC4,
403-
CC5,
404-
}
405-
406446
impl Instance for TIMER0 {
407447
const INTERRUPT: Interrupt = Interrupt::TIMER0;
408448

@@ -462,6 +502,69 @@ impl Instance for TIMER4 {
462502
}
463503
}
464504

505+
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
506+
/// Adds task- and event PPI endpoint getters for CC[4] and CC[5] on supported instances.
507+
pub trait ExtendedCCTimer {
508+
fn task_capture_cc4(&self) -> &Reg<u32, TasksCapture3>;
509+
fn task_capture_cc5(&self) -> &Reg<u32, TasksCapture3>;
510+
fn event_compare_cc4(&self) -> &Reg<u32, EventsCompare3>;
511+
fn event_compare_cc5(&self) -> &Reg<u32, EventsCompare3>;
512+
}
513+
514+
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
515+
impl ExtendedCCTimer for Timer<TIMER3> {
516+
/// Returns reference to the CC[4] `CAPTURE` task endpoint for PPI.
517+
#[inline(always)]
518+
fn task_capture_cc4(&self) -> &Reg<u32, TasksCapture3> {
519+
&self.0.tasks_capture[4]
520+
}
521+
522+
/// Returns reference to the CC[5] `CAPTURE` task endpoint for PPI.
523+
#[inline(always)]
524+
fn task_capture_cc5(&self) -> &Reg<u32, TasksCapture3> {
525+
&self.0.tasks_capture[5]
526+
}
527+
528+
/// Returns reference to the CC[4] `COMPARE` event endpoint for PPI.
529+
#[inline(always)]
530+
fn event_compare_cc4(&self) -> &Reg<u32, EventsCompare3> {
531+
&self.0.events_compare[4]
532+
}
533+
534+
/// Returns reference to the CC[5] `COMPARE` event endpoint for PPI.
535+
#[inline(always)]
536+
fn event_compare_cc5(&self) -> &Reg<u32, EventsCompare3> {
537+
&self.0.events_compare[5]
538+
}
539+
}
540+
541+
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
542+
impl ExtendedCCTimer for Timer<TIMER4> {
543+
/// Returns reference to the CC[4] `CAPTURE` task endpoint for PPI.
544+
#[inline(always)]
545+
fn task_capture_cc4(&self) -> &Reg<u32, TasksCapture3> {
546+
&self.0.tasks_capture[4]
547+
}
548+
549+
/// Returns reference to the CC[5] `CAPTURE` task endpoint for PPI.
550+
#[inline(always)]
551+
fn task_capture_cc5(&self) -> &Reg<u32, TasksCapture3> {
552+
&self.0.tasks_capture[5]
553+
}
554+
555+
/// Returns reference to the CC[4] `COMPARE` event endpoint for PPI.
556+
#[inline(always)]
557+
fn event_compare_cc4(&self) -> &Reg<u32, EventsCompare3> {
558+
&self.0.events_compare[4]
559+
}
560+
561+
/// Returns reference to the CC[5] `COMPARE` event endpoint for PPI.
562+
#[inline(always)]
563+
fn event_compare_cc5(&self) -> &Reg<u32, EventsCompare3> {
564+
&self.0.events_compare[5]
565+
}
566+
}
567+
465568
mod sealed {
466569
pub trait Sealed {}
467570
impl Sealed for super::TIMER0 {}

0 commit comments

Comments
 (0)