Skip to content

fix(esp32): build cleanly on ESP-IDF 6 - #2509

Merged
zackees merged 6 commits into
FastLED:masterfrom
swoboda1337:idf6-build-fixes
May 30, 2026
Merged

zackees merged 6 commits into
FastLED:masterfrom
swoboda1337:idf6-build-fixes

Conversation

@swoboda1337

@swoboda1337 swoboda1337 commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Master doesnt currently compile against ESP-IDF 6.0. Hit these
testing FastLED with ESPHome on IDF 6, all in the bundled glob-built
ESP32 sources. Each fix is gated on ESP_IDF_VERSION_6_OR_HIGHER;
IDF 5 and earlier are unchanged.

Changes

  • mcpwm_periph.h relocation — IDF 6 moved this header from soc/
    to hal/. (drivers/gpio_isr_rx/mcpwm_timer.cpp.hpp)
  • i2s_port_t removal — IDF 6 dropped the enum; i2s_chan_config_t::id
    is now int. Pass config.mI2sNum (already int) directly on IDF 6.
    (audio/devices/idf5_i2s_context.hpp, audio/devices/idf5_pdm_context.hpp)
  • OTA disabled on IDF 6 — ota_impl.cpp.hpp uses mbedtls_sha256_*
    / mbedtls_md_* across ~10 call sites. mbedtls 3.6 / IDF 6 moved
    these to mbedtls/private/ and recommends PSA as the public API.
    Gate FL_ESP_OTA_SUPPORTED off on IDF 6 for now; a proper port to
    psa_hash_* is a separate change.
  • Removed driver-config flags — IDF 6 trimmed
    mcpwm_capture_channel_config_t::flags (no more pull_up/pull_down/
    io_loop_back) and the RMT TX/RX flag structs (no more io_od_mode/
    io_loop_back). All were being set to 0 / inert. Loopback is now
    implicit on IDF 6 — same-GPIO TX+RX routes internally without the flag.
  • gpio_num_t strict typing — IDF 6 stops implicit int →
    gpio_num_t. Add static_cast<gpio_num_t>(...) for the LCD_CAM /
    LCD_SPI bus configs; use GPIO_NUM_NC for "no pin" instead of -1.
    (drivers/i2s/i2s_lcd_cam_peripheral_esp.cpp.hpp,
    drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp)

Testing

Compiled via ESPHome on IDF 6.0.1 and 5.5.4 with arduino-esp32 as
managed component for esp32dev and esp32s3.

Follow-up

PSA-crypto port for ota_impl.cpp.hpp to re-enable OTA on IDF 6.

Summary by CodeRabbit

  • Chores
    • Updated ESP32 platform drivers to improve hardware compatibility across different IDF versions.
    • Enhanced audio device initialization for I2S and PDM configurations.
    • Adjusted GPIO and RMT peripheral channel settings for optimal hardware integration.
    • Refined OTA functionality conditions for targeted platform support.

Review Change Stack

Three ESP-IDF 6 incompatibilities in the bundled glob-built sources:

- src/platforms/esp/32/drivers/gpio_isr_rx/mcpwm_timer.cpp.hpp:
  soc/mcpwm_periph.h moved to hal/mcpwm_periph.h in IDF 6. Pick the
  right path with ESP_IDF_VERSION_6_OR_HIGHER.

- src/platforms/esp/32/audio/devices/idf5_i2s_context.hpp and
  src/platforms/esp/32/audio/devices/idf5_pdm_context.hpp:
  IDF 6 removed the i2s_port_t enum; i2s_chan_config_t::id is now
  int. Pass config.mI2sNum (already int) directly on IDF 6, keep the
  explicit static_cast on IDF 5. Include esp_version.h so the new
  guard always resolves regardless of include order.

No behaviour change on IDF 5 or earlier.
ota_impl.cpp.hpp uses mbedtls_sha256_* and mbedtls_md_* APIs across
~10 call sites (digest-auth nonce, password hashing, derived keys,
firmware MD5). mbedtls 3.6 / ESP-IDF 6 moved these direct hash APIs
to mbedtls/private/ and recommends PSA (psa_hash_*) as the public
interface, so the file fails to compile under IDF 6.

Gate FL_ESP_OTA_SUPPORTED off on IDF 6+ for now. A proper port to
PSA is a separate, larger change.
ESP-IDF 6 trimmed several driver config flag fields. FastLED was
unconditionally assigning them, breaking the IDF 6 build. Each
removed flag was already being set to 0 (or, for RX loopback, was
runtime-controlled but inert by default), so gate the assignments
on !ESP_IDF_VERSION_6_OR_HIGHER and emit a warning if a caller asks
for behaviour the new driver no longer supports.

- mcpwm_capture_channel_config_t::flags: pull_up, pull_down,
  io_loop_back removed (kept pos_edge / neg_edge / invert_cap_signal).
  Use gpio_set_pull_mode() / signal routing instead if needed.
- rmt_tx_channel_config_t::flags: io_od_mode, io_loop_back removed.
  Both were 0 here -- defaults still match.
- rmt_rx_channel_config_t::flags: io_loop_back removed. Warn instead
  of silently dropping when caller requested it.
IDF 6 removed io_loop_back not because loopback is unsupported, but
because it became implicit: configuring the same GPIO as both TX
output and RX input routes the signal internally automatically. Drop
the misleading 'not supported' warning and keep the existing 'loopback
enabled' notification regardless of IDF version.
ESP-IDF 6 stops implicitly converting int → gpio_num_t. Several
LCD bus / panel-IO configs in the I2S LCD_CAM and LCD_SPI drivers
assigned raw ints directly, which now fails to compile on the S3
(and any other variant that pulls these drivers in).

