embassy-stm32

Crates

git

Versions

stm32u073hb

Flavors

embassy_stm32::timer::low_level

Struct Timer

Source
pub struct Timer<'d, T: CoreInstance> { /* private fields */ }
Expand description

Low-level timer driver.

Implementations§

Source§

impl<'d, T: CoreInstance> Timer<'d, T>

Source

pub fn new(tim: impl Peripheral<P = T> + 'd) -> Self

Create a new timer driver.

Source

pub fn regs_core(&self) -> TimCore

Get access to the virutal core 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source

pub fn start(&self)

Start the timer.

Source

pub fn stop(&self)

Stop the timer.

Source

pub fn reset(&self)

Reset the counter value to 0

Source

pub fn set_frequency(&self, frequency: Hertz)

Set the frequency of how many times per second the timer counts up to the max value or down to 0.

This means that in the default edge-aligned mode, the timer counter will wrap around at the same frequency as is being set. In center-aligned mode (which not all timers support), the wrap-around frequency is effectively halved because it needs to count up and down.

Source

pub fn set_tick_freq(&mut self, freq: Hertz)

Set tick frequency.

Source

pub fn clear_update_interrupt(&self) -> bool

Clear update interrupt.

Returns whether the update interrupt flag was set.

Source

pub fn enable_update_interrupt(&self, enable: bool)

Enable/disable the update interrupt.

Source

pub fn set_autoreload_preload(&self, enable: bool)

Enable/disable autoreload preload.

Source

pub fn get_frequency(&self) -> Hertz

Get the timer frequency.

Source

pub fn get_clock_frequency(&self) -> Hertz

Get the clock frequency of the timer (before prescaler is applied).

Source§

impl<'d, T: BasicNoCr2Instance> Timer<'d, T>

Source

pub fn regs_basic_no_cr2(&self) -> TimBasicNoCr2

Get access to the Baisc 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source

pub fn enable_update_dma(&self, enable: bool)

Enable/disable the update dma.

Source

pub fn get_update_dma_state(&self) -> bool

Get the update dma enable/disable state.

Source§

impl<'d, T: BasicInstance> Timer<'d, T>

Source

pub fn regs_basic(&self) -> TimBasic

Get access to the Baisc 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source§

impl<'d, T: GeneralInstance1Channel> Timer<'d, T>

Source

pub fn regs_1ch(&self) -> Tim1ch

Get access to the general purpose 1 channel 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source

pub fn set_clock_division(&self, ckd: Ckd)

Set clock divider.

Source

pub fn get_max_compare_value(&self) -> u32

Get max compare value. This depends on the timer frequency and the clock frequency from RCC.

Source§

impl<'d, T: GeneralInstance2Channel> Timer<'d, T>

Source

pub fn regs_2ch(&self) -> Tim2ch

Get access to the general purpose 2 channel 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source§

impl<'d, T: GeneralInstance4Channel> Timer<'d, T>

Source

pub fn regs_gp16(&self) -> TimGp16

Get access to the general purpose 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source

pub fn enable_outputs(&self)

Enable timer outputs.

Source

pub fn set_counting_mode(&self, mode: CountingMode)

Set counting mode.

Source

pub fn get_counting_mode(&self) -> CountingMode

Get counting mode.

Source

pub fn set_input_capture_filter(&self, channel: Channel, icf: FilterValue)

Set input capture filter.

Source

pub fn clear_input_interrupt(&self, channel: Channel)

Clear input interrupt.

Source

pub fn get_input_interrupt(&self, channel: Channel) -> bool

Get input interrupt.

Source

pub fn enable_input_interrupt(&self, channel: Channel, enable: bool)

Enable input interrupt.

Source

pub fn set_input_capture_prescaler(&self, channel: Channel, factor: u8)

Set input capture prescaler.

Source

pub fn set_input_ti_selection(&self, channel: Channel, tisel: InputTISelection)

Set input TI selection.

Source

pub fn set_input_capture_mode(&self, channel: Channel, mode: InputCaptureMode)

Set input capture mode.

Source

pub fn set_output_compare_mode(&self, channel: Channel, mode: OutputCompareMode)

Set output compare mode.

Source

pub fn set_output_polarity(&self, channel: Channel, polarity: OutputPolarity)

Set output polarity.

Source

pub fn enable_channel(&self, channel: Channel, enable: bool)

Enable/disable a channel.

Source

pub fn get_channel_enable_state(&self, channel: Channel) -> bool

Get enable/disable state of a channel

Source

pub fn set_compare_value(&self, channel: Channel, value: u32)

Set compare value for a channel.

Source

pub fn get_compare_value(&self, channel: Channel) -> u32

Get compare value for a channel.

Source

pub fn get_capture_value(&self, channel: Channel) -> u32

Get capture value for a channel.

Source

pub fn set_output_compare_preload(&self, channel: Channel, preload: bool)

Set output compare preload.

Source

pub fn get_cc_dma_selection(&self) -> Ccds

Get capture compare DMA selection

Source

pub fn set_cc_dma_selection(&self, ccds: Ccds)

Set capture compare DMA selection

Source

pub fn get_cc_dma_enable_state(&self, channel: Channel) -> bool

Get capture compare DMA enable state

Source

pub fn set_cc_dma_enable_state(&self, channel: Channel, ccde: bool)

Set capture compare DMA enable state

Source

pub fn set_slave_mode(&self, sms: SlaveMode)

Set Timer Slave Mode

Source

pub fn set_trigger_source(&self, ts: TriggerSource)

Set Timer Trigger Source

Source§

impl<'d, T: GeneralInstance32bit4Channel> Timer<'d, T>

Source

pub fn regs_gp32(&self) -> TimGp32

Get access to the general purpose 32bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source§

impl<'d, T: AdvancedInstance1Channel> Timer<'d, T>

Source

pub fn regs_1ch_cmp(&self) -> Tim1chCmp

Get access to the general purpose 1 channel with one complementary 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source

pub fn set_dead_time_clock_division(&self, value: Ckd)

Set clock divider for the dead time.

Source

pub fn set_dead_time_value(&self, value: u8)

Set dead time, as a fraction of the max duty value.

Source

pub fn set_moe(&self, enable: bool)

Set state of MOE-bit in BDTR register to en-/disable output

Source§

impl<'d, T: AdvancedInstance2Channel> Timer<'d, T>

Source

pub fn regs_2ch_cmp(&self) -> Tim2chCmp

Get access to the general purpose 2 channel with one complementary 16bit timer registers.

Note: This works even if the timer is more capable, because registers for the less capable timers are a subset. This allows writing a driver for a given set of capabilities, and having it transparently work with more capable timers.

Source§

impl<'d, T: AdvancedInstance4Channel> Timer<'d, T>

Source

pub fn regs_advanced(&self) -> TimAdv

Get access to the advanced timer registers.

Source

pub fn set_complementary_output_polarity( &self, channel: Channel, polarity: OutputPolarity, )

Set complementary output polarity.

Source

pub fn enable_complementary_channel(&self, channel: Channel, enable: bool)

Enable/disable a complementary channel.

Trait Implementations§

Source§

impl<'d, T: CoreInstance> Drop for Timer<'d, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'d, T> Freeze for Timer<'d, T>
where T: Freeze,

§

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

§

impl<'d, T> Send for Timer<'d, T>
where T: Send,

§

impl<'d, T> Sync for Timer<'d, T>
where T: Sync,

§

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

§

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

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