Skip to content

#1552: Improve ESP32-S3 SPI Support - #1610

Merged
samguyer merged 1 commit into
FastLED:masterfrom
coryking:fix-1552-better
Mar 15, 2024
Merged

samguyer merged 1 commit into
FastLED:masterfrom
coryking:fix-1552-better

Conversation

@coryking

@coryking coryking commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

This pull request aims to resolve issue #1552 by adapting FastLED's SPI handling for the ESP32-S3. The ESP32-S3 diverges from previous ESP32 models by not using named SPI buses (VSPI/HSPI). Instead, it supports flexible pin assignments for SPI communication. In response, this update defaults to "FSPI" for the ESP32-S3, allowing dynamic pin assignment rather than relying on hardcoded pin mappings.

I want to note that while this solution aligns FastLED with the ESP32-S3's SPI flexibility, I'm not entirely certain this is the absolute "best practice" within the broader context of esp-idf and the arduino-espressif library ecosystem. If you know a better way, I'm all ears!

…g FSPI. This seems to be the right approach.

However, this does limit the ability to support multiple SPI busses running on multiple pins--something that should in theory be supported by the ESP32S3.
@coryking coryking changed the title Basically this change just "tricks" the system into thinking its usin… #1552: Improve ESP32-S3 SPI Support Mar 15, 2024
@samguyer

Copy link
Copy Markdown
Contributor

Looks great! I'm just running the automatic merge checks...

@samguyer
samguyer merged commit b0ba83d into FastLED:master Mar 15, 2024
@samguyer

Copy link
Copy Markdown
Contributor

Merged! Thanks for your contribution

@nrbrook

nrbrook commented Apr 14, 2024 •

Copy link
Copy Markdown

I'm targeting ESP32 S3 (Arduino Nano ESP32) with master branch containing this PR. I'm doing the following:

#define FASTLED_ALL_PINS_HARDWARE_SPI
#include <FastLED.h>
#define DATA_PIN     11
#define CLK_PIN     13
#define NUM_LEDS    144
#define BRIGHTNESS  64
#define LED_TYPE    APA102
#define COLOR_ORDER BGR
CRGB leds[NUM_LEDS];
...
void setup() {
    FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS);
}

I get these errors:

