Skip to content

Commit

Permalink
[beken-72xx] Fix CHANGE interrupt logic (#290)
Browse files Browse the repository at this point in the history
* fix CHANGE interrupt for beken-72xx

* Update cores/beken-72xx/arduino/src/wiring_irq.c

---------

Co-authored-by: Kuba Szczodrzyński <[email protected]>
  • Loading branch information
olivluca and kuba2k2 authored Sep 5, 2024
1 parent 17043f6 commit 41819f2
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cores/beken-72xx/arduino/src/wiring_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ static void irqHandler(unsigned char gpio) {
PinData *data = pinData(pin);
if (!data->irqHandler)
return;
if (!data->irqParam)
((voidFuncPtr)data->irqHandler)();
else
((voidFuncPtrParam)data->irqHandler)(data->irqParam);
if (data->irqChange) {
if (data->gpioMode == INPUT_PULLDOWN) {
data->gpioMode = INPUT_PULLUP;
if (data->irqMode == RISING) {
data->irqMode = FALLING;
gpio_int_enable(pin->gpio, GPIO_INT_LEVEL_FALLING, irqHandler);
} else if (data->gpioMode == INPUT_PULLUP) {
data->gpioMode = INPUT_PULLDOWN;
} else {
data->irqMode = RISING;
gpio_int_enable(pin->gpio, GPIO_INT_LEVEL_RISING, irqHandler);
}
}
if (!data->irqParam)
((voidFuncPtr)data->irqHandler)();
else
((voidFuncPtrParam)data->irqHandler)(data->irqParam);
}

void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void *param) {
Expand Down Expand Up @@ -52,7 +52,13 @@ void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback,
event = GPIO_INT_LEVEL_RISING;
break;
case CHANGE:
event = GPIO_INT_LEVEL_FALLING;
if (gpio_input(pin->gpio)) {
event = GPIO_INT_LEVEL_FALLING;
mode = FALLING;
} else {
event = GPIO_INT_LEVEL_RISING;
mode = RISING;
}
change = true;
break;
default:
Expand Down

0 comments on commit 41819f2

Please sign in to comment.