Skip to content

feat(esp32): select SPI host per controller (#1516) - #4088

Merged
zackees merged 1 commit into
masterfrom
feat/1516-esp32-spi-bus-override
Aug 31, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/1516-esp32-spi-bus-override

Conversation

@zackees

@zackees zackees commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Summary:

  • add typed per-controller ESP32 SPI2/SPI3 host selection to both Channel and legacy APIs
  • carry the selected host through channel configuration, grouping, and controller allocation
  • preserve AUTO priority behavior and isolate same-clock groups requested on different hosts
  • guard SPI3 on one-host ESP32 variants
  • add behavioral allocation regressions and a two-bus ESP32-S3 example

Validation:

  • spi_manager debug/sanitizer suite passed
  • spi_channel_adapter debug/sanitizer suite passed
  • ESP32-S3 MultipleEsp32SpiBuses exact public-API compile passed
  • ESP32-C3 APA102 single-host portability compile passed
  • comprehensive lint passed
  • diff check passed

Closes #1516

Summary by CodeRabbit

  • New Features

    • Added support for selecting ESP32 SPI2 or SPI3 independently for each LED controller.
    • Added an example showing two APA102 strips running on separate SPI buses.
    • Automatic bus selection remains available when no bus is specified.
  • Documentation

    • Updated ESP32 guidance with instructions for configuring per-controller SPI buses.

@zackees
zackees merged commit c39dc59 into master Aug 31, 2026
25 of 30 checks passed
@zackees
zackees deleted the feat/1516-esp32-spi-bus-override branch August 31, 2026 04:55
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 65bf1c64-6bf1-4fb5-b9a2-8b10532f3965

📥 Commits

Reviewing files that changed from the base of the PR and between 9b7f9e3 and ff2d913.

📒 Files selected for processing (20)
  • examples/MultipleEsp32SpiBuses/MultipleEsp32SpiBuses.ino
  • src/FastLED.h
  • src/fl/channels/adapters/spi_channel_adapter.cpp.hpp
  • src/fl/channels/adapters/spi_channel_adapter.h
  • src/fl/channels/cled_controller.h
  • src/fl/channels/config.h
  • src/fl/chipsets/apa102.h
  • src/fl/chipsets/hd108.h
  • src/fl/chipsets/lpd880x.h
  • src/fl/chipsets/p9813.h
  • src/fl/chipsets/sm16716.h
  • src/fl/chipsets/ws2801.h
  • src/fl/spi_bus.h
  • src/platforms/esp/32/README.md
  • src/platforms/esp/32/core/fastspi_esp32_idf.h
  • src/platforms/esp/32/drivers/spi/spi_device_proxy.h
  • src/platforms/shared/spi_manager.cpp.hpp
  • src/platforms/shared/spi_manager.h
  • tests/fl/channels/adapters/spi_channel_adapter.cpp
  • tests/platforms/shared/spi_manager.cpp

📝 Walkthrough

Walkthrough

Adds explicit Esp32SpiBus selection to FastLED APIs, channel routing, SPI allocation, and ESP32 output initialization. AUTO allocation remains available. The PR also adds tests, documentation, and an example using separate SPI2 and SPI3 APA102 strips.

Changes

ESP32 SPI bus selection

Layer / File(s) Summary
Public SPI bus API
src/fl/spi_bus.h, src/fl/channels/..., src/FastLED.h
Adds Esp32SpiBus, stores it in SpiChipsetConfig, exposes setSpiBus, and adds FastLED.addLeds overloads with explicit bus selection.
Bus output and allocation
src/platforms/esp/32/core/..., src/platforms/esp/32/drivers/..., src/platforms/shared/spi_manager.*, src/fl/chipsets/*
Forwards requested buses through SPI controllers and SPIDeviceProxy. The bus manager matches requested buses during registration and controller allocation. ESP32 output selects SPI2, SPI3, or AUTO.
Channel bus-aware routing
src/fl/channels/adapters/spi_channel_adapter.*
Groups channels and reuses assignments by clock pin and requested bus. Explicit requests filter controllers by bus.
Validation and usage
tests/..., src/platforms/esp/32/README.md, examples/MultipleEsp32SpiBuses/...
Adds tests for explicit and AUTO allocation, documents the API, and demonstrates two APA102 strips on SPI2 and SPI3.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FastLED
  participant SpiChannelEngineAdapter
  participant SPIBusManager
  participant ESP32SPIOutput
  FastLED->>SpiChannelEngineAdapter: register channel with requested Esp32SpiBus
  SpiChannelEngineAdapter->>SPIBusManager: register device and requested bus
  SPIBusManager->>SPIBusManager: select matching controller or AUTO controller
  SPIBusManager->>ESP32SPIOutput: initialize selected SPI host
  FastLED->>SpiChannelEngineAdapter: FastLED.show()
  SpiChannelEngineAdapter->>ESP32SPIOutput: transmit LED data
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/1516-esp32-spi-bus-override

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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Aug 31, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Aug 31, 2026
zackees added a commit that referenced this pull request Sep 1, 2026
…) (#4115)

Seven board builds were red on master since #4088: arduino_uno_q, nucleo_f429zi, nucleo_f439zi, stm32f103c8_bluepill, stm32f103cb_maplemini, stm32f103tb_tinystm, check_stm32f103c8_bluepill_size.

fl/spi_bus.h declared `enum class Esp32SpiBus { AUTO, SPI2 = 2, SPI3 = 3 }` and reaches every platform through fl/channels/cled_controller.h. On STM32 the CMSIS device headers get there first and define those names as object-like macros -- `#define SPI2 ((SPI_TypeDef *) SPI2_BASE)` -- so the preprocessor rewrote the enumerator into `((SPI_TypeDef *) SPI2_BASE) = 2,` and the file failed to parse.

Renamed to HOST2 / HOST3, which is also closer to what they are: ESP-IDF's SPI2_HOST and SPI3_HOST. Wire values unchanged.

The alternatives were worse. `#undef SPI2` in a core FastLED header would delete a CMSIS peripheral macro out from under user sketches on STM32. Guarding the enum on `#if defined(ESP32)` leaves the type undeclared everywhere else while core code references it unconditionally.

tests/fl/spi_bus_macro_collision.cpp defines CMSIS-shaped macros before including the header, reproducing the failure without an ARM toolchain -- verified failing on the old names and passing on the new. It also defines HSPI/VSPI, because Arduino-ESP32 3.1.0+ defines SPI2 as well: this was never STM32-specific, which is why it gets a standing guard.

288/288 unit tests, including the new one.

Closes #4113
Refs #4088
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Multiple SPI buses (for ESP32-S2 and ESP32-S3)

1 participant