Skip to content

Commit

Permalink
Merge pull request atomvm#1258 from rafaltrojniak/fix/gpiodriver_set_…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
bettio committed Sep 20, 2024
2 parents de8923e + d3ec5c0 commit 5b6d8af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ instead
### Fixed

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

## [0.6.4] - 2024-08-18

Expand Down
8 changes: 4 additions & 4 deletions src/platforms/esp32/components/avm_builtins/gpio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ static term gpiodriver_set_int(Context *ctx, int32_t target_pid, term cmd)

struct GPIOData *gpio_data = ctx->platform_data;

term gpio_num_term = term_to_int32(term_get_tuple_element(cmd, 1));
term gpio_num_term = term_get_tuple_element(cmd, 1);
gpio_num_t gpio_num;
if (LIKELY(term_is_integer(gpio_num_term))) {
avm_int_t pin_int = term_to_int32(gpio_num_term);
int32_t pin_int = term_to_int32(gpio_num_term);
if (UNLIKELY((pin_int < 0) || (pin_int >= GPIO_NUM_MAX))) {
return ERROR_ATOM;
}
Expand Down Expand Up @@ -525,10 +525,10 @@ static term gpiodriver_remove_int(Context *ctx, term cmd)
{
struct GPIOData *gpio_data = ctx->platform_data;

term gpio_num_term = term_to_int32(term_get_tuple_element(cmd, 1));
term gpio_num_term = term_get_tuple_element(cmd, 1);
gpio_num_t gpio_num;
if (LIKELY(term_is_integer(gpio_num_term))) {
avm_int_t pin_int = term_to_int32(gpio_num_term);
int32_t pin_int = term_to_int32(gpio_num_term);
if (UNLIKELY((pin_int < 0) || (pin_int >= GPIO_NUM_MAX))) {
return ERROR_ATOM;
}
Expand Down

0 comments on commit 5b6d8af

Please sign in to comment.