Timer

Struct Timer 

Source
pub struct Timer<TIM> { /* private fields */ }
Expand description

Timer wrapper

Implementations§

Source§

impl<TIM: Instance + Steal> Timer<TIM>

Source

pub fn new(tim: TIM, mcu: &mut Mcu) -> Self

Initialize timer

Source

pub fn counter<const FREQ: u32>(self) -> Counter<TIM, FREQ>

Non-blocking Counter with custom fixed precision

Source

pub fn counter_ms(self) -> CounterMs<TIM>

Non-blocking Counter with fixed precision of 1 ms (1 kHz sampling)

Can wait from 2 ms to 65 sec for 16-bit timer and from 2 ms to 49 days for 32-bit timer.

NOTE: don’t use this if your system frequency more than 65 MHz

Source

pub fn counter_us(self) -> CounterUs<TIM>

Non-blocking Counter with fixed precision of 1 μs (1 MHz sampling)

Can wait from 2 μs to 65 ms for 16-bit timer and from 2 μs to 71 min for 32-bit timer.

Source

pub fn counter_hz(self) -> CounterHz<TIM>

Non-blocking Counter with dynamic precision which uses Hertz as Duration units

Source

pub fn delay<const FREQ: u32>(self) -> Delay<TIM, FREQ>

Blocking Delay with custom fixed precision

Source

pub fn delay_ms(self) -> DelayMs<TIM>

Blocking Delay with fixed precision of 1 ms (1 kHz sampling)

Can wait from 2 ms to 49 days.

NOTE: don’t use this if your system frequency more than 65 MHz

Source

pub fn delay_us(self) -> DelayUs<TIM>

Blocking Delay with fixed precision of 1 μs (1 MHz sampling)

Can wait from 2 μs to 71 min.

Source

pub fn release(self) -> TIM

Source

pub fn listen(&mut self, event: Event)

Starts listening for an event

Note, you will also have to enable the TIM2 interrupt in the NVIC to start receiving events.

Source

pub fn clear_interrupt(&mut self, event: Event)

Clears interrupt associated with event.

If the interrupt is not cleared, it will immediately retrigger after the ISR has finished.

Source

pub fn get_interrupt(&mut self) -> Event

Source

pub fn unlisten(&mut self, event: Event)

Stops listening for an event

Source

pub fn stop_in_debug(&mut self, state: bool)

Stopping timer in debug mode can cause troubles when sampling the signal

Source§

impl<TIM: Instance + MasterTimer> Timer<TIM>

Source

pub fn set_master_mode(&mut self, mode: MasterMode)

Source§

impl<TIM: Instance + TimerDirection> Timer<TIM>

Source§

impl<'a, TIM: Instance + TimerWithPwm1Ch + Steal + 'a> Timer<TIM>

Source

pub fn into_pwm1<REMAP: RemapMode<TIM>>( self, _pin: impl TimCh1Pin<REMAP>, update_freq: Hertz, preload: bool, mcu: &mut Mcu, ) -> (PwmTimer<TIM>, impl PwmChannel + 'a)

Source§

impl<'a, TIM: Instance + TimerWithPwm2Ch + Steal + 'a> Timer<TIM>

Source

pub fn into_pwm2<REMAP: RemapMode<TIM>>( self, pins: (Option<impl TimCh1Pin<REMAP>>, Option<impl TimCh2Pin<REMAP>>), update_freq: Hertz, preload: bool, mcu: &mut Mcu, ) -> (PwmTimer<TIM>, Option<impl PwmChannel + 'a>, Option<impl PwmChannel + 'a>)

Source§

impl<'a, TIM: Instance + TimerWithPwm4Ch + Steal + 'a> Timer<TIM>

Source

pub fn into_pwm4<REMAP: RemapMode<TIM>>( self, pins: (Option<impl TimCh1Pin<REMAP>>, Option<impl TimCh2Pin<REMAP>>, Option<impl TimCh3Pin<REMAP>>, Option<impl TimCh4Pin<REMAP>>), update_freq: Hertz, preload: bool, mcu: &mut Mcu, ) -> (PwmTimer<TIM>, Option<impl PwmChannel + 'a>, Option<impl PwmChannel + 'a>, Option<impl PwmChannel + 'a>, Option<impl PwmChannel + 'a>)

Auto Trait Implementations§

§

impl<TIM> Freeze for Timer<TIM>
where TIM: Freeze,

§

impl<TIM> RefUnwindSafe for Timer<TIM>
where TIM: RefUnwindSafe,

§

impl<TIM> Send for Timer<TIM>
where TIM: Send,

§

impl<TIM> Sync for Timer<TIM>
where TIM: Sync,

§

impl<TIM> Unpin for Timer<TIM>
where TIM: Unpin,

§

impl<TIM> UnwindSafe for Timer<TIM>
where TIM: 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> 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<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<T, const R: u8> RFrom<T, R> for T

Source§

fn rfrom(value: T) -> T

Source§

impl<S, T, const R: u8> RInto<T, R> for S
where T: RFrom<S, R>,

Source§

fn rinto(self) -> T

Source§

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

Source§

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>,

Source§

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.