Skip to content

Commit 9b4622d

Browse files
facchinmpillo79
andauthored
Add Arduino Nano ESP32 target (espressif#8417)
* USB: enable DFU interface and stub * nano_nora: add Arduino Nano ESP32 board support * [pin_remap 1/3] platform: define ARDUINO_CORE_BUILD when building core files * [pin_remap 2/3] core,libs: add pin remap hooks * [pin_remap 3/3] nano_nora: implement and enable pin remap * nano_nora: fix: reset all matrix connections at boot * nano_nora: add recovery image for release/v2.x * nano_nora: use official Arduino branding * nano_nora: core split + recovery mode rework Use an absolute address in SPIRAM to store the magic tokens, almost at the end of the memory, to avoid the markers from being overwritten on any kind of sketch and core combination. Also, only start the recovery once if a valid binary is present in the Flash, by immediately setting that for the next boot when recovery starts. * platform: fix: use {compiler.sdk.path} for sdk path In preparation for the sdk -> tool transition * package_index: remove dfu-util from template The tool is already available in mainline package_index.json * on_release: allow single board packages --------- Co-authored-by: Luca Burelli <l.burelli@arduino.cc>
1 parent 1577701 commit 9b4622d

22 files changed

+886
-21
lines changed

.github/scripts/on-release.sh

+27-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ echo "Event: $GITHUB_EVENT_NAME, Repo: $GITHUB_REPOSITORY, Path: $GITHUB_WORKSPA
3636
echo "Action: $action, Branch: $RELEASE_BRANCH, ID: $RELEASE_ID"
3737
echo "Tag: $RELEASE_TAG, Draft: $draft, Pre-Release: $RELEASE_PRE"
3838

39+
# Try extracting something like a JSON with a "boards" array/element and "vendor" fields
40+
BOARDS=`echo $RELEASE_BODY | grep -Pzo '(?s){.*}' | jq -r '.boards[]? // .boards? // empty' | xargs echo -n 2>/dev/null`
41+
VENDOR=`echo $RELEASE_BODY | grep -Pzo '(?s){.*}' | jq -r '.vendor? // empty' | xargs echo -n 2>/dev/null`
42+
if ! [ -z "${BOARDS}" ]; then echo "Releasing board(s): $BOARDS" ; fi
43+
if ! [ -z "${VENDOR}" ]; then echo "Setting packager: $VENDOR" ; fi
44+
3945
function get_file_size(){
4046
local file="$1"
4147
if [[ "$OSTYPE" == "darwin"* ]]; then
@@ -171,12 +177,26 @@ mkdir -p "$PKG_DIR/tools"
171177

172178
# Copy all core files to the package folder
173179
echo "Copying files for packaging ..."
174-
cp -f "$GITHUB_WORKSPACE/boards.txt" "$PKG_DIR/"
180+
if [ -z "${BOARDS}" ]; then
181+
# Copy all variants
182+
cp -f "$GITHUB_WORKSPACE/boards.txt" "$PKG_DIR/"
183+
cp -Rf "$GITHUB_WORKSPACE/variants" "$PKG_DIR/"
184+
else
185+
# Remove all entries not starting with any board code or "menu." from boards.txt
186+
cat "$GITHUB_WORKSPACE/boards.txt" | grep "^menu\." > "$PKG_DIR/boards.txt"
187+
for board in ${BOARDS} ; do
188+
cat "$GITHUB_WORKSPACE/boards.txt" | grep "^${board}\." >> "$PKG_DIR/boards.txt"
189+
done
190+
# Copy only relevant variant files
191+
mkdir "$PKG_DIR/variants/"
192+
for variant in `cat ${PKG_DIR}/boards.txt | grep "\.variant=" | cut -d= -f2` ; do
193+
cp -Rf "$GITHUB_WORKSPACE/variants/${variant}" "$PKG_DIR/variants/"
194+
done
195+
fi
175196
cp -f "$GITHUB_WORKSPACE/package.json" "$PKG_DIR/"
176197
cp -f "$GITHUB_WORKSPACE/programmers.txt" "$PKG_DIR/"
177198
cp -Rf "$GITHUB_WORKSPACE/cores" "$PKG_DIR/"
178199
cp -Rf "$GITHUB_WORKSPACE/libraries" "$PKG_DIR/"
179-
cp -Rf "$GITHUB_WORKSPACE/variants" "$PKG_DIR/"
180200
cp -f "$GITHUB_WORKSPACE/tools/espota.exe" "$PKG_DIR/tools/"
181201
cp -f "$GITHUB_WORKSPACE/tools/espota.py" "$PKG_DIR/tools/"
182202
cp -f "$GITHUB_WORKSPACE/tools/gen_esp32part.py" "$PKG_DIR/tools/"
@@ -209,6 +229,11 @@ sed 's/debug.server.openocd.scripts_dir={runtime.platform.path}\/tools\/openocd-
209229
sed 's/debug.server.openocd.scripts_dir.windows={runtime.platform.path}\\tools\\openocd-esp32\\share\\openocd\\scripts\\/debug.server.openocd.scripts_dir.windows=\{runtime.tools.openocd-esp32.path\}\\share\\openocd\\scripts\\/g' \
210230
> "$PKG_DIR/platform.txt"
211231

232+
if ! [ -z ${VENDOR} ]; then
233+
# Append vendor name to platform.txt to create a separate section
234+
sed -i "/^name=.*/s/$/ ($VENDOR)/" "$PKG_DIR/platform.txt"
235+
fi
236+
212237
# Add header with version information
213238
echo "Generating core_version.h ..."
214239
ver_define=`echo $RELEASE_TAG | tr "[:lower:].\055" "[:upper:]_"`

boards.txt

+51
Original file line numberDiff line numberDiff line change
@@ -24112,3 +24112,54 @@ nebulas3.menu.EraseFlash.all=Enabled
2411224112
nebulas3.menu.EraseFlash.all.upload.erase_cmd=-e
2411324113

2411424114
##############################################################
24115+
24116+
nano_nora.name=Arduino Nano ESP32
24117+
nano_nora.vid.0=0x2341
24118+
nano_nora.pid.0=0x0070
24119+
nano_nora.upload_port.0.vid=0x2341
24120+
nano_nora.upload_port.0.pid=0x0070
24121+
24122+
nano_nora.bootloader.tool=esptool_py
24123+
nano_nora.bootloader.tool.default=esptool_py
24124+
24125+
nano_nora.upload.tool=dfu-util
24126+
nano_nora.upload.tool.default=dfu-util
24127+
nano_nora.upload.tool.network=esp_ota
24128+
nano_nora.upload.protocol=serial
24129+
nano_nora.upload.maximum_size=3145728
24130+
nano_nora.upload.maximum_data_size=327680
24131+
nano_nora.upload.use_1200bps_touch=false
24132+
nano_nora.upload.wait_for_upload_port=false
24133+
24134+
nano_nora.serial.disableDTR=false
24135+
nano_nora.serial.disableRTS=false
24136+
24137+
nano_nora.build.tarch=xtensa
24138+
nano_nora.build.bootloader_addr=0x0
24139+
nano_nora.build.target=esp32s3
24140+
nano_nora.build.mcu=esp32s3
24141+
nano_nora.build.core=esp32
24142+
nano_nora.build.variant=arduino_nano_nora
24143+
nano_nora.build.board=NANO_ESP32
24144+
nano_nora.build.code_debug=0
24145+
24146+
nano_nora.build.usb_mode=0
24147+
nano_nora.build.cdc_on_boot=1
24148+
nano_nora.build.msc_on_boot=0
24149+
nano_nora.build.dfu_on_boot=1
24150+
nano_nora.build.f_cpu=240000000L
24151+
nano_nora.build.flash_size=16MB
24152+
nano_nora.build.flash_freq=80m
24153+
nano_nora.build.flash_mode=dio
24154+
nano_nora.build.boot=qio
24155+
nano_nora.build.boot_freq=80m
24156+
nano_nora.build.partitions=app3M_fat9M_fact512k_16MB
24157+
nano_nora.build.defines=-DBOARD_HAS_PIN_REMAP -DBOARD_HAS_PSRAM '-DUSB_MANUFACTURER="Arduino"' '-DUSB_PRODUCT="Nano ESP32"'
24158+
nano_nora.build.loop_core=-DARDUINO_RUNNING_CORE=1
24159+
nano_nora.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1
24160+
nano_nora.build.psram_type=opi
24161+
nano_nora.build.memory_type={build.boot}_{build.psram_type}
24162+
24163+
nano_nora.tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0xf70000 "{build.variant.path}/extra/nora_recovery/nora_recovery.ino.bin" 0x10000 "{build.path}/{build.project_name}.bin"
24164+
24165+
##############################################################

cores/esp32/Arduino.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@
110110
#define analogInPinToBit(P) (P)
111111
#if SOC_GPIO_PIN_COUNT <= 32
112112
#define digitalPinToPort(pin) (0)
113-
#define digitalPinToBitMask(pin) (1UL << (pin))
113+
#define digitalPinToBitMask(pin) (1UL << digitalPinToGPIONumber(pin))
114114
#define portOutputRegister(port) ((volatile uint32_t*)GPIO_OUT_REG)
115115
#define portInputRegister(port) ((volatile uint32_t*)GPIO_IN_REG)
116116
#define portModeRegister(port) ((volatile uint32_t*)GPIO_ENABLE_REG)
117117
#elif SOC_GPIO_PIN_COUNT <= 64
118-
#define digitalPinToPort(pin) (((pin)>31)?1:0)
119-
#define digitalPinToBitMask(pin) (1UL << (((pin)>31)?((pin)-32):(pin)))
118+
#define digitalPinToPort(pin) ((digitalPinToGPIONumber(pin)>31)?1:0)
119+
#define digitalPinToBitMask(pin) (1UL << (digitalPinToGPIONumber(pin)&31))
120120
#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG))
121121
#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG))
122122
#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG))
@@ -220,5 +220,6 @@ void noTone(uint8_t _pin);
220220
#endif /* __cplusplus */
221221

222222
#include "pins_arduino.h"
223+
#include "io_pin_remap.h"
223224

224225
#endif /* _ESP32_CORE_ARDUINO_H_ */

cores/esp32/FunctionalInterrupt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void ARDUINO_ISR_ATTR interruptFunctional(void* arg)
2828
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode)
2929
{
3030
// use the local interrupt routine which takes the ArgStructure as argument
31-
__attachInterruptFunctionalArg (pin, (voidFuncPtrArg)interruptFunctional, new InterruptArgStructure{intRoutine}, mode, true);
31+
__attachInterruptFunctionalArg (digitalPinToGPIONumber(pin), (voidFuncPtrArg)interruptFunctional, new InterruptArgStructure{intRoutine}, mode, true);
3232
}
3333

3434
extern "C"

cores/esp32/HardwareSerial.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <inttypes.h>
55

66
#include "pins_arduino.h"
7+
#include "io_pin_remap.h"
78
#include "HardwareSerial.h"
89
#include "soc/soc_caps.h"
910
#include "driver/uart.h"
@@ -370,6 +371,10 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
370371
}
371372
}
372373

