Skip to content

Add ESP32-S3 and nRF52 GPIO support#162

Open
Elwimen wants to merge 4 commits intoPaulStoffregen:masterfrom
Elwimen:master
Open

Add ESP32-S3 and nRF52 GPIO support#162
Elwimen wants to merge 4 commits intoPaulStoffregen:masterfrom
Elwimen:master

Conversation

@Elwimen
Copy link
Copy Markdown

@Elwimen Elwimen commented Mar 25, 2026

This adds direct GPIO support for two platforms that are currently missing from OneWire_direct_gpio.h.

ESP32-S3

The ESP32-S3 uses struct-based GPIO register access (.val) in IDF v5, unlike the plain ESP32 which uses scalar registers. This adds explicit CONFIG_IDF_TARGET_ESP32S3 branches to all five GPIO functions (directRead, directWriteLow, directWriteHigh, directModeInput, directModeOutput) with an ESP_IDF_VERSION_MAJOR >= 5 guard to handle both IDF versions. The extended pin range (GPIOs 0–48) is also covered via the in1/out1_w1tc/out1_w1ts/enable1_w1tc/enable1_w1ts registers for pins 32–48.

nRF52 series (nRF52832/nRF52833/nRF52840)

Adds a new platform section using the nrf_gpio_*() SDK functions. g_ADigitalPinMap[] from the Adafruit/RAK nRF52 Arduino core translates Arduino pin numbers to the absolute hardware GPIO numbers that nrf_gpio_*() expects, covering both single-port and dual-port (P0/P1) boards. IO_REG_TYPE is defined as unsigned int rather than uint32_t to avoid a pointer-type mismatch on ARM toolchains where uint32_t aliases unsigned long.

Tested with Meshtastic firmware on ESP32-S3 (IDF v4 and v5) and nRF52840.

Elwimen added 4 commits March 24, 2026 19:19
ESP32-S3 (IDF v5): add explicit CONFIG_IDF_TARGET_ESP32S3 branches to all
five GPIO functions. ESP32-S3 uses struct-based register access (.val) in
IDF v5, unlike plain ESP32 which uses scalar registers. Also extends the
valid pin range to 48 (GPIOs 0-48 on ESP32-S3 vs 0-45 on plain ESP32).

nRF52 series (nRF52832/nRF52833/nRF52840): add a new platform section using
nrf_gpio_*() SDK functions. g_ADigitalPinMap[] from the Adafruit/RAK nRF52
Arduino core translates Arduino pin numbers to the absolute hardware GPIO
numbers that nrf_gpio_*() expects, covering dual-port (P0/P1) boards.
…e mismatch

On some ARM toolchains uint32_t aliases to unsigned long, which is a distinct
type from unsigned int even though both are 32-bit on Cortex-M. This caused a
compile error in OneWire.cpp when assigning the IO_REG_TYPE* class member to a
local volatile IO_REG_TYPE* variable. Using unsigned int directly avoids the
ambiguity and matches the else-fallback definition used by other platforms.
IDF v4 GPIO registers for pins 0-31 are plain scalars (GPIO.in, GPIO.out_w1tc,
etc.). IDF v5 changed them to structs requiring .val. The ESP32-S3 section now
selects scalar or struct access at compile time based on ESP_IDF_VERSION_MAJOR,
keeping the extended pin range (0-48) for both versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant