src/platforms/esp/32/drivers/spi/README.md
This directory contains the ESP32-specific implementation of FastLED's SPI channel driver for LED control.
Main Documentation: See src/platforms/README_SPI_ADVANCED.md for comprehensive SPI system architecture.
| Platform | SPI0 | SPI1 | SPI2 | SPI3 | Available for LEDs | FastLED Status |
|---|---|---|---|---|---|---|
| ESP32 (classic) | Flash cache | Flash | ✅ General | ✅ General | 2 hosts (SPI2+SPI3) | ✅ Enabled |
| ESP32-S2 | Flash cache | Flash | ✅ General | ✅ General | 2 hosts (SPI2+SPI3) | ✅ Enabled |
| ESP32-S3 | Flash cache | Flash | ✅ General | ✅ General | 2 hosts (SPI2+SPI3) | ✅ Enabled |
| ESP32-C3 | Flash cache | Flash | ✅ General | ❌ N/A | 1 host (SPI2) | ✅ Enabled (limited) |
| ESP32-C6 | Flash cache | Flash | ✅ General | ❌ N/A | 1 host (SPI2) | ❌ Disabled (RMT5 used) |
| ESP32-H2 | Flash cache | Flash | ✅ General | ❌ N/A | 1 host (SPI2) | ❌ Disabled (RMT5 used) |
| ESP32-P4 | Flash cache | Flash | ✅ General | ✅ General | 2 hosts (SPI2+SPI3) | ✅ Enabled + Octal |
spi_bus_initialize() APIAnswer: These chips DO have SPI2 available, but FastLED intentionally doesn't use it:
Reasons:
Misconception: Earlier comments stated "ESP32-C6 does not have available SPI hosts (max 0 hosts)" - this was imprecise. The accurate statement is: "ESP32-C6 has 1 SPI host (SPI2), but RMT5 is the preferred driver for LED control."
| File | Purpose |
|---|---|
channel_engine_spi.cpp | Main SPI channel driver implementation (900+ lines) |
channel_engine_spi.h | Generic SPI channel interface (480 lines) |
spi_hw_1_esp32.cpp | Single-lane SPI hardware driver |
spi_esp32_init.cpp | ESP32 SPI initialization and configuration |
spi_platform_esp32.cpp | Platform-specific SPI utilities |
spi_device_proxy.h | Template proxy for routing SPI calls |
idf5_clockless_spi_esp32.h | ESP-IDF 5.x SPI configuration |
User API (FastLED.addLeds<APA102, DATA, CLK>)
↓
ChannelEngineSpi (this directory)
↓
SPI Bus Manager (acquires SPI2/SPI3 hosts)
↓
ESP32 SPI Peripheral (hardware DMA)
SPI-based LED chipsets that work with this driver:
Code: channel_engine_spi.cpp:525-538
spi_host_device_t hosts[] = {
#ifdef SPI2_HOST
SPI2_HOST, // Priority 1: HSPI/SPI2
#endif
#ifdef SPI3_HOST
SPI3_HOST, // Priority 2: VSPI/SPI3
#endif
#ifdef SPI1_HOST
SPI1_HOST, // Priority 3: Flash SPI (avoid, last resort)
#endif
};
Note: SPI1 is included with lowest priority but is typically reserved for flash. In practice, ESP32 variants use SPI2 and SPI3 for LED control.
Dynamically calculated from chipset T1/T2/T3 timing via calculateSpiTiming().
For WS2812: ~6.67 MHz (8 SPI bits per 1250ns LED bit period).
0 → 11000000 (2 HIGH bits = short pulse ~300ns)1 → 11111000 (5 HIGH bits = long pulse ~750ns)1e9 / quantum_ns where quantum = GCD of T1, T2, T3wave8_encoder_spi.h (LUT builder) and encodeChunk() in channel_engine_spi.cpp.hppESP32 @ 240 MHz, 40 MHz SPI clock, 100 LEDs
| Configuration | Time | CPU Usage | Speedup |
|---|---|---|---|
| Software bit-bang | 2.0 ms | 100% | 1x baseline |
| Single-lane SPI | 2.0 ms | 0% | ~1x (DMA) |
| Dual-lane SPI (2 strips) | 1.0 ms | 0% | 2x |
| Quad-lane SPI (4 strips) | 0.5 ms | 0% | 4x |
Key Advantage: DMA-driven transmission = 0% CPU usage during LED updates
Enable debug output:
#define FASTLED_DEBUG 1
#include <FastLED.h>
Debug messages include:
src/platforms/README_SPI_ADVANCED.md (comprehensive guide)src/platforms/esp/32/drivers/channel_bus_manager_esp32.cppsrc/platforms/esp/is_esp.hsrc/platforms/esp/32/feature_flags/enabled.h