Struct nrf52811_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> Timer<T>
where T: Instance,

source

pub fn one_shot(timer: T) -> Timer<T>

source

pub fn new(timer: T) -> Timer<T>

source§

impl<T> Timer<T, Periodic>
where T: Instance,

source

pub fn periodic(timer: T) -> Timer<T, Periodic>

source§

impl<T, U> Timer<T, U>
where T: Instance,

source

pub const TICKS_PER_SECOND: u32 = 1_000_000u32

source

pub fn into_periodic(self) -> Timer<T, Periodic>

source

pub fn into_oneshot(self) -> Timer<T>

source

pub fn free(self) -> T

Return the raw interface to the underlying timer peripheral.

source

pub fn read(&self) -> u32

Return the current value of the counter, by capturing to CC[1].

source

pub fn reset_event(&self)

Reset the interrupt event flag

source

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.

source

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.

source

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.

source

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.

source

pub fn delay(&mut self, cycles: u32)

Starts the timer for the given number of cycles and waits for it to finish.

source

pub fn task_start(&self) -> &Reg<TASKS_START_SPEC>

Returns reference to the START task endpoint for PPI. Starts timer.

source

pub fn task_stop(&self) -> &Reg<TASKS_STOP_SPEC>

Returns reference to the STOP task endpoint for PPI. Stops timer.

source

pub fn task_count(&self) -> &Reg<TASKS_COUNT_SPEC>

Returns reference to the COUNT task endpoint for PPI. Increments timer (counter mode only).

source

pub fn task_clear(&self) -> &Reg<TASKS_CLEAR_SPEC>

Returns reference to the CLEAR task endpoint for PPI. Clears timer.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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> Cancel for Timer<T, U>
where T: Instance,

§

type Error = ()

Error returned when a countdown can’t be canceled.
source§

fn cancel(&mut self) -> Result<(), <Timer<T, U> as Cancel>::Error>

Tries to cancel this countdown. Read more
source§

impl<T, U> CountDown for Timer<T, U>
where T: Instance,

source§

fn start<Time>(&mut self, cycles: Time)
where Time: Into<<Timer<T, U> as CountDown>::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>>

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.

§

type Time = u32

The unit of time used by this timer
source§

impl<T, U> DelayMs<u16> for Timer<T, U>
where T: Instance,

source§

fn delay_ms(&mut self, ms: u16)

Pauses execution for ms milliseconds
source§

impl<T, U> DelayMs<u32> for Timer<T, U>
where T: Instance,

source§

fn delay_ms(&mut self, ms: u32)

Pauses execution for ms milliseconds
source§

impl<T, U> DelayMs<u8> for Timer<T, U>
where T: Instance,

source§

fn delay_ms(&mut self, ms: u8)

Pauses execution for ms milliseconds
source§

impl<T, U> DelayNs for Timer<T, U>
where T: Instance,

source§

fn delay_ns(&mut self, ns: u32)

Pauses execution for at minimum ns nanoseconds. Pause can be longer if the implementation requires it due to precision/timing issues.
source§

fn delay_us(&mut self, us: u32)

Pauses execution for at minimum us microseconds. Pause can be longer if the implementation requires it due to precision/timing issues.
source§

fn delay_ms(&mut self, ms: u32)

Pauses execution for at minimum ms milliseconds. Pause can be longer if the implementation requires it due to precision/timing issues.
source§

impl<T, U> DelayUs<u16> for Timer<T, U>
where T: Instance,

source§

fn delay_us(&mut self, us: u16)

Pauses execution for us microseconds
source§

impl<T, U> DelayUs<u32> for Timer<T, U>
where T: Instance,

source§

fn delay_us(&mut self, us: u32)

Pauses execution for us microseconds
source§

impl<T, U> DelayUs<u8> for Timer<T, U>
where T: Instance,

source§

fn delay_us(&mut self, us: u8)

Pauses execution for us microseconds
source§

impl<T> Periodic for Timer<T, Periodic>
where T: Instance,

Auto Trait Implementations§

§

impl<T, U> Freeze for Timer<T, U>
where T: Freeze,

§

impl<T, U> RefUnwindSafe for Timer<T, U>

§

impl<T, U> Send for Timer<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for Timer<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for Timer<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnwindSafe for Timer<T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.