chore: Update TimerClockConfig to support period updating method (#1898)
* chore: Update `TimerClockConfig` to support period updating method * docs: added a change log entry
This commit is contained in:
parent
63a2d407ee
commit
888e9425a4
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Added new `Io::new_no_bind_interrupt` constructor (#1861)
|
- Added new `Io::new_no_bind_interrupt` constructor (#1861)
|
||||||
- Added touch pad support for esp32 (#1873)
|
- Added touch pad support for esp32 (#1873)
|
||||||
|
- Allow configuration of period updating method for MCPWM timers (#1898)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@ -32,13 +32,19 @@ impl<const TIM: u8, PWM: PwmPeripheral> Timer<TIM, PWM> {
|
|||||||
/// Apply the given timer configuration.
|
/// Apply the given timer configuration.
|
||||||
///
|
///
|
||||||
/// ### Note:
|
/// ### Note:
|
||||||
/// The prescaler and period configuration will be applied immediately and
|
/// The prescaler and period configuration will be applied immediately by
|
||||||
/// before setting the [`PwmWorkingMode`].
|
/// default and before setting the [`PwmWorkingMode`].
|
||||||
/// If the timer is already running you might want to call [`Timer::stop`]
|
/// If the timer is already running you might want to call [`Timer::stop`]
|
||||||
/// and/or [`Timer::set_counter`] first
|
/// and/or [`Timer::set_counter`] first
|
||||||
/// (if the new period is larger than the current counter value this will
|
/// (if the new period is larger than the current counter value this will
|
||||||
/// cause weird behavior).
|
/// cause weird behavior).
|
||||||
///
|
///
|
||||||
|
/// If configured via [`TimerClockConfig::with_period_updating_method`],
|
||||||
|
/// another behavior can be applied. Currently, only
|
||||||
|
/// [`PeriodUpdatingMethod::Immediately`]
|
||||||
|
/// and [`PeriodUpdatingMethod::TimerEqualsZero`] are useful as the sync
|
||||||
|
/// method is not yet implemented.
|
||||||
|
///
|
||||||
/// The hardware supports writing these settings in sync with certain timer
|
/// The hardware supports writing these settings in sync with certain timer
|
||||||
/// events but this HAL does not expose these for now.
|
/// events but this HAL does not expose these for now.
|
||||||
pub fn start(&mut self, timer_config: TimerClockConfig<'_>) {
|
pub fn start(&mut self, timer_config: TimerClockConfig<'_>) {
|
||||||
@ -46,7 +52,8 @@ impl<const TIM: u8, PWM: PwmPeripheral> Timer<TIM, PWM> {
|
|||||||
self.cfg0().write(|w| unsafe {
|
self.cfg0().write(|w| unsafe {
|
||||||
w.prescale().bits(timer_config.prescaler);
|
w.prescale().bits(timer_config.prescaler);
|
||||||
w.period().bits(timer_config.period);
|
w.period().bits(timer_config.period);
|
||||||
w.period_upmethod().bits(0)
|
w.period_upmethod()
|
||||||
|
.bits(timer_config.period_updating_method as u8)
|
||||||
});
|
});
|
||||||
|
|
||||||
// set timer to continuously run and set the timer working mode
|
// set timer to continuously run and set the timer working mode
|
||||||
@ -111,6 +118,7 @@ impl<const TIM: u8, PWM: PwmPeripheral> Timer<TIM, PWM> {
|
|||||||
pub struct TimerClockConfig<'a> {
|
pub struct TimerClockConfig<'a> {
|
||||||
frequency: HertzU32,
|
frequency: HertzU32,
|
||||||
period: u16,
|
period: u16,
|
||||||
|
period_updating_method: PeriodUpdatingMethod,
|
||||||
prescaler: u8,
|
prescaler: u8,
|
||||||
mode: PwmWorkingMode,
|
mode: PwmWorkingMode,
|
||||||
phantom: PhantomData<&'a Clocks<'a>>,
|
phantom: PhantomData<&'a Clocks<'a>>,
|
||||||
@ -134,6 +142,7 @@ impl<'a> TimerClockConfig<'a> {
|
|||||||
frequency,
|
frequency,
|
||||||
prescaler,
|
prescaler,
|
||||||
period,
|
period,
|
||||||
|
period_updating_method: PeriodUpdatingMethod::Immediately,
|
||||||
mode,
|
mode,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
@ -167,11 +176,20 @@ impl<'a> TimerClockConfig<'a> {
|
|||||||
frequency,
|
frequency,
|
||||||
prescaler: prescaler as u8,
|
prescaler: prescaler as u8,
|
||||||
period,
|
period,
|
||||||
|
period_updating_method: PeriodUpdatingMethod::Immediately,
|
||||||
mode,
|
mode,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the method for updating the PWM period
|
||||||
|
pub fn with_period_updating_method(self, method: PeriodUpdatingMethod) -> Self {
|
||||||
|
Self {
|
||||||
|
period_updating_method: method,
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the timer clock frequency.
|
/// Get the timer clock frequency.
|
||||||
///
|
///
|
||||||
/// ### Note:
|
/// ### Note:
|
||||||
@ -181,6 +199,21 @@ impl<'a> TimerClockConfig<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Method for updating the PWM period
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum PeriodUpdatingMethod {
|
||||||
|
/// The period is updated immediately.
|
||||||
|
Immediately = 0,
|
||||||
|
/// The period is updated when the timer equals zero.
|
||||||
|
TimerEqualsZero = 1,
|
||||||
|
/// The period is updated on a synchronization event.
|
||||||
|
Sync = 2,
|
||||||
|
/// The period is updated either when the timer equals zero or on a
|
||||||
|
/// synchronization event.
|
||||||
|
TimerEqualsZeroOrSync = 3,
|
||||||
|
}
|
||||||
|
|
||||||
/// PWM working mode
|
/// PWM working mode
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user