Struct stm32_hal2::timer::Timer
source · [−]pub struct Timer<TIM> {
pub regs: TIM,
pub cfg: TimerConfig,
/* private fields */
}
Expand description
Represents a General Purpose or Advanced Control timer.
Fields
regs: TIM
cfg: TimerConfig
Implementations
sourceimpl Timer<TIM1>
impl Timer<TIM1>
sourcepub fn new_tim1(
regs: TIM1,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim1(
regs: TIM1,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u16
pub fn get_max_duty(&self) -> u16
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM1>
impl Timer<TIM1>
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u16
pub fn get_duty(&self, channel: TimChannel) -> u16
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u16)
pub fn set_duty(&mut self, channel: TimChannel, duty: u16)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
sourceimpl Timer<TIM2>
impl Timer<TIM2>
sourcepub fn new_tim2(
regs: TIM2,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim2(
regs: TIM2,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u32
pub fn get_max_duty(&self) -> u32
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM2>
impl Timer<TIM2>
sourcepub fn set_dir(&mut self)
pub fn set_dir(&mut self)
Function that allows us to set direction only on timers that have this option.
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u32
pub fn get_duty(&self, channel: TimChannel) -> u32
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u32)
pub fn set_duty(&mut self, channel: TimChannel, duty: u32)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_alignment(&mut self, alignment: Alignment)
Set timer alignment to Edge, or one of 3 center modes. STM32F303 ref man, section 21.4.1: Bits 6:5 CMS: Center-aligned mode selection 00: Edge-aligned mode. The counter counts up or down depending on the direction bit (DIR). 01: Center-aligned mode 1. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting down. 10: Center-aligned mode 2. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting up. 11: Center-aligned mode 3. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set both when the counter is counting up or down.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
sourceimpl Timer<TIM3>
impl Timer<TIM3>
sourcepub fn new_tim3(
regs: TIM3,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim3(
regs: TIM3,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u32
pub fn get_max_duty(&self) -> u32
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM3>
impl Timer<TIM3>
sourcepub fn set_dir(&mut self)
pub fn set_dir(&mut self)
Function that allows us to set direction only on timers that have this option.
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u32
pub fn get_duty(&self, channel: TimChannel) -> u32
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u32)
pub fn set_duty(&mut self, channel: TimChannel, duty: u32)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_alignment(&mut self, alignment: Alignment)
Set timer alignment to Edge, or one of 3 center modes. STM32F303 ref man, section 21.4.1: Bits 6:5 CMS: Center-aligned mode selection 00: Edge-aligned mode. The counter counts up or down depending on the direction bit (DIR). 01: Center-aligned mode 1. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting down. 10: Center-aligned mode 2. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting up. 11: Center-aligned mode 3. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set both when the counter is counting up or down.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
sourceimpl Timer<TIM4>
impl Timer<TIM4>
sourcepub fn new_tim4(
regs: TIM4,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim4(
regs: TIM4,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u32
pub fn get_max_duty(&self) -> u32
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM4>
impl Timer<TIM4>
sourcepub fn set_dir(&mut self)
pub fn set_dir(&mut self)
Function that allows us to set direction only on timers that have this option.
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u32
pub fn get_duty(&self, channel: TimChannel) -> u32
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u32)
pub fn set_duty(&mut self, channel: TimChannel, duty: u32)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_alignment(&mut self, alignment: Alignment)
Set timer alignment to Edge, or one of 3 center modes. STM32F303 ref man, section 21.4.1: Bits 6:5 CMS: Center-aligned mode selection 00: Edge-aligned mode. The counter counts up or down depending on the direction bit (DIR). 01: Center-aligned mode 1. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting down. 10: Center-aligned mode 2. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting up. 11: Center-aligned mode 3. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set both when the counter is counting up or down.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
sourceimpl Timer<TIM5>
impl Timer<TIM5>
sourcepub fn new_tim5(
regs: TIM5,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim5(
regs: TIM5,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u32
pub fn get_max_duty(&self) -> u32
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM5>
impl Timer<TIM5>
sourcepub fn set_dir(&mut self)
pub fn set_dir(&mut self)
Function that allows us to set direction only on timers that have this option.
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u32
pub fn get_duty(&self, channel: TimChannel) -> u32
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u32)
pub fn set_duty(&mut self, channel: TimChannel, duty: u32)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_alignment(&mut self, alignment: Alignment)
Set timer alignment to Edge, or one of 3 center modes. STM32F303 ref man, section 21.4.1: Bits 6:5 CMS: Center-aligned mode selection 00: Edge-aligned mode. The counter counts up or down depending on the direction bit (DIR). 01: Center-aligned mode 1. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting down. 10: Center-aligned mode 2. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set only when the counter is counting up. 11: Center-aligned mode 3. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS=00 in TIMx_CCMRx register) are set both when the counter is counting up or down.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
sourceimpl Timer<TIM15>
impl Timer<TIM15>
sourcepub fn new_tim15(
regs: TIM15,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim15(
regs: TIM15,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u16
pub fn get_max_duty(&self) -> u16
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM15>
impl Timer<TIM15>
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u16
pub fn get_duty(&self, channel: TimChannel) -> u16
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u16)
pub fn set_duty(&mut self, channel: TimChannel, duty: u16)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
sourceimpl Timer<TIM16>
impl Timer<TIM16>
sourcepub fn new_tim16(
regs: TIM16,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim16(
regs: TIM16,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u16
pub fn get_max_duty(&self) -> u16
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM16>
impl Timer<TIM16>
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u16
pub fn get_duty(&self, channel: TimChannel) -> u16
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u16)
pub fn set_duty(&mut self, channel: TimChannel, duty: u16)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
sourceimpl Timer<TIM17>
impl Timer<TIM17>
sourcepub fn new_tim17(
regs: TIM17,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
pub fn new_tim17(
regs: TIM17,
freq: f32,
cfg: TimerConfig,
clocks: &Clocks
) -> Self
Initialize a DFSDM peripheral, including enabling and resetting its RCC peripheral clock.
sourcepub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn enable_interrupt(&mut self, interrupt: TimerInterrupt)
Enable a specific type of Timer interrupt.
sourcepub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn disable_interrupt(&mut self, interrupt: TimerInterrupt)
Disable a specific type of Timer interrupt.
sourcepub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
pub fn clear_interrupt(&mut self, interrupt: TimerInterrupt)
Clears interrupt associated with this timer.
If the interrupt is not cleared, it will immediately retrigger after the ISR has finished. For examlpe, place this at the top of your timer’s interrupt handler.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the timer is enabled.
sourcepub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
pub fn set_freq(&mut self, freq: f32) -> Result<(), ValueError>
Set the timer frequency, in Hz. Overrides the period or frequency set in the constructor.
sourcepub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
pub fn set_period(&mut self, period: f32) -> Result<(), ValueError>
Set the timer period, in seconds. Overrides the period or frequency set in the constructor.
sourcepub fn set_auto_reload(&mut self, arr: u32)
pub fn set_auto_reload(&mut self, arr: u32)
Set the auto-reload register value. Used for adjusting frequency.
sourcepub fn set_prescaler(&mut self, psc: u16)
pub fn set_prescaler(&mut self, psc: u16)
Set the prescaler value. Used for adjusting frequency.
sourcepub fn reset_countdown(&mut self)
pub fn reset_countdown(&mut self)
Reset the countdown; set the counter to 0.
sourcepub fn reinitialize(&mut self)
pub fn reinitialize(&mut self)
Re-initialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared. When changing timer frequency (or period) via PSC, you may need to run this. Alternatively, change the freq in an update ISR. Note from RM, PSC reg: PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIMx_EGR register or through trigger controller when configured in “reset mode”).’ If you’re doing something where the updates can wait a cycle, this isn’t required. (eg PWM with changing duty period).
sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Read the current counter value.
sourcepub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
pub fn enable_pwm_output(
&mut self,
channel: TimChannel,
compare: OutputCompare,
duty: f32
)
Enables PWM output for a given channel and output compare, with an initial duty cycle, in Hz.
sourcepub fn get_max_duty(&self) -> u16
pub fn get_max_duty(&self) -> u16
Return the integer associated with the maximum duty period.
sourcepub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
pub unsafe fn write_dma_burst<D>(
&mut self,
buf: &[u16],
base_address: u8,
burst_len: u8,
dma_channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>,
ds_32_bits: bool
) where
D: Deref<Target = RegisterBlock>,
See G4 RM, section 29.4.24: Dma burst mode. “The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to re-program part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.”
sourceimpl Timer<TIM17>
impl Timer<TIM17>
sourcepub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
pub fn _enable_pwm_input(
&mut self,
_channel: TimChannel,
_compare: OutputCompare,
_dir: CountDir,
_duty: f32
)
Enables basic PWM input. TODO: Doesn’t work yet. L4 RM, section 26.3.8
sourcepub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
pub fn set_output_compare(&mut self, channel: TimChannel, mode: OutputCompare)
Set Output Compare Mode. See docs on the OutputCompare
enum.
sourcepub fn get_duty(&self, channel: TimChannel) -> u16
pub fn get_duty(&self, channel: TimChannel) -> u16
Return the set duty period for a given channel. Divide by get_max_duty()
to find the portion of the duty cycle used.
sourcepub fn set_duty(&mut self, channel: TimChannel, duty: u16)
pub fn set_duty(&mut self, channel: TimChannel, duty: u16)
Set the duty cycle, as a portion of ARR (get_max_duty()
). Note that this
needs to be re-run if you change ARR at any point.
sourcepub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
pub fn set_polarity(&mut self, channel: TimChannel, polarity: Polarity)
Set output polarity. See docs on the Polarity
enum.
sourcepub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
pub fn set_complementary_polarity(
&mut self,
channel: TimChannel,
polarity: Polarity
)
Set complementary output polarity. See docs on the Polarity
enum.
sourcepub fn disable_capture_compare(&mut self, channel: TimChannel)
pub fn disable_capture_compare(&mut self, channel: TimChannel)
Disables capture compare on a specific channel.
sourcepub fn enable_capture_compare(&mut self, channel: TimChannel)
pub fn enable_capture_compare(&mut self, channel: TimChannel)
Enables capture compare on a specific channel.
sourcepub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
pub fn set_capture_compare(&mut self, channel: TimChannel, mode: CaptureCompare)
Set Capture Compare Mode. See docs on the CaptureCompare
enum.
sourcepub fn set_preload(&mut self, channel: TimChannel, value: bool)
pub fn set_preload(&mut self, channel: TimChannel, value: bool)
Set preload mode. OC1PE: Output Compare 1 preload enable 0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately. 1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_CCR1 preload value is loaded in the active register at each update event. Note: 1: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S=’00’ (the channel is configured in output). 2: The PWM mode can be used without validating the preload register only in one pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.
Setting preload is required to enable PWM.
Trait Implementations
impl Periodic for Timer<TIM1>
impl Periodic for Timer<TIM2>
impl Periodic for Timer<TIM3>
impl Periodic for Timer<TIM4>
impl Periodic for Timer<TIM5>
impl Periodic for Timer<TIM15>
impl Periodic for Timer<TIM16>
impl Periodic for Timer<TIM17>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more