Skip to content

Commit 5b6d8af

Browse files
committed
Merge pull request #1258 from rafaltrojniak/fix/gpiodriver_set_int_pin_number_handling
fix: ESP32 gpiodriver_set_int - pin number handling Cast Pin number to integer after checking if it is integer. These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents de8923e + d3ec5c0 commit 5b6d8af

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)