374+
// map logical pins to GPIO numbers
375+
rxPin = digitalPinToGPIONumber(rxPin);
376+
txPin = digitalPinToGPIONumber(txPin);
377+
373378
if(_uart) {
374379
// in this case it is a begin() over a previous begin() - maybe to change baud rate
375380
// thus do not disable debug output
@@ -554,6 +559,12 @@ bool HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t r
554559
return false;
555560
}
556561

562+
// map logical pins to GPIO numbers
563+
rxPin = digitalPinToGPIONumber(rxPin);
564+
txPin = digitalPinToGPIONumber(txPin);
565+
ctsPin = digitalPinToGPIONumber(ctsPin);
566+
rtsPin = digitalPinToGPIONumber(rtsPin);
567+
557568
// uartSetPins() checks if pins are valid for each function and for the SoC
558569
bool retCode = uartSetPins(_uart, rxPin, txPin, ctsPin, rtsPin);
559570
if (retCode) {

cores/esp32/USB.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@
4747
#define USB_WEBUSB_URL "https://espressif.github.io/arduino-esp32/webusb.html"
4848
#endif
4949

50+
#if CFG_TUD_DFU
51+
__attribute__((weak, unused)) uint16_t load_dfu_ota_descriptor(uint8_t * dst, uint8_t * itf) {
52+
return 0;
53+
}
54+
#endif /* CFG_TUD_DFU */
55+
5056
#if CFG_TUD_DFU_RUNTIME
51-
static uint16_t load_dfu_descriptor(uint8_t * dst, uint8_t * itf)
57+
__attribute__((unused)) static uint16_t load_dfu_descriptor(uint8_t * dst, uint8_t * itf)
5258
{
5359
#define DFU_ATTRS (DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_CAN_UPLOAD | DFU_ATTR_MANIFESTATION_TOLERANT)
5460

@@ -185,7 +191,7 @@ bool ESPUSB::begin(){
185191
.webusb_enabled = webusb_enabled,
186192
.webusb_url = webusb_url.c_str()
187193
};
188-
_started = tinyusb_init(&tinyusb_device_config) == ESP_OK;
194+
_started = tinyusb_init(&tinyusb_device_config) == ESP_OK;
189195
}
190196
return _started;
191197
}
@@ -203,7 +209,9 @@ ESPUSB::operator bool() const
203209
}
204210

