pub struct Timer<'d, T: CoreInstance> { /* private fields */ }
Expand description
Low-level timer driver.
Implementations§
source§impl<'d, T: CoreInstance> Timer<'d, T>
impl<'d, T: CoreInstance> Timer<'d, T>
sourcepub fn new(tim: impl Peripheral<P = T> + 'd) -> Self
pub fn new(tim: impl Peripheral<P = T> + 'd) -> Self
Create a new timer driver.
sourcepub fn regs_core(&self) -> TimCore
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.
sourcepub fn set_frequency(&self, frequency: Hertz)
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.
sourcepub fn set_tick_freq(&mut self, freq: Hertz)
pub fn set_tick_freq(&mut self, freq: Hertz)
Set tick frequency.
sourcepub fn clear_update_interrupt(&self) -> bool
pub fn clear_update_interrupt(&self) -> bool
Clear update interrupt.
Returns whether the update interrupt flag was set.
sourcepub fn enable_update_interrupt(&self, enable: bool)
pub fn enable_update_interrupt(&self, enable: bool)
Enable/disable the update interrupt.
sourcepub fn set_autoreload_preload(&self, enable: bool)
pub fn set_autoreload_preload(&self, enable: bool)
Enable/disable autoreload preload.
sourcepub fn get_frequency(&self) -> Hertz
pub fn get_frequency(&self) -> Hertz
Get the timer frequency.
sourcepub fn get_clock_frequency(&self) -> Hertz
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>
impl<'d, T: BasicNoCr2Instance> Timer<'d, T>
sourcepub fn regs_basic_no_cr2(&self) -> TimBasicNoCr2
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.
sourcepub fn enable_update_dma(&self, enable: bool)
pub fn enable_update_dma(&self, enable: bool)
Enable/disable the update dma.
sourcepub fn get_update_dma_state(&self) -> bool
pub fn get_update_dma_state(&self) -> bool
Get the update dma enable/disable state.
source§impl<'d, T: BasicInstance> Timer<'d, T>
impl<'d, T: BasicInstance> Timer<'d, T>
sourcepub fn regs_basic(&self) -> TimBasic
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>
impl<'d, T: GeneralInstance1Channel> Timer<'d, T>
sourcepub fn regs_1ch(&self) -> Tim1ch
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.
sourcepub fn set_clock_division(&self, ckd: Ckd)
pub fn set_clock_division(&self, ckd: Ckd)
Set clock divider.
sourcepub fn get_max_compare_value(&self) -> u32
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>
impl<'d, T: GeneralInstance2Channel> Timer<'d, T>
sourcepub fn regs_2ch(&self) -> Tim2ch
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>
impl<'d, T: GeneralInstance4Channel> Timer<'d, T>
sourcepub fn regs_gp16(&self) -> TimGp16
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.
sourcepub fn enable_outputs(&self)
pub fn enable_outputs(&self)
Enable timer outputs.
sourcepub fn set_counting_mode(&self, mode: CountingMode)
pub fn set_counting_mode(&self, mode: CountingMode)
Set counting mode.
sourcepub fn get_counting_mode(&self) -> CountingMode
pub fn get_counting_mode(&self) -> CountingMode
Get counting mode.
sourcepub fn set_input_capture_filter(&self, channel: Channel, icf: FilterValue)
pub fn set_input_capture_filter(&self, channel: Channel, icf: FilterValue)
Set input capture filter.
sourcepub fn clear_input_interrupt(&self, channel: Channel)
pub fn clear_input_interrupt(&self, channel: Channel)
Clear input interrupt.
sourcepub fn get_input_interrupt(&self, channel: Channel) -> bool
pub fn get_input_interrupt(&self, channel: Channel) -> bool
Get input interrupt.
sourcepub fn enable_input_interrupt(&self, channel: Channel, enable: bool)
pub fn enable_input_interrupt(&self, channel: Channel, enable: bool)
Enable input interrupt.
sourcepub fn set_input_capture_prescaler(&self, channel: Channel, factor: u8)
pub fn set_input_capture_prescaler(&self, channel: Channel, factor: u8)
Set input capture prescaler.
sourcepub fn set_input_ti_selection(&self, channel: Channel, tisel: InputTISelection)
pub fn set_input_ti_selection(&self, channel: Channel, tisel: InputTISelection)
Set input TI selection.
sourcepub fn set_input_capture_mode(&self, channel: Channel, mode: InputCaptureMode)
pub fn set_input_capture_mode(&self, channel: Channel, mode: InputCaptureMode)
Set input capture mode.
sourcepub fn set_output_compare_mode(&self, channel: Channel, mode: OutputCompareMode)
pub fn set_output_compare_mode(&self, channel: Channel, mode: OutputCompareMode)
Set output compare mode.
sourcepub fn set_output_polarity(&self, channel: Channel, polarity: OutputPolarity)
pub fn set_output_polarity(&self, channel: Channel, polarity: OutputPolarity)
Set output polarity.
sourcepub fn enable_channel(&self, channel: Channel, enable: bool)
pub fn enable_channel(&self, channel: Channel, enable: bool)
Enable/disable a channel.
sourcepub fn get_channel_enable_state(&self, channel: Channel) -> bool
pub fn get_channel_enable_state(&self, channel: Channel) -> bool
Get enable/disable state of a channel
sourcepub fn set_compare_value(&self, channel: Channel, value: u32)
pub fn set_compare_value(&self, channel: Channel, value: u32)
Set compare value for a channel.
sourcepub fn get_compare_value(&self, channel: Channel) -> u32
pub fn get_compare_value(&self, channel: Channel) -> u32
Get compare value for a channel.
sourcepub fn get_capture_value(&self, channel: Channel) -> u32
pub fn get_capture_value(&self, channel: Channel) -> u32
Get capture value for a channel.
sourcepub fn set_output_compare_preload(&self, channel: Channel, preload: bool)
pub fn set_output_compare_preload(&self, channel: Channel, preload: bool)
Set output compare preload.
sourcepub fn get_cc_dma_selection(&self) -> Ccds
pub fn get_cc_dma_selection(&self) -> Ccds
Get capture compare DMA selection
sourcepub fn set_cc_dma_selection(&self, ccds: Ccds)
pub fn set_cc_dma_selection(&self, ccds: Ccds)
Set capture compare DMA selection
sourcepub fn get_cc_dma_enable_state(&self, channel: Channel) -> bool
pub fn get_cc_dma_enable_state(&self, channel: Channel) -> bool
Get capture compare DMA enable state
sourcepub fn set_cc_dma_enable_state(&self, channel: Channel, ccde: bool)
pub fn set_cc_dma_enable_state(&self, channel: Channel, ccde: bool)
Set capture compare DMA enable state
sourcepub fn set_slave_mode(&self, sms: SlaveMode)
pub fn set_slave_mode(&self, sms: SlaveMode)
Set Timer Slave Mode
sourcepub fn set_trigger_source(&self, ts: TriggerSource)
pub fn set_trigger_source(&self, ts: TriggerSource)
Set Timer Trigger Source
source§impl<'d, T: GeneralInstance32bit4Channel> Timer<'d, T>
impl<'d, T: GeneralInstance32bit4Channel> Timer<'d, T>
sourcepub fn regs_gp32(&self) -> TimGp32
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>
impl<'d, T: AdvancedInstance1Channel> Timer<'d, T>
sourcepub fn regs_1ch_cmp(&self) -> Tim1chCmp
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.
sourcepub fn set_dead_time_clock_division(&self, value: Ckd)
pub fn set_dead_time_clock_division(&self, value: Ckd)
Set clock divider for the dead time.
sourcepub fn set_dead_time_value(&self, value: u8)
pub fn set_dead_time_value(&self, value: u8)
Set dead time, as a fraction of the max duty value.
source§impl<'d, T: AdvancedInstance2Channel> Timer<'d, T>
impl<'d, T: AdvancedInstance2Channel> Timer<'d, T>
sourcepub fn regs_2ch_cmp(&self) -> Tim2chCmp
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>
impl<'d, T: AdvancedInstance4Channel> Timer<'d, T>
sourcepub fn regs_advanced(&self) -> TimAdv
pub fn regs_advanced(&self) -> TimAdv
Get access to the advanced timer registers.
sourcepub fn set_complementary_output_polarity(
&self,
channel: Channel,
polarity: OutputPolarity,
)
pub fn set_complementary_output_polarity( &self, channel: Channel, polarity: OutputPolarity, )
Set complementary output polarity.
sourcepub fn enable_complementary_channel(&self, channel: Channel, enable: bool)
pub fn enable_complementary_channel(&self, channel: Channel, enable: bool)
Enable/disable a complementary channel.