Struct nrf52840_hal::Timer
source · pub struct Timer<T, U = OneShot>(/* private fields */);
Expand description
Interface to a TIMER instance.
Right now, this is a very basic interface. The timer will always be hardcoded to a frequency of 1 MHz and 32 bits accuracy.
CC[0] is used for the current/most-recent delay period and CC[1] is used to grab the current value of the counter at a given instant.
Implementations§
source§impl<T, U> Timer<T, U>where
T: Instance,
impl<T, U> Timer<T, U>where
T: Instance,
pub const TICKS_PER_SECOND: u32 = 1_000_000u32
pub fn into_periodic(self) -> Timer<T, Periodic>
pub fn into_oneshot(self) -> Timer<T>
sourcepub fn reset_event(&self)
pub fn reset_event(&self)
Reset the interrupt event flag
sourcepub fn enable_interrupt(&mut self)
pub fn enable_interrupt(&mut self)
Enables the interrupt for this timer.
Enables an interrupt that is fired when the timer reaches the value that
is given as an argument to start
.
Note that the interrupt also has to be unmasked in the NVIC, or the handler won’t get called.
sourcepub fn disable_interrupt(&mut self)
pub fn disable_interrupt(&mut self)
Disables the interrupt for this timer.
Disables an interrupt that is fired when the timer reaches the value
that is given as an argument to start
.
Note that the interrupt also has to be unmasked in the NVIC, or the handler won’t get called.
sourcepub fn start(&mut self, cycles: u32)
pub fn start(&mut self, cycles: u32)
Starts the timer.
The timer will run for the given number of cycles, then it will stop and reset.
sourcepub fn reset_if_finished(&mut self) -> bool
pub fn reset_if_finished(&mut self) -> bool
If the timer has finished, resets it and returns true.
Returns false if the timer is still running.
sourcepub fn delay(&mut self, cycles: u32)
pub fn delay(&mut self, cycles: u32)
Starts the timer for the given number of cycles and waits for it to finish.
sourcepub fn task_start(&self) -> &Reg<TASKS_START_SPEC>
pub fn task_start(&self) -> &Reg<TASKS_START_SPEC>
Returns reference to the START
task endpoint for PPI.
Starts timer.
sourcepub fn task_stop(&self) -> &Reg<TASKS_STOP_SPEC>
pub fn task_stop(&self) -> &Reg<TASKS_STOP_SPEC>
Returns reference to the STOP
task endpoint for PPI.
Stops timer.
sourcepub fn task_count(&self) -> &Reg<TASKS_COUNT_SPEC>
pub fn task_count(&self) -> &Reg<TASKS_COUNT_SPEC>
Returns reference to the COUNT
task endpoint for PPI.
Increments timer (counter mode only).
sourcepub fn task_clear(&self) -> &Reg<TASKS_CLEAR_SPEC>
pub fn task_clear(&self) -> &Reg<TASKS_CLEAR_SPEC>
Returns reference to the CLEAR
task endpoint for PPI.
Clears timer.
sourcepub fn task_capture_cc0(&self) -> &Reg<TASKS_CAPTURE_SPEC>
pub fn task_capture_cc0(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[0] CAPTURE
task endpoint for PPI.
Captures timer value to the CC[0] register.
sourcepub fn task_capture_cc1(&self) -> &Reg<TASKS_CAPTURE_SPEC>
pub fn task_capture_cc1(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[1] CAPTURE
task endpoint for PPI.
Captures timer value to the CC[1] register.
sourcepub fn task_capture_cc2(&self) -> &Reg<TASKS_CAPTURE_SPEC>
pub fn task_capture_cc2(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[2] CAPTURE
task endpoint for PPI.
Captures timer value to the CC[2] register.
sourcepub fn task_capture_cc3(&self) -> &Reg<TASKS_CAPTURE_SPEC>
pub fn task_capture_cc3(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[3] CAPTURE
task endpoint for PPI.
Captures timer value to the CC[3] register.
sourcepub fn event_compare_cc0(&self) -> &Reg<EVENTS_COMPARE_SPEC>
pub fn event_compare_cc0(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[0] COMPARE
event endpoint for PPI.
Generated when the counter is incremented and then matches the value
specified in the CC[0] register.
sourcepub fn event_compare_cc1(&self) -> &Reg<EVENTS_COMPARE_SPEC>
pub fn event_compare_cc1(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[1] COMPARE
event endpoint for PPI.
Generated when the counter is incremented and then matches the value
specified in the CC[1] register.
sourcepub fn event_compare_cc2(&self) -> &Reg<EVENTS_COMPARE_SPEC>
pub fn event_compare_cc2(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[2] COMPARE
event endpoint for PPI.
Generated when the counter is incremented and then matches the value
specified in the CC[2] register.
sourcepub fn event_compare_cc3(&self) -> &Reg<EVENTS_COMPARE_SPEC>
pub fn event_compare_cc3(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[3] COMPARE
event endpoint for PPI.
Generated when the counter is incremented and then matches the value
specified in the CC[3] register.
Trait Implementations§
source§impl<T, U> CountDown for Timer<T, U>where
T: Instance,
impl<T, U> CountDown for Timer<T, U>where
T: Instance,
source§fn start<Time>(&mut self, cycles: Time)
fn start<Time>(&mut self, cycles: Time)
Start the timer.
The timer will run for the given number of cycles, then it will stop and reset.
source§fn wait(&mut self) -> Result<(), Error<Void>>
fn wait(&mut self) -> Result<(), Error<Void>>
Wait for the timer to stop.
Will return Err(nb::Error::WouldBlock)
while the timer is still
running. Once the timer reached the number of cycles given in the
start
method, it will return Ok(())
.
To block until the timer has stopped, use the block!
macro from the
nb
crate. Please refer to the documentation of nb
for other options.
source§impl<T, U> DelayNs for Timer<T, U>where
T: Instance,
impl<T, U> DelayNs for Timer<T, U>where
T: Instance,
source§fn delay_ns(&mut self, ns: u32)
fn delay_ns(&mut self, ns: u32)
ns
nanoseconds. Pause can be longer
if the implementation requires it due to precision/timing issues.source§impl ExtendedCCTimer for Timer<TIMER3>
impl ExtendedCCTimer for Timer<TIMER3>
source§fn task_capture_cc4(&self) -> &Reg<TASKS_CAPTURE_SPEC>
fn task_capture_cc4(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[4] CAPTURE
task endpoint for PPI.
source§fn task_capture_cc5(&self) -> &Reg<TASKS_CAPTURE_SPEC>
fn task_capture_cc5(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[5] CAPTURE
task endpoint for PPI.
source§fn event_compare_cc4(&self) -> &Reg<EVENTS_COMPARE_SPEC>
fn event_compare_cc4(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[4] COMPARE
event endpoint for PPI.
source§fn event_compare_cc5(&self) -> &Reg<EVENTS_COMPARE_SPEC>
fn event_compare_cc5(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[5] COMPARE
event endpoint for PPI.
source§impl ExtendedCCTimer for Timer<TIMER4>
impl ExtendedCCTimer for Timer<TIMER4>
source§fn task_capture_cc4(&self) -> &Reg<TASKS_CAPTURE_SPEC>
fn task_capture_cc4(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[4] CAPTURE
task endpoint for PPI.
source§fn task_capture_cc5(&self) -> &Reg<TASKS_CAPTURE_SPEC>
fn task_capture_cc5(&self) -> &Reg<TASKS_CAPTURE_SPEC>
Returns reference to the CC[5] CAPTURE
task endpoint for PPI.
source§fn event_compare_cc4(&self) -> &Reg<EVENTS_COMPARE_SPEC>
fn event_compare_cc4(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[4] COMPARE
event endpoint for PPI.
source§fn event_compare_cc5(&self) -> &Reg<EVENTS_COMPARE_SPEC>
fn event_compare_cc5(&self) -> &Reg<EVENTS_COMPARE_SPEC>
Returns reference to the CC[5] COMPARE
event endpoint for PPI.