205211
bool ESPUSB::enableDFU(){
206-
#if CFG_TUD_DFU_RUNTIME
212+
#if CFG_TUD_DFU
213+
return tinyusb_enable_interface(USB_INTERFACE_DFU, TUD_DFU_DESC_LEN(1), load_dfu_ota_descriptor) == ESP_OK;
214+
#elif CFG_TUD_DFU_RUNTIME
207215
return tinyusb_enable_interface(USB_INTERFACE_DFU, TUD_DFU_RT_DESC_LEN, load_dfu_descriptor) == ESP_OK;
208216
#endif /* CFG_TUD_DFU_RUNTIME */
209217
return false;

cores/esp32/io_pin_remap.h

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#ifndef __IO_PIN_REMAP_H__
2+
#define __IO_PIN_REMAP_H__
3+
4+
#include "Arduino.h"
5+
6+
#if defined(BOARD_HAS_PIN_REMAP) && !defined(BOARD_USES_HW_GPIO_NUMBERS)
7+
8+
// Pin remapping functions
9+
int8_t digitalPinToGPIONumber(int8_t digitalPin);
10+
int8_t digitalPinFromGPIONumber(int8_t gpioPin);
11+
12+
// Apply pin remapping to API only when building libraries and user sketch
13+
#ifndef ARDUINO_CORE_BUILD
14+
15+
// Override APIs requiring pin remapping
16+
17+
// cores/esp32/Arduino.h
18+
#define pulseInLong(pin, state, timeout) pulseInLong(digitalPinToGPIONumber(pin), state, timeout)
19+
#define pulseIn(pin, state, timeout) pulseIn(digitalPinToGPIONumber(pin), state, timeout)
20+
#define noTone(_pin) noTone(digitalPinToGPIONumber(_pin))
21+
#define tone(_pin, frequency, duration) tone(digitalPinToGPIONumber(_pin), frequency, duration)
22+
23+
// cores/esp32/esp32-hal.h
24+
#define analogGetChannel(pin) analogGetChannel(digitalPinToGPIONumber(pin))
25+
#define analogWrite(pin, value) analogWrite(digitalPinToGPIONumber(pin), value)
26+
27+
// cores/esp32/esp32-hal-adc.h
28+
#define adcAttachPin(pin) adcAttachPin(digitalPinToGPIONumber(pin))
29+
#define analogRead(pin) analogRead(digitalPinToGPIONumber(pin))
30+
#define analogReadMilliVolts(pin) analogReadMilliVolts(digitalPinToGPIONumber(pin))
31+
#define analogSetPinAttenuation(pin, attenuation) analogSetPinAttenuation(digitalPinToGPIONumber(pin), attenuation)
32+
#define analogSetVRefPin(pin) analogSetVRefPin(digitalPinToGPIONumber(pin))
33+
34+
// cores/esp32/esp32-hal-dac.h
35+
#define dacDisable(pin) dacDisable(digitalPinToGPIONumber(pin))
36+
#define dacWrite(pin, value) dacWrite(digitalPinToGPIONumber(pin), value)
37+
38+
// cores/esp32/esp32-hal-gpio.h
39+
#define analogChannelToDigitalPin(channel) gpioNumberToDigitalPin(analogChannelToDigitalPin(channel))
40+
#define digitalPinToAnalogChannel(pin) digitalPinToAnalogChannel(digitalPinToGPIONumber(pin))
41+
#define digitalPinToTouchChannel(pin) digitalPinToTouchChannel(digitalPinToGPIONumber(pin))
42+
#define digitalRead(pin) digitalRead(digitalPinToGPIONumber(pin))
43+
#define attachInterruptArg(pin, fcn, arg, mode) attachInterruptArg(digitalPinToGPIONumber(pin), fcn, arg, mode)
44+
#define attachInterrupt(pin, fcn, mode) attachInterrupt(digitalPinToGPIONumber(pin), fcn, mode)
45+
#define detachInterrupt(pin) detachInterrupt(digitalPinToGPIONumber(pin))
46+
#define digitalWrite(pin, val) digitalWrite(digitalPinToGPIONumber(pin), val)
47+
#define pinMode(pin, mode) pinMode(digitalPinToGPIONumber(pin), mode)
48+
49+
// cores/esp32/esp32-hal-i2c.h
50+
#define i2cInit(i2c_num, sda, scl, clk_speed) i2cInit(i2c_num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), clk_speed)
51+
52+
// cores/esp32/esp32-hal-i2c-slave.h
53+
#define i2cSlaveInit(num, sda, scl, slaveID, frequency, rx_len, tx_len) i2cSlaveInit(num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), slaveID, frequency, rx_len, tx_len)
54+
55+
// cores/esp32/esp32-hal-ledc.h
56+
#define ledcAttachPin(pin, channel) ledcAttachPin(digitalPinToGPIONumber(pin), channel)
57+
#define ledcDetachPin(pin) ledcDetachPin(digitalPinToGPIONumber(pin))
58+
59+
// cores/esp32/esp32-hal-matrix.h
60+
#define pinMatrixInAttach(pin, signal, inverted) pinMatrixInAttach(digitalPinToGPIONumber(pin), signal, inverted)
61+
#define pinMatrixOutAttach(pin, function, invertOut, invertEnable) pinMatrixOutAttach(digitalPinToGPIONumber(pin), function, invertOut, invertEnable)
62+
#define pinMatrixOutDetach(pin, invertOut, invertEnable) pinMatrixOutDetach(digitalPinToGPIONumber(pin), invertOut, invertEnable)
63+
64+
// cores/esp32/esp32-hal-rgb-led.h
65+
#define neopixelWrite(pin, red_val, green_val, blue_val) neopixelWrite(digitalPinToGPIONumber(pin), red_val, green_val, blue_val)
66+
67+
// cores/esp32/esp32-hal-rmt.h
68+
#define rmtInit(pin, tx_not_rx, memsize) rmtInit(digitalPinToGPIONumber(pin), tx_not_rx, memsize)
69+
70+
// cores/esp32/esp32-hal-sigmadelta.h
71+
#define sigmaDeltaSetup(pin, channel, freq) sigmaDeltaSetup(digitalPinToGPIONumber(pin), channel, freq)
72+
#define sigmaDeltaDetachPin(pin) sigmaDeltaDetachPin(digitalPinToGPIONumber(pin))
73+
74+
// cores/esp32/esp32-hal-spi.h
75+
#define spiAttachSCK(spi, sck) spiAttachSCK(spi, digitalPinToGPIONumber(sck))
76+
#define spiAttachMISO(spi, miso) spiAttachMISO(spi, digitalPinToGPIONumber(miso))
77+
#define spiAttachMOSI(spi, mosi) spiAttachMOSI(spi, digitalPinToGPIONumber(mosi))
78+
#define spiDetachSCK(spi, sck) spiDetachSCK(spi, digitalPinToGPIONumber(sck))
79+
#define spiDetachMISO(spi, miso) spiDetachMISO(spi, digitalPinToGPIONumber(miso))
80+
#define spiDetachMOSI(spi, mosi) spiDetachMOSI(spi, digitalPinToGPIONumber(mosi))
81+
#define spiAttachSS(spi, cs_num, ss) spiAttachSS(spi, cs_num, digitalPinToGPIONumber(ss))
82+
#define spiDetachSS(spi, ss) spiDetachSS(spi, digitalPinToGPIONumber(ss))
83+
84+
// cores/esp32/esp32-hal-touch.h
85+
#define touchInterruptGetLastStatus(pin) touchInterruptGetLastStatus(digitalPinToGPIONumber(pin))
86+
#define touchRead(pin) touchRead(digitalPinToGPIONumber(pin))
87+
#define touchAttachInterruptArg(pin, userFunc, arg, threshold) touchAttachInterruptArg(digitalPinToGPIONumber(pin), userFunc, arg, threshold)
88+
#define touchAttachInterrupt(pin, userFunc, threshold) touchAttachInterrupt(digitalPinToGPIONumber(pin), userFunc, threshold)
89+
#define touchDetachInterrupt(pin) touchDetachInterrupt(digitalPinToGPIONumber(pin))
90+
#define touchSleepWakeUpEnable(pin, threshold) touchSleepWakeUpEnable(digitalPinToGPIONumber(pin), threshold)
91+
92+
// cores/esp32/esp32-hal-uart.h
93+
#define uartBegin(uart_nr, baudrate, config, rxPin, txPin, rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd) \
94+
uartBegin(uart_nr, baudrate, config, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd)
95+
#define uartSetPins(uart, rxPin, txPin, ctsPin, rtsPin) \
96+
uartSetPins(uart, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), digitalPinToGPIONumber(ctsPin), digitalPinToGPIONumber(rtsPin))
97+
#define uartDetachPins(uart, rxPin, txPin, ctsPin, rtsPin) \
98+
uartDetachPins(uart, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), digitalPinToGPIONumber(ctsPin), digitalPinToGPIONumber(rtsPin))
99+
100+
#endif // ARDUINO_CORE_BUILD
101+
102+
#else
103+
104+
// pin remapping disabled: use stubs
105+
#define digitalPinToGPIONumber(digitalPin) (digitalPin)
106+
#define gpioNumberToDigitalPin(gpioNumber) (gpioNumber)
107+
108+
#endif
109+
110+
#endif /* __GPIO_PIN_REMAP_H__ */

