From bde2d643eca430b6cae3f1487eeba9a0c9732076 Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Fri, 4 Aug 2023 15:40:31 +0300 Subject: [PATCH 1/2] Sync PlatformIO build scripts (#8488) Added special handling of the `ARDUINO_BUILD_CORE` macro required only for the core files --- tools/platformio-build.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/platformio-build.py b/tools/platformio-build.py index e3c7b50dbb8..5b11c1a9bba 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -172,6 +172,10 @@ def add_tinyuf2_extra_image(): # Target: Build Core Library # +# Set -DARDUINO_CORE_BUILD only for the core library +corelib_env = env.Clone() +corelib_env.Append(CPPDEFINES=["ARDUINO_CORE_BUILD"]) + libs = [] variants_dir = join(FRAMEWORK_DIR, "variants") @@ -181,13 +185,14 @@ def add_tinyuf2_extra_image(): if "build.variant" in board_config: env.Append(CPPPATH=[join(variants_dir, board_config.get("build.variant"))]) - env.BuildSources( + corelib_env.Append(CPPPATH=[join(variants_dir, board_config.get("build.variant"))]) + corelib_env.BuildSources( join("$BUILD_DIR", "FrameworkArduinoVariant"), join(variants_dir, board_config.get("build.variant")), ) libs.append( - env.BuildLibrary( + corelib_env.BuildLibrary( join("$BUILD_DIR", "FrameworkArduino"), join(FRAMEWORK_DIR, "cores", board_config.get("build.core")), ) From 369e974e97757f8d2046588b08b6818d2d91ce16 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Fri, 4 Aug 2023 15:25:40 +0200 Subject: [PATCH 2/2] io_pin_remap fixes for the Arduino Nano ESP32 (#8489) * io_pin_remap: fix tone() function mapping declaration Since tone() can have either 2 or 3 parameters, pass any argument after the first to the actual function implementation. * io_pin_remap: add sanity checks to the core build Building with BOARD_HAS_PIN_REMAP but without setting ARDUINO_CORE_BUILD on core files is absolutely forbidden, as this would lead to multiple pin remappings being silently applied on the same numbers. Also advise the user when, on a board that has a custom pin mapping, - the core is being built without pin mapping support, or - the user explictly asked to use GPIO pin numbers. --- cores/esp32/io_pin_remap.h | 2 +- variants/arduino_nano_nora/io_pin_remap.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cores/esp32/io_pin_remap.h b/cores/esp32/io_pin_remap.h index 4a23de4a829..cd5c93f8737 100644 --- a/cores/esp32/io_pin_remap.h +++ b/cores/esp32/io_pin_remap.h @@ -18,7 +18,7 @@ int8_t digitalPinFromGPIONumber(int8_t gpioPin); #define pulseInLong(pin, state, timeout) pulseInLong(digitalPinToGPIONumber(pin), state, timeout) #define pulseIn(pin, state, timeout) pulseIn(digitalPinToGPIONumber(pin), state, timeout) #define noTone(_pin) noTone(digitalPinToGPIONumber(_pin)) -#define tone(_pin, frequency, duration) tone(digitalPinToGPIONumber(_pin), frequency, duration) +#define tone(_pin, args...) tone(digitalPinToGPIONumber(_pin), args) // cores/esp32/esp32-hal.h #define analogGetChannel(pin) analogGetChannel(digitalPinToGPIONumber(pin)) diff --git a/variants/arduino_nano_nora/io_pin_remap.cpp b/variants/arduino_nano_nora/io_pin_remap.cpp index e53c500a328..2a18e029df2 100644 --- a/variants/arduino_nano_nora/io_pin_remap.cpp +++ b/variants/arduino_nano_nora/io_pin_remap.cpp @@ -1,4 +1,20 @@ -#ifndef BOARD_USES_HW_GPIO_NUMBERS +#if defined(BOARD_HAS_PIN_REMAP) && !defined(ARDUINO_CORE_BUILD) +// -DARDUINO_CORE_BUILD must be set for core files only, to avoid extra +// remapping steps that would create all sorts of issues in the core. +// Removing -DBOARD_HAS_PIN_REMAP at least does correctly restore the +// use of GPIO numbers in the API. +#error This build system is not supported. Please rebuild without BOARD_HAS_PIN_REMAP. +#endif + +#if !defined(BOARD_HAS_PIN_REMAP) +// This board uses pin mapping but the build system has disabled it +#warning The build system forces the Arduino API to use GPIO numbers on a board that has custom pin mapping. +#elif defined(BOARD_USES_HW_GPIO_NUMBERS) +// The user has chosen to disable pin mappin. +#warning The Arduino API will use GPIO numbers for this build. +#endif + +#if defined(BOARD_HAS_PIN_REMAP) && !defined(BOARD_USES_HW_GPIO_NUMBERS) #include "Arduino.h"