From 75fa3889eb90b15b5d05140e35cff44852ca6d3b Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Thu, 25 Jul 2024 09:20:39 +0200 Subject: [PATCH 1/2] Prepare v0.6.4 release Signed-off-by: Davide Bettio --- CHANGELOG.md | 2 ++ src/libAtomVM/atomvm_version.h | 2 +- version.cmake | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0723619b5..61278721e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.6.4] - Unreleased + ## [0.6.3] - 20-07-2024 ### Added diff --git a/src/libAtomVM/atomvm_version.h b/src/libAtomVM/atomvm_version.h index 37ee1b256..51fbfa84b 100644 --- a/src/libAtomVM/atomvm_version.h +++ b/src/libAtomVM/atomvm_version.h @@ -23,6 +23,6 @@ #define ATOMVM_VERSION_MAJOR 0 #define ATOMVM_VERSION_MINOR 6 -#define ATOMVM_VERSION_PATCH 3 +#define ATOMVM_VERSION_PATCH 4 #endif diff --git a/version.cmake b/version.cmake index aa3111da0..dd95e5f26 100644 --- a/version.cmake +++ b/version.cmake @@ -19,5 +19,5 @@ # # Please, keep also in sync src/libAtomVM/atomvm_version.h -set(ATOMVM_BASE_VERSION "0.6.3") -set(ATOMVM_DEV FALSE) +set(ATOMVM_BASE_VERSION "0.6.4") +set(ATOMVM_DEV TRUE) From 855460c571ff124ee2149c9ada1bd37a46e89208 Mon Sep 17 00:00:00 2001 From: Paul Guyot Date: Sun, 21 Jul 2024 09:26:24 +0200 Subject: [PATCH 2/2] Implement `gpio:init/1` on esp32 Some GPIO pins require initialization as gpio pins to work, for example GPIO 4 on ESP32C3. This is achieved by calling esp-idf `gpio_config`. Implement this within `gpio:init/1` which is used on rp2040. Signed-off-by: Paul Guyot --- CHANGELOG.md | 5 ++ libs/eavmlib/src/gpio.erl | 2 +- .../components/avm_builtins/gpio_driver.c | 48 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61278721e..aedfd7318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.6.4] - Unreleased +### Added + +- Implement `gpio:init/1` on esp32 to initialize pins for GPIO usage, which some pins +require depending on default function and bootloader code + ## [0.6.3] - 20-07-2024 ### Added diff --git a/libs/eavmlib/src/gpio.erl b/libs/eavmlib/src/gpio.erl index 7a5b345e5..d0fac085a 100644 --- a/libs/eavmlib/src/gpio.erl +++ b/libs/eavmlib/src/gpio.erl @@ -296,7 +296,7 @@ remove_int(GPIO, Pin) -> %% @param Pin number to initialize %% @returns ok %% @doc Initialize a pin to be used as GPIO. -%% Currently only implemented (and required) for RP2040 (Pico). +%% This is required on RP2040 and for some pins on ESP32. %% @end %%----------------------------------------------------------------------------- -spec init(Pin :: pin()) -> ok. diff --git a/src/platforms/esp32/components/avm_builtins/gpio_driver.c b/src/platforms/esp32/components/avm_builtins/gpio_driver.c index b04917ded..7dcabf1f0 100644 --- a/src/platforms/esp32/components/avm_builtins/gpio_driver.c +++ b/src/platforms/esp32/components/avm_builtins/gpio_driver.c @@ -644,10 +644,43 @@ REGISTER_PORT_DRIVER(gpio, gpio_driver_init, NULL, gpio_driver_create_port) #ifdef CONFIG_AVM_ENABLE_GPIO_NIFS +static term nif_gpio_init(Context *ctx, int argc, term argv[]) +{ + UNUSED(argc); + + gpio_num_t gpio_num; + if (LIKELY(term_is_integer(argv[0]))) { + avm_int_t pin_int = term_to_int32(argv[0]); + if (UNLIKELY((pin_int < 0) || (pin_int >= GPIO_NUM_MAX))) { + RAISE_ERROR(BADARG_ATOM); + } + gpio_num = (gpio_num_t) pin_int; + } else { + RAISE_ERROR(BADARG_ATOM); + } + + gpio_config_t config = {}; + config.pin_bit_mask = 1 << gpio_num; + config.mode = GPIO_MODE_DISABLE; + config.pull_up_en = GPIO_PULLUP_DISABLE; + config.pull_down_en = GPIO_PULLDOWN_DISABLE; + config.intr_type = GPIO_INTR_DISABLE; + + esp_err_t result = gpio_config(&config); + + if (UNLIKELY(result != ESP_OK)) { + RAISE_ERROR(BADARG_ATOM); + } + + return OK_ATOM; +} + /* TODO: in the case of {error, Return} we should RAISE_ERROR(Reason) */ static term nif_gpio_set_pin_mode(Context *ctx, int argc, term argv[]) { + UNUSED(argc); + return gpio_set_pin_mode(ctx, argv[0], argv[1]); } @@ -706,6 +739,12 @@ static term nif_gpio_digital_read(Context *ctx, int argc, term argv[]) return gpio_digital_read(argv[0]); } +static const struct Nif gpio_init_nif = +{ + .base.type = NIFFunctionType, + .nif_ptr = nif_gpio_init +}; + static const struct Nif gpio_set_pin_mode_nif = { .base.type = NIFFunctionType, @@ -757,6 +796,15 @@ static const struct Nif gpio_digital_read_nif = { const struct Nif *gpio_nif_get_nif(const char *nifname) { + if (strcmp("gpio:init/1", nifname) == 0) { + TRACE("Resolved platform nif %s ...\n", nifname); + return &gpio_init_nif; + } + if (strcmp("Elixir.GPIO:init/1", nifname) == 0) { + TRACE("Resolved platform nif %s ...\n", nifname); + return &gpio_init_nif; + } + if (strcmp("gpio:set_pin_mode/2", nifname) == 0) { TRACE("Resolved platform nif %s ...\n", nifname); return &gpio_set_pin_mode_nif;