Skip to content

Add methods to check if there's an IRQ handler #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cores/arduino/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions cores/arduino/HardwareTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down