-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Allow using argument with attachInterrupt #1535
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
me-no-dev
merged 8 commits into
espressif:master
from
bertmelis:attachInterrupt-with-arg
Jul 7, 2018
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
beb115a
Allow using argument with attachInterrupt
bertmelis 83affbe
formatting
bertmelis e41d985
fix bug more then 1 interrupt
bertmelis 1e79a6f
leftover
bertmelis ac45eb9
add example
bertmelis bcda737
make attachInterruptArg public
bertmelis f806244
update example
bertmelis d56548a
leftover
bertmelis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={ | |
}; | ||
|
||
typedef void (*voidFuncPtr)(void); | ||
typedef void (*voidFuncPtrArg)(void*); | ||
static voidFuncPtr __pinInterruptHandlers[GPIO_PIN_COUNT] = {0,}; | ||
|
||
#include "driver/rtc_io.h" | ||
|
@@ -208,7 +209,11 @@ static void IRAM_ATTR __onPinInterrupt(void *arg) | |
do { | ||
if(gpio_intr_status_l & ((uint32_t)1 << pin)) { | ||
if(__pinInterruptHandlers[pin]) { | ||
__pinInterruptHandlers[pin](); | ||
if(arg){ | ||
((voidFuncPtrArg)__pinInterruptHandlers[pin])(arg); | ||
} else { | ||
__pinInterruptHandlers[pin](); | ||
} | ||
} | ||
} | ||
} while(++pin<32); | ||
|
@@ -218,22 +223,26 @@ static void IRAM_ATTR __onPinInterrupt(void *arg) | |
do { | ||
if(gpio_intr_status_h & ((uint32_t)1 << (pin - 32))) { | ||
if(__pinInterruptHandlers[pin]) { | ||
__pinInterruptHandlers[pin](); | ||
if(arg){ | ||
((voidFuncPtrArg)__pinInterruptHandlers[pin])(arg); | ||
} else { | ||
__pinInterruptHandlers[pin](); | ||
} | ||
} | ||
} | ||
} while(++pin<GPIO_PIN_COUNT); | ||
} | ||
} | ||
|
||
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) | ||
extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type) | ||
{ | ||
static bool interrupt_initialized = false; | ||
|
||
if(!interrupt_initialized) { | ||
interrupt_initialized = true; | ||
esp_intr_alloc(ETS_GPIO_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __onPinInterrupt, NULL, &gpio_intr_handle); | ||
esp_intr_alloc(ETS_GPIO_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __onPinInterrupt, arg, &gpio_intr_handle); | ||
} | ||
__pinInterruptHandlers[pin] = userFunc; | ||
__pinInterruptHandlers[pin] = (voidFuncPtr)userFunc; | ||
esp_intr_disable(gpio_intr_handle); | ||
if(esp_intr_get_cpu(gpio_intr_handle)) { //APP_CPU | ||
GPIO.pin[pin].int_ena = 1; | ||
|
@@ -244,6 +253,10 @@ extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) | |
esp_intr_enable(gpio_intr_handle); | ||
} | ||
|
||
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) { | ||
__attachInterruptArg(pin, (voidFuncPtrArg)userFunc, NULL, intr_type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The casting (voidFuncPtrArg) looks redundant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but then I get a compiler warning. |
||
} | ||
|
||
extern void __detachInterrupt(uint8_t pin) | ||
{ | ||
esp_intr_disable(gpio_intr_handle); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks too much indentation in here. Are there tabs or gitub change like this?