embassy-stm32

Crates

git

Versions

stm32h533he

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.