Skip to content

Commit

Permalink
io_pin_remap fixes for the Arduino Nano ESP32 (espressif#8489)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pillo79 authored Aug 4, 2023
1 parent ebb4123 commit 369e974
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cores/esp32/io_pin_remap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 17 additions & 1 deletion variants/arduino_nano_nora/io_pin_remap.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down

0 comments on commit 369e974

Please sign in to comment.