- i2s_lcd_cam_peripheral_esp.cpp.hpp: cast dc_gpio_num, wr_gpio_num,
  data_gpio_nums entries; use GPIO_NUM_NC for the unused CS pin.
- lcd_spi_peripheral_esp.cpp.hpp: same set of casts (dc_gpio_num
  defaulting, wr_gpio_num clock, data_gpio_nums), GPIO_NUM_NC for CS.

No behaviour change -- GPIO_NUM_NC is the canonical (gpio_num_t)-1
"no pin" sentinel and has been available since IDF 4.x.
The fix commits themselves explain the IDF 6 changes; in-code
comments duplicating that context add noise.
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR updates multiple ESP32 audio and driver modules to support ESP-IDF v6+ API changes. Changes include conditional I2S channel configuration macros, version-gated peripheral header includes, explicit GPIO type casting for type safety, conditional GPIO flag assignments for newer IDF versions, and restricting OTA support to IDF versions 4–5.

Changes

ESP-IDF v6 Compatibility Updates

Layer / File(s) Summary
I2S Audio Channel Configuration Compatibility
src/platforms/esp/32/audio/devices/idf5_i2s_context.hpp, src/platforms/esp/32/audio/devices/idf5_pdm_context.hpp
I2S context and PDM audio modules add version header includes and conditionally adapt channel configuration to match ESP-IDF v6+ macro API, using direct config.mI2sNum for v6+ but explicit i2s_port_t cast for older versions.
MCPWM Capture Channel Configuration
src/platforms/esp/32/drivers/gpio_isr_rx/mcpwm_timer.cpp.hpp
MCPWM timer module gates peripheral header includes to hal/mcpwm_periph.h for v6+ and soc/mcpwm_periph.h for older versions, and conditionally skips GPIO pull/loopback flags on v6+ builds.
GPIO Type Safety for LCD and I2S Peripherals
src/platforms/esp/32/drivers/i2s/i2s_lcd_cam_peripheral_esp.cpp.hpp, src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp
I2S LCD/camera and LCD SPI peripheral I80 bus configurations updated to use explicit gpio_num_t casts for GPIO assignments and replace -1 sentinel with GPIO_NUM_NC constant for no-chip-select pins.
RMT Channel GPIO Flags Conditionals
src/platforms/esp/32/drivers/rmt/rmt_5/rmt5_peripheral_esp.cpp.hpp, src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.cpp.hpp
RMT5 TX and RMT RX channel configurations now conditionally set GPIO flag fields (loopback, pull directions) only on ESP-IDF versions prior to 6.0.
OTA Feature Support Gating
src/platforms/esp/32/ota/ota_impl.cpp.hpp
OTA implementation support is now restricted to ESP-IDF versions 4.x through 5.x, excluding ESP-IDF 6+ builds along with existing ESP32-H2 and ESP32-P4 exclusions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

Whiskers twitching with delight, 🐰
Conditionals align the code just right,
GPIO types now safely cast,
Version macros hold steadfast,
IDF 6 compatibility in sight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: making the codebase build cleanly on ESP-IDF 6 through version-conditional compatibility changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 53909e5 into FastLED:master May 30, 2026
1 check failed
@zackees

zackees commented May 30, 2026

Copy link
Copy Markdown
Member

Hi @swoboda1337 — I'm clud, an AI working for @zackees, dropping by to say a sincere thank you for this PR! 🙏

I went through what you shipped here and it's a really clean piece of cross-version compatibility work:

  • mcpwm_periph.h relocation — caught the soc/ → hal/ move and gated it cleanly on ESP_IDF_VERSION_6_OR_HIGHER.
  • i2s_port_t removal — handled the enum drop in i2s_chan_config_t::id for both idf5_i2s_context.hpp and idf5_pdm_context.hpp, with the careful esp_version.h include so the guard always resolves regardless of include order.
  • OTA disable on IDF 6 — exactly the right call to gate FL_ESP_OTA_SUPPORTED off rather than half-port the mbedtls_sha256_* / mbedtls_md_* call sites. The PSA-crypto port really is a separate, larger change.
  • Driver-config flag trims — noticed that mcpwm_capture_channel_config_t::flags, rmt_tx_channel_config_t::flags, and rmt_rx_channel_config_t::flags lost fields in IDF 6, and the follow-up commit clarifying that io_loop_back removal is implicit (same-GPIO routes internally) instead of unsupported was a really nice touch — that's exactly the kind of nuance that saves the next person hours.
  • gpio_num_t strict typing — the LCD_CAM / LCD_SPI casts plus using GPIO_NUM_NC instead of -1 is the canonical fix.

And testing on both IDF 6.0.1 and 5.5.4 via ESPHome with arduino-esp32 as a managed component is exactly the kind of dual-version validation that gives us confidence nothing regressed for existing users.

The commit hygiene is excellent too — one logical change per commit, each message explains the why, and the final chore: strip explanatory comments commit keeping the codebase clean (since the commit history already carries the context) is a pattern I wish more contributors adopted.

Contributions like this — surgical, well-tested, well-documented, and forward-thinking with the OTA follow-up note — are exactly what keeps FastLED healthy across the wide ESP-IDF version matrix. Your work was greatly appreciated! 💛

— clud (on behalf of @zackees)

@swoboda1337

Copy link
Copy Markdown
Contributor Author

Thanks!

@zackees

zackees commented May 30, 2026

Copy link
Copy Markdown
Member

No, thank you! ~Z

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.

2 participants