From 0faf7b752d143f4acec4842e6eabb733360f8c55 Mon Sep 17 00:00:00 2001 From: Hendry Kaak Date: Mon, 11 Nov 2019 16:33:30 +0100 Subject: [PATCH] [Timer] Add getHandle function This enables users to config timers using the HAL layers for more advanced timer settings when needed. This is especially useful when multiple timer channels require separate configurations under the same timer instance. --- cores/arduino/HardwareTimer.cpp | 12 ++++++++++++ cores/arduino/HardwareTimer.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/cores/arduino/HardwareTimer.cpp b/cores/arduino/HardwareTimer.cpp index 081ad5dae4..8eeec08cfd 100644 --- a/cores/arduino/HardwareTimer.cpp +++ b/cores/arduino/HardwareTimer.cpp @@ -712,6 +712,18 @@ void HardwareTimer::refresh() HAL_TIM_GenerateEvent(&(_timerObj.handle), TIM_EVENTSOURCE_UPDATE); } +/** + * @brief Return the timer object handle object for more advanced setup + * @note Using this function and editing the Timer handle is at own risk! No support will + * be provided whatsoever if the HardwareTimer does not work as expected when editing + * the handle using the HAL functionality or other custom coding. + * @retval TIM_HandleTypeDef address + */ +TIM_HandleTypeDef *HardwareTimer::getHandle() +{ + return &_timerObj.handle; +} + /** * @brief Generic Update (rollover) callback which will call user callback * @param htim: HAL timer handle diff --git a/cores/arduino/HardwareTimer.h b/cores/arduino/HardwareTimer.h index ce3e0cc1ac..a687af36ee 100644 --- a/cores/arduino/HardwareTimer.h +++ b/cores/arduino/HardwareTimer.h @@ -126,6 +126,8 @@ class HardwareTimer { static void captureCompareCallback(TIM_HandleTypeDef *htim); // Generic Caputre and Compare callback which will call user callback static void updateCallback(TIM_HandleTypeDef *htim); // Generic Update (rollover) callback which will call user callback + // The following function(s) are available for more advanced timer options + TIM_HandleTypeDef *getHandle(); // return the handle address for HAL related configuration private: TIM_OC_InitTypeDef _channelOC[TIMER_CHANNELS]; TIM_IC_InitTypeDef _channelIC[TIMER_CHANNELS];