diff --git a/cores/arduino/HardwareTimer.cpp b/cores/arduino/HardwareTimer.cpp index 081ad5dae4..9a2469ac15 100644 --- a/cores/arduino/HardwareTimer.cpp +++ b/cores/arduino/HardwareTimer.cpp @@ -701,6 +701,28 @@ void HardwareTimer::detachInterrupt(uint32_t channel) callbacks[channel] = NULL; } +/** + * @brief Checks if there's an interrupt callback attached on Rollover event + * @retval returns true if a timer rollover interrupt has already been set + */ +bool HardwareTimer::hasInterrupt() +{ + return callbacks[0] != NULL; +} + +/** + * @brief Checks if there's an interrupt callback attached on Capture/Compare event + * @param channel: Arduino channel [1..4] + * @retval returns true if a channel compare match interrupt has already been set + */ +bool HardwareTimer::hasInterrupt(uint32_t channel) +{ + if ((channel == 0) || (channel > (TIMER_CHANNELS + 1))) { + Error_Handler(); // only channel 1..4 have an interrupt + } + return callbacks[channel] != NULL; +} + /** * @brief Generate an update event to force all registers (Autoreload, prescaler, compare) to be taken into account * @note Refresh() can only be called after a 1st call to resume() to be sure timer is initialised. diff --git a/cores/arduino/HardwareTimer.h b/cores/arduino/HardwareTimer.h index ce3e0cc1ac..dca655032a 100644 --- a/cores/arduino/HardwareTimer.h +++ b/cores/arduino/HardwareTimer.h @@ -110,9 +110,11 @@ class HardwareTimer { //Add interrupt to period update void attachInterrupt(void (*handler)(HardwareTimer *)); // Attach interrupt callback which will be called upon update event (timer rollover) void detachInterrupt(); // remove interrupt callback which was attached to update event + bool hasInterrupt(); //returns true if a timer rollover interrupt has already been set //Add interrupt to capture/compare channel void attachInterrupt(uint32_t channel, void (*handler)(HardwareTimer *)); // Attach interrupt callback which will be called upon compare match event of specified channel void detachInterrupt(uint32_t channel); // remove interrupt callback which was attached to compare match event of specified channel + bool hasInterrupt(uint32_t channel); //returns true if an interrupt has already been set on the channel compare match void timerHandleDeinit(); // Timer deinitialization