Skip to content

Commit 9abbc79

Browse files
HardwareTimer: Allow setting preload enable bits
1 parent 109edb3 commit 9abbc79

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

cores/arduino/HardwareTimer.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,41 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
677677
}
678678
}
679679

680+
/**
681+
* @brief Enable or disable preloading for overflow value
682+
* When disabled, changes to the overflow value take effect
683+
* immediately. When enabled, the value takes effect only at
684+
* the next update event (typically the next overflow).
685+
* @param value: true to enable preloading, false to disable
686+
* @retval None
687+
*/
688+
void HardwareTimer::setPreloadEnable(bool value) {
689+
if (value)
690+
LL_TIM_EnableARRPreload(_timerObj.handle.Instance);
691+
else
692+
LL_TIM_DisableARRPreload(_timerObj.handle.Instance);
693+
}
694+
695+
/**
696+
* @brief Enable or disable preloading for capture/compare value
697+
* When disabled, changes to the capture/compare value take
698+
* effect immediately. When enabled, the value takes effect
699+
* only at the next update event (typically the next overflow).
700+
* @param channel: Arduino channel [1..4]
701+
* @param value: true to enable preloading, false to disable
702+
* @retval None
703+
*/
704+
void HardwareTimer::setPreloadEnable(uint32_t channel, bool value) {
705+
int LLChannel = getLLChannel(channel);
706+
if (LLChannel == -1) {
707+
Error_Handler();
708+
}
709+
if (value)
710+
LL_TIM_OC_EnablePreload(_timerObj.handle.Instance, LLChannel);
711+
else
712+
LL_TIM_OC_DisablePreload(_timerObj.handle.Instance, LLChannel);
713+
}
714+
680715
/**
681716
* @brief Set channel Capture/Compare register
682717
* @param channel: Arduino channel [1..4]

cores/arduino/HardwareTimer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class HardwareTimer {
118118
void setMode(uint32_t channel, TimerModes_t mode, PinName pin = NC); // Configure timer channel with specified mode on specified pin if available
119119
void setMode(uint32_t channel, TimerModes_t mode, uint32_t pin);
120120

121+
void setPreloadEnable(bool value);
122+
void setPreloadEnable(uint32_t channel, bool value);
123+
121124
uint32_t getCaptureCompare(uint32_t channel, TimerCompareFormat_t format = TICK_COMPARE_FORMAT); // return Capture/Compare register value of specified channel depending on format provided
122125
void setCaptureCompare(uint32_t channel, uint32_t compare, TimerCompareFormat_t format = TICK_COMPARE_FORMAT); // set Compare register value of specified channel depending on format provided
123126

0 commit comments

Comments
 (0)