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