libraries/I2S/src/I2S.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -317,24 +317,24 @@ int I2SClass::begin(int mode, int sampleRate, int bitsPerSample, bool driveClock
317317
int I2SClass::_applyPinSetting(){
318318
if(_driverInstalled){
319319
esp_i2s::i2s_pin_config_t pin_config = {
320-
.bck_io_num = _sckPin,
321-
.ws_io_num = _fsPin,
320+
.bck_io_num = digitalPinToGPIONumber(_sckPin),
321+
.ws_io_num = digitalPinToGPIONumber(_fsPin),
322322
.data_out_num = I2S_PIN_NO_CHANGE,
323323
.data_in_num = I2S_PIN_NO_CHANGE
324324
};
325325
if (_state == I2S_STATE_DUPLEX){ // duplex
326-
pin_config.data_out_num = _outSdPin;
327-
pin_config.data_in_num = _inSdPin;
326+
pin_config.data_out_num = digitalPinToGPIONumber(_outSdPin);
327+
pin_config.data_in_num = digitalPinToGPIONumber(_inSdPin);
328328
}else{ // simplex
329329
if(_state == I2S_STATE_RECEIVER){
330330
pin_config.data_out_num = I2S_PIN_NO_CHANGE;
331-
pin_config.data_in_num = _sdPin;
331+
pin_config.data_in_num = digitalPinToGPIONumber(_sdPin);
332332
}else if(_state == I2S_STATE_TRANSMITTER){
333-
pin_config.data_out_num = _sdPin;
333+
pin_config.data_out_num = digitalPinToGPIONumber(_sdPin);
334334
pin_config.data_in_num = I2S_PIN_NO_CHANGE;
335335
}else{
336336
pin_config.data_out_num = I2S_PIN_NO_CHANGE;
337-
pin_config.data_in_num = _sdPin;
337+
pin_config.data_in_num = digitalPinToGPIONumber(_sdPin);
338338
}
339339
}
340340
if(ESP_OK != esp_i2s::i2s_set_pin((esp_i2s::i2s_port_t) _deviceIndex, &pin_config)){

libraries/SD_MMC/src/SD_MMC.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "pins_arduino.h"
16+
#include "io_pin_remap.h"
1617
#include "SD_MMC.h"
1718
#ifdef SOC_SDMMC_HOST_SUPPORTED
1819
#include "vfs_api.h"
@@ -54,6 +55,15 @@ bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3)
5455
log_e("SD_MMC.setPins must be called before SD_MMC.begin");
5556
return false;
5657
}
58+
59+
// map logical pins to GPIO numbers
60+
clk = digitalPinToGPIONumber(clk);
61+
cmd = digitalPinToGPIONumber(cmd);
62+
d0 = digitalPinToGPIONumber(d0);
63+
d1 = digitalPinToGPIONumber(d1);
64+
d2 = digitalPinToGPIONumber(d2);
65+
d3 = digitalPinToGPIONumber(d3);
66+
5767
#ifdef SOC_SDMMC_USE_GPIO_MATRIX
5868
// SoC supports SDMMC pin configuration via GPIO matrix. Save the pins for later use in SDMMCFS::begin.
5969
_pin_clk = (int8_t) clk;

libraries/SPI/src/SPI.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include "SPI.h"
23+
#include "io_pin_remap.h"
2324
#include "esp32-hal-log.h"
2425

2526
#if !CONFIG_DISABLE_HAL_LOCKS

0 commit comments

Comments
 (0)