Skip to content

Commit d3ec5c0

Browse files
committed
fix: ESP32 gpiodriver interrupt pin number handling
Cast Pin number to integer after checking if it is integer. Now set_int can set interrupt on any pin, not only pin 2. Improved pin_int typing after casting to int Signed-off-by: Rafał Trójniak <git@trojniak.net>
1 parent de8923e commit d3ec5c0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ instead
2626
### Fixed
2727

2828
- ESP32: content of `boot.avm` partition is not truncated anymore
29+
- ESP32: Fixed gpio:set_int` to accept any pin, not only pin 2
2930

3031
## [0.6.4] - 2024-08-18
3132

src/platforms/esp32/components/avm_builtins/gpio_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ static term gpiodriver_set_int(Context *ctx, int32_t target_pid, term cmd)
422422

423423
struct GPIOData *gpio_data = ctx->platform_data;
424424

425-
term gpio_num_term = term_to_int32(term_get_tuple_element(cmd, 1));
425+
term gpio_num_term = term_get_tuple_element(cmd, 1);
426426
gpio_num_t gpio_num;
427427
if (LIKELY(term_is_integer(gpio_num_term))) {
428-
avm_int_t pin_int = term_to_int32(gpio_num_term);
428+
int32_t pin_int = term_to_int32(gpio_num_term);
429429
if (UNLIKELY((pin_int < 0) || (pin_int >= GPIO_NUM_MAX))) {
430430
return ERROR_ATOM;
431431
}
@@ -525,10 +525,10 @@ static term gpiodriver_remove_int(Context *ctx, term cmd)
525525
{
526526
struct GPIOData *gpio_data = ctx->platform_data;
527527

528-
term gpio_num_term = term_to_int32(term_get_tuple_element(cmd, 1));
528+
term gpio_num_term = term_get_tuple_element(cmd, 1);
529529
gpio_num_t gpio_num;
530530
if (LIKELY(term_is_integer(gpio_num_term))) {
531-
avm_int_t pin_int = term_to_int32(gpio_num_term);
531+
int32_t pin_int = term_to_int32(gpio_num_term);
532532
if (UNLIKELY((pin_int < 0) || (pin_int >= GPIO_NUM_MAX))) {
533533
return ERROR_ATOM;
534534
}

0 commit comments

Comments
 (0)