File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -1158,6 +1158,42 @@ void HardwareTimer::captureCompareCallback(TIM_HandleTypeDef *htim)
11581158 }
11591159}
11601160
1161+ /* *
1162+ * @brief Checks whether HardwareTimer is running (paused or resumed).
1163+ * @retval returns true if the HardwareTimer is running
1164+ */
1165+ bool HardwareTimer::isRunning ()
1166+ {
1167+ return LL_TIM_IsEnabledCounter (_timerObj.handle .Instance );
1168+ }
1169+
1170+ /* *
1171+ * @brief Checks whether channel is running (paused or resumed).
1172+ * @param channel: Arduino channel [1..4]
1173+ * @retval returns true if HardwareTimer is running and the channel is enabled
1174+ */
1175+ bool HardwareTimer::isRunningChannel (uint32_t channel)
1176+ {
1177+ int timAssociatedInputChannel;
1178+ int LLChannel = getLLChannel (channel);
1179+ int interrupt = getIT (channel);
1180+ bool ret;
1181+
1182+ if (LLChannel == -1 ) {
1183+ Error_Handler ();
1184+ }
1185+
1186+ if (interrupt == -1 ) {
1187+ Error_Handler ();
1188+ }
1189+
1190+ // channel is runnning if: timer is running, and either output channel is
1191+ // enabled or interrupt is set
1192+ ret = LL_TIM_CC_IsEnabledChannel (_timerObj.handle .Instance , LLChannel)
1193+ || (__HAL_TIM_GET_IT_SOURCE (&(_timerObj.handle ), interrupt) == SET);
1194+ return (isRunning () && ret);
1195+ }
1196+
11611197/* *
11621198 * @brief HardwareTimer destructor
11631199 * @retval None
Original file line number Diff line number Diff line change @@ -148,9 +148,12 @@ class HardwareTimer {
148148
149149 uint32_t getTimerClkFreq (); // return timer clock frequency in Hz.
150150
151- static void captureCompareCallback (TIM_HandleTypeDef *htim); // Generic Caputre and Compare callback which will call user callback
151+ static void captureCompareCallback (TIM_HandleTypeDef *htim); // Generic Capture and Compare callback which will call user callback
152152 static void updateCallback (TIM_HandleTypeDef *htim); // Generic Update (rollover) callback which will call user callback
153153
154+ bool isRunning (); // returns true if HardwareTimer is running
155+ bool isRunningChannel (uint32_t channel); // returns true if channel is running
156+
154157 // The following function(s) are available for more advanced timer options
155158 TIM_HandleTypeDef *getHandle (); // return the handle address for HAL related configuration
156159 int getChannel (uint32_t channel);
You can’t perform that action at this time.
0 commit comments