In file included from /Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastled_esp32.h:6,
from /Users/nick/Documents/Arduino/libraries/FastLED/src/platforms.h:42,
from /Users/nick/Documents/Arduino/libraries/FastLED/src/FastLED.h:66,
from /Users/nick/Documents/Repos/LED project/LED_project/LED_project.ino:2:
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:2:17: note: #pragma message: ESP32 Hardware SPI support added
#pragma message "ESP32 Hardware SPI support added"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastled_esp32.h:6,
from /Users/nick/Documents/Arduino/libraries/FastLED/src/platforms.h:42,
from /Users/nick/Documents/Arduino/libraries/FastLED/src/FastLED.h:66,
from /Users/nick/Documents/Repos/LED project/LED_project/LED_project.ino:2:
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:54:18: note: #pragma message: Targeting ESP32S3, which has better SPI support. Configuring for flexible pin assignment.
#pragma message "Targeting ESP32S3, which has better SPI support. Configuring for flexible pin assignment."
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h: In instantiation of 'static void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeWord(uint16_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 10000000; uint16_t = short unsigned int]':
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:447:25: required from 'void P9813Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED>::writeBoundary() [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 10000000]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:466:3: required from 'void P9813Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED>::showPixels(PixelController<RGB_ORDER>&) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 10000000]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:463:15: required from here
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:118:69: error: cannot call member function 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeByte(uint8_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 10000000; uint8_t = unsigned char]' without object
static void writeWord(uint16_t w) attribute((always_inline)) { writeByte(w>>8); writeByte(w&0xFF); }
^~~~~~~~~
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:118:86: error: cannot call member function 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeByte(uint8_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 10000000; uint8_t = unsigned char]' without object
static void writeWord(uint16_t w) attribute((always_inline)) { writeByte(w>>8); writeByte(w&0xFF); }
^~~~~~~~~
In file included from /Users/nick/Documents/Arduino/libraries/FastLED/src/FastLED.h:80,
from /Users/nick/Documents/Repos/LED project/LED_project/LED_project.ino:2:
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h: In instantiation of 'static void LPD8806Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED>::LPD8806_ADJUST::postBlock(int) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 12000000]':
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:189:15: required from 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writePixels(PixelController<RGB_ORDER>) [with unsigned char FLAGS = 0; D = LPD8806Controller<11, 13, (EOrder)136, 12000000>::LPD8806_ADJUST; EOrder RGB_ORDER = (EOrder)136; unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 12000000]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:113:3: required from 'void LPD8806Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED>::showPixels(PixelController<RGB_ORDER>&) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 12000000]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:112:15: required from here
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:96:27: error: cannot call member function 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeBytesValueRaw(uint8_t, int) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 12000000; uint8_t = unsigned char]' without object
SPI::writeBytesValueRaw(0, ((len*3+63)>>6));
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastled_esp32.h:6,
from /Users/nick/Documents/Arduino/libraries/FastLED/src/platforms.h:42,
from /Users/nick/Documents/Arduino/libraries/FastLED/src/FastLED.h:66,
from /Users/nick/Documents/Repos/LED project/LED_project/LED_project.ino:2:
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h: In instantiation of 'static void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeWord(uint16_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 24000000; uint16_t = short unsigned int]':
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:231:3: required from 'void APA102Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED, GAMMA_CORRECTION_MODE, START_FRAME, END_FRAME>::startBoundary() [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 24000000; FiveBitGammaCorrectionMode GAMMA_CORRECTION_MODE = (FiveBitGammaCorrectionMode)1; unsigned int START_FRAME = 0; unsigned int END_FRAME = 0]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:322:3: required from 'void APA102Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED, GAMMA_CORRECTION_MODE, START_FRAME, END_FRAME>::showPixelsDefault(PixelController<RGB_ORDER>&) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 24000000; FiveBitGammaCorrectionMode GAMMA_CORRECTION_MODE = (FiveBitGammaCorrectionMode)1; unsigned int START_FRAME = 0; unsigned int END_FRAME = 0]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:284:5: required from 'void APA102Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED, GAMMA_CORRECTION_MODE, START_FRAME, END_FRAME>::showPixels(PixelController<RGB_ORDER>&) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 24000000; FiveBitGammaCorrectionMode GAMMA_CORRECTION_MODE = (FiveBitGammaCorrectionMode)1; unsigned int START_FRAME = 0; unsigned int END_FRAME = 0]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:281:15: required from here
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:118:69: error: cannot call member function 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeByte(uint8_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 24000000; uint8_t = unsigned char]' without object
static void writeWord(uint16_t w) attribute((always_inline)) { writeByte(w>>8); writeByte(w&0xFF); }
^~~~~~~~~
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:118:86: error: cannot call member function 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeByte(uint8_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 24000000; uint8_t = unsigned char]' without object
static void writeWord(uint16_t w) attribute((always_inline)) { writeByte(w>>8); writeByte(w&0xFF); }
^~~~~~~~~
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h: In instantiation of 'static void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeWord(uint16_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 12000000; uint16_t = short unsigned int]':
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:231:3: required from 'void APA102Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED, GAMMA_CORRECTION_MODE, START_FRAME, END_FRAME>::startBoundary() [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 12000000; FiveBitGammaCorrectionMode GAMMA_CORRECTION_MODE = (FiveBitGammaCorrectionMode)0; unsigned int START_FRAME = 0; unsigned int END_FRAME = 4278190080]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:322:3: required from 'void APA102Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED, GAMMA_CORRECTION_MODE, START_FRAME, END_FRAME>::showPixelsDefault(PixelController<RGB_ORDER>&) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 12000000; FiveBitGammaCorrectionMode GAMMA_CORRECTION_MODE = (FiveBitGammaCorrectionMode)0; unsigned int START_FRAME = 0; unsigned int END_FRAME = 4278190080]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:284:5: required from 'void APA102Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED, GAMMA_CORRECTION_MODE, START_FRAME, END_FRAME>::showPixels(PixelController<RGB_ORDER>&) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; EOrder RGB_ORDER = (EOrder)136; unsigned int SPI_SPEED = 12000000; FiveBitGammaCorrectionMode GAMMA_CORRECTION_MODE = (FiveBitGammaCorrectionMode)0; unsigned int START_FRAME = 0; unsigned int END_FRAME = 4278190080]'
/Users/nick/Documents/Arduino/libraries/FastLED/src/chipsets.h:281:15: required from here
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:118:69: error: cannot call member function 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeByte(uint8_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 12000000; uint8_t = unsigned char]' without object
static void writeWord(uint16_t w) attribute((always_inline)) { writeByte(w>>8); writeByte(w&0xFF); }
^~~~~~~~~
/Users/nick/Documents/Arduino/libraries/FastLED/src/platforms/esp/32/fastspi_esp32.h:118:86: error: cannot call member function 'void ESP32SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>::writeByte(uint8_t) [with unsigned char DATA_PIN = 11; unsigned char CLOCK_PIN = 13; unsigned int SPI_SPEED = 12000000; uint8_t = unsigned char]' without object
static void writeWord(uint16_t w) attribute((always_inline)) { writeByte(w>>8); writeByte(w&0xFF); }
^~~~~~~~~

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.

3 participants