Struct esp32_simple::clock::Timer

source ·
pub struct Timer<'a, T: Trigger> { /* private fields */ }
Expand description

Represents a timer that can be used for various operations.

§Type Parameters

  • 'a - Lifetime of the timer.
  • T - The trigger type implementing the Trigger trait.

Implementations§

source§

impl<'a, T: Trigger> Timer<'a, T>

source

pub fn new(timer: TimerDriver<'a>) -> Result<Self>

Creates a new Timer instance.

§Arguments
  • timer - A timer driver instance.
§Returns

A new Timer instance.

§Errors

Returns an error if the timer cannot be initialized.

source

pub fn configure_interrupt( &mut self, freq: u64, notifier: Notifier<T>, trigger: &'static T, ) -> Result<()>

Configures the timer interrupt.

§Arguments
  • freq - Frequency of the timer interrupt in Hz.
  • notifier - A notifier to send timer tick events.
  • trigger - The trigger to emit when the timer ticks.
§Returns

Ok(()) on success.

§Errors

Returns an error if the interrupt cannot be configured.

source

pub fn on(&mut self) -> Result<()>

Turns on the timer.

§Returns

Ok(()) on success.

§Errors

Returns an error if the timer cannot be turned on.

source

pub fn off(&mut self) -> Result<()>

Turns off the timer.

§Returns

Ok(()) on success.

§Errors

Returns an error if the timer cannot be turned off.

source

pub async fn delay(&mut self, freq: u64) -> Result<()>

Delays execution for a period determined by the given frequency.

The delay duration is 1 / freq seconds (i.e., one period of the frequency).

§Arguments
  • freq - Frequency in Hz; the delay lasts one period of this frequency.
§Returns

Ok(()) when the delay completes.

§Errors

Returns an error if the delay cannot be performed.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Timer<'a, T>

§

impl<'a, T> RefUnwindSafe for Timer<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Timer<'a, T>

§

impl<'a, T> Sync for Timer<'a, T>

§

impl<'a, T> Unpin for Timer<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for Timer<'a, T>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.