Skip to content

Commit 149b648

Browse files
LinoBarrecafpistm
authored andcommitted
Add methods to check if there's an IRQ handler (#764)
1 parent 1e2a598 commit 149b648

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: cores/arduino/HardwareTimer.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,28 @@ void HardwareTimer::detachInterrupt(uint32_t channel)
701701
callbacks[channel] = NULL;
702702
}
703703

704+
/**
705+
* @brief Checks if there's an interrupt callback attached on Rollover event
706+
* @retval returns true if a timer rollover interrupt has already been set
707+
*/
708+
bool HardwareTimer::hasInterrupt()
709+
{
710+
return callbacks[0] != NULL;
711+
}
712+
713+
/**
714+
* @brief Checks if there's an interrupt callback attached on Capture/Compare event
715+
* @param channel: Arduino channel [1..4]
716+
* @retval returns true if a channel compare match interrupt has already been set
717+
*/
718+
bool HardwareTimer::hasInterrupt(uint32_t channel)
719+
{
720+
if ((channel == 0) || (channel > (TIMER_CHANNELS + 1))) {
721+
Error_Handler(); // only channel 1..4 have an interrupt
722+
}
723+
return callbacks[channel] != NULL;
724+
}
725+
704726
/**
705727
* @brief Generate an update event to force all registers (Autoreload, prescaler, compare) to be taken into account
706728
* @note Refresh() can only be called after a 1st call to resume() to be sure timer is initialised.

Diff for: cores/arduino/HardwareTimer.h

+2
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ class HardwareTimer {
110110
//Add interrupt to period update
111111
void attachInterrupt(void (*handler)(HardwareTimer *)); // Attach interrupt callback which will be called upon update event (timer rollover)
112112
void detachInterrupt(); // remove interrupt callback which was attached to update event
113+
bool hasInterrupt(); //returns true if a timer rollover interrupt has already been set
113114
//Add interrupt to capture/compare channel
114115
void attachInterrupt(uint32_t channel, void (*handler)(HardwareTimer *)); // Attach interrupt callback which will be called upon compare match event of specified channel
115116
void detachInterrupt(uint32_t channel); // remove interrupt callback which was attached to compare match event of specified channel
117+
bool hasInterrupt(uint32_t channel); //returns true if an interrupt has already been set on the channel compare match
116118

117119
void timerHandleDeinit(); // Timer deinitialization
118120

0 commit comments

Comments
 (0)