r/FastLED • u/Ing-Dom • Jul 25 '24
Support Timing of FastLed.Show() on ESP
Hi there,
I changed from "classic" Status LED to some WS2813C LED due to the lack of GPIOs.
I'm aware how this Serial LEDs work, what the bit timings are and why this takes it's time.
I also know in principle what DMA is and how it works, but I don't have experience with it on ESP.
I hack some quick proof of concept using 6 WS2812C and measured FastLED.Show().
It's 216us.
With 6 LEDs a 24bit and a bit timing of 1.25us = 180us it looked like the compiler message - all outputs are bit banging - is correct.
So I added
define FASTLED_ALL_PINS_HARDWARE_SPI true
which changed the compiler message.
But the measured timing was identical: 216us
when I used
FASTLED_ESP32_I2S
it get even worse with 260us.
Maybe, I thought, there is some larger overhead when using DMA which only pays off with more LEDs.
But when I changed NUM_LEDS to 60, I measured 1860us.
Which is quite the time it takes to send that data on the data pin (60x24x1.25 = 1800us).
So, it seems there is no DMA.
What am I doing wrong?
Is there even a "DMA" option for clockless LEDs on ESP?
#include "Arduino.h"
//#define FASTLED_ALL_PINS_HARDWARE_SPI true
//#define FASTLED_ESP32_I2S
#include <FastLED.h>
//#define #define NUM_LEDS 6
#define NUM_LEDS 60
#define DATA_PIN 4
CRGB leds[NUM_LEDS];
void setup()
{
Serial.begin(115200);
Serial.println("Setup");
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
}
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
bool led = LOW;
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis2 >= 500)
{
previousMillis2 = currentMillis;
led = !led;
if(led)
{
leds[0] = CRGB::Blue;
}
else
{
leds[0] = CRGB::Black;
}
uint32_t micros_ = micros();
FastLED.show();
uint32_t micros2 = micros();
Serial.print("Setting LED took ");
Serial.print(micros2-micros_);
Serial.println("us");
}
}
5
u/sutaburosu [stavros] Jul 26 '24
You are using clockless LEDs, not SPI LEDs, so setting
FASTLED_ALL_PINS_HARDWARE_SPIwill make no difference.For clockless LEDs on ESP32 FastLED can use either the RMT or I2S peripheral. Both use DMA. Both block in show() until all the LEDs are sent.
2
u/Netmindz Jul 26 '24
Why does the speed matter? Sounds like you might not need to call show unless you actually want to change the state of the LEDs if you are just using for status display or wrap inside an EVERY_X_MILLIS to periodically update
1
u/Yves-bazin Jul 28 '24
You have to take into account the overhead of the driver and preparation which is done before the sending of the data. This overhead being a fix time hence if you increase the number of leds its effect will be not noticeable anymore.
1
u/ZachVorhies Zach Vorhies Sep 04 '24
We block on show until all leds are displayed. This can be changed but it hasn’t yet.
Feel free to issue a pull request. The leds should kick off during show and block on the next call to ClockLessDriver::onBeginShow()