Skip to content

Commit 8cdcca7

Browse files
committed
Documenation for Timer Instance
1 parent 663008c commit 8cdcca7

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

nrf-hal-common/src/timer.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,10 @@ pub trait Instance: sealed::Sealed {
353353
/// This interrupt associated with this RTC instance.
354354
const INTERRUPT: Interrupt;
355355

356+
/// Return the correct register block
356357
fn as_timer0(&self) -> &RegBlock0;
357358

359+
/// Starts the timer after clearing the counter register and setting the events compare trigger correctly to the numer of `cycles`
358360
fn timer_start<Time>(&self, cycles: Time)
359361
where
360362
Time: Into<u32>,
@@ -369,7 +371,7 @@ pub trait Instance: sealed::Sealed {
369371
// nothing else this method does will reset the event, and if it's still
370372
// active after this method exits, then the next call to `wait` will
371373
// return immediately, no matter how much time has actually passed.
372-
self.as_timer0().events_compare[0].reset();
374+
self.timer_reset_event();
373375

374376
// Configure timer to trigger EVENTS_COMPARE when given number of cycles
375377
// is reached.
@@ -389,46 +391,56 @@ pub trait Instance: sealed::Sealed {
389391
self.as_timer0().tasks_start.write(|w| unsafe { w.bits(1) });
390392
}
391393

394+
/// Reset event for CC[0] register
392395
fn timer_reset_event(&self) {
393-
self.as_timer0().events_compare[0].write(|w| w);
396+
self.as_timer0().events_compare[0].reset();
394397
}
395398

399+
/// Cancel timer by setting it to stop mode and resetting the events
396400
fn timer_cancel(&self) {
397401
self.as_timer0().tasks_stop.write(|w| unsafe { w.bits(1) });
398402
self.timer_reset_event();
399403
}
400404

405+
/// Checks if the timer is still running which means no event is yet generated for CC[0]
401406
fn timer_running(&self) -> bool {
402407
self.as_timer0().events_compare[0].read().bits() == 0
403408
}
404409

410+
///
405411
fn read_counter(&self) -> u32 {
406412
self.as_timer0().tasks_capture[1].write(|w| unsafe { w.bits(1) });
407413
self.as_timer0().cc[1].read().bits()
408414
}
409415

416+
/// Disable interrupt for event COMPARE[0] by default
410417
fn disable_interrupt(&self) {
411418
self.as_timer0()
412419
.intenclr
413420
.modify(|_, w| w.compare0().clear());
414421
}
415422

423+
/// Enable interrupt for event COMPARE[0] by default
416424
fn enable_interrupt(&self) {
417425
self.as_timer0().intenset.modify(|_, w| w.compare0().set());
418426
}
419427

428+
/// Set timer into periodic mode
420429
fn set_shorts_periodic(&self) {
421430
self.as_timer0()
422431
.shorts
423432
.write(|w| w.compare0_clear().enabled().compare0_stop().disabled());
424433
}
425434

435+
/// Set timer into oneshot mode
426436
fn set_shorts_oneshot(&self) {
427437
self.as_timer0()
428438
.shorts
429439
.write(|w| w.compare0_clear().enabled().compare0_stop().enabled());
430440
}
431441

442+
/// Set up timer for 1 MHz prescaled periods with 32 bits accuracy
443+
/// Only safe to call when the timer is stopped
432444
fn set_periodic(&self) {
433445
self.set_shorts_periodic();
434446
self.as_timer0().prescaler.write(
@@ -437,6 +449,8 @@ pub trait Instance: sealed::Sealed {
437449
self.as_timer0().bitmode.write(|w| w.bitmode()._32bit());
438450
}
439451

452+
/// Set up timer for a 1 MHz prescaled oneshot with 32 bits accuracy
453+
/// Only safe to call when the timer is stopped
440454
fn set_oneshot(&self) {
441455
self.set_shorts_oneshot();
442456
self.as_timer0().prescaler.write(

0 commit comments

Comments
 (0)