5#if !FL_HAS_INCLUDE("esp_memory_utils.h")
7 "esp_memory_utils.h is not available, are you using esp-idf 4.4 or earlier?"
10#pragma GCC diagnostic push
11#pragma GCC diagnostic ignored "-Wattributes"
12#pragma GCC diagnostic ignored "-Wvolatile"
16#include "esp_heap_caps.h"
17#include "esp_intr_alloc.h"
18#include "esp_memory_utils.h"
21#include "platforms/assert_defs.h"
25#include "driver/gpio.h"
26#include "esp_memory_utils.h"
27#include "esp_private/gdma.h"
28#include "esp_rom_gpio.h"
29#include "hal/dma_types.h"
30#include "hal/gpio_hal.h"
32#include "soc/soc_caps.h"
36#include "hal/lcd_hal.h"
37#include "hal/lcd_ll.h"
38#include "soc/lcd_periph.h"
40#include "esp_heap_caps.h"
41#include "esp_lcd_panel_interface.h"
42#include "esp_lcd_panel_io.h"
43#include "esp_lcd_panel_io_interface.h"
44#include "esp_lcd_panel_ops.h"
47#include "soc/gdma_reg.h"
48#include "platforms/esp/esp_version.h"
50#define IDF_5_4_OR_EARLIER (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 5, 0))
55#define FASTLED_EXPERIMENTAL_YVES_EXTRA_WAIT_MICROS 300
65#ifndef ALTERNATEPATTERN
66#define ALTERNATEPATTERN 1
71#pragma push_macro("AA")
72#pragma push_macro("CC")
73#pragma push_macro("FF")
74#pragma push_macro("FF2")
102#define AA (0x00AA00AAL)
103#define CC (0x0000CCCCL)
104#define FF (0xF0F0F0F0L)
105#define FF2 (0x0F0F0F0FL)
112#define MIN(a, b) (((a) < (b)) ? (a) : (b))
117#define __OFFSET_END (24 * 3 * 2 * 2 * 2 + 2)
118#ifndef HARDWARESPRITES
119#define HARDWARESPRITES 0
122#if HARDWARESPRITES == 1
123#include "hardwareSprite.h"
126#ifdef COLOR_ORDER_GRBW
130#define _nb_components 4
132#ifdef COLOR_ORDER_RGB
136#define _nb_components 3
138#ifdef COLOR_ORDER_RBG
142#define _nb_components 3
144#ifdef COLOR_ORDER_GBR
148#define _nb_components 3
150#ifdef COLOR_ORDER_BGR
154#define _nb_components 3
156#ifdef COLOR_ORDER_BRG
160#define _nb_components 3
162#ifdef COLOR_ORDER_GRB
166#define _nb_components 3
172#define _nb_components 3
187#define LCD_DRIVER_PSRAM_DATA_ALIGNMENT 64
193#ifdef FASTLED_OVERCLOCK
194#define FASTLED_ESP32S3_I2S_CLOCK_HZ_SCALE (FASTLED_OVERCLOCK)
196#define FASTLED_ESP32S3_I2S_CLOCK_HZ_SCALE (1)
199#ifndef FASTLED_ESP32S3_I2S_CLOCK_HZ
200#define FASTLED_ESP32S3_I2S_CLOCK_HZ uint32_t((24 * 100 * 1000)*FASTLED_ESP32S3_I2S_CLOCK_HZ_SCALE)
205static bool IRAM_ATTR flush_ready(esp_lcd_panel_io_handle_t panel_io,
206 esp_lcd_panel_io_event_data_t *edata,
215enum colorarrangment {
232bool DRIVER_READY =
true;
234typedef struct led_driver_t led_driver_t;
238 void (*update)(uint8_t *colors,
size_t len);
240volatile xSemaphoreHandle I2SClocklessLedDriverS3_sem = NULL;
241volatile bool isDisplaying =
false;
242volatile bool iswaiting =
false;
244static void IRAM_ATTR transpose16x1_noinline2(
unsigned char *A, uint16_t *B) {
246 uint32_t
x,
y, x1, y1,
t;
248 y = *(
unsigned int *)(A);
250 x = *(
unsigned int *)(A + 4);
256 y1 = *(
unsigned int *)(A + 8);
261 x1 = *(
unsigned int *)(A + 12);
268 t = (
x ^ (
x >> 7)) & AA;
269 x =
x ^
t ^ (
t << 7);
270 t = (
x ^ (
x >> 14)) & CC;
271 x =
x ^
t ^ (
t << 14);
274 t = (x1 ^ (x1 >> 7)) & AA;
275 x1 = x1 ^
t ^ (
t << 7);
276 t = (x1 ^ (x1 >> 14)) & CC;
277 x1 = x1 ^
t ^ (
t << 14);
280 t = (
y ^ (
y >> 7)) & AA;
281 y =
y ^
t ^ (
t << 7);
282 t = (
y ^ (
y >> 14)) & CC;
283 y =
y ^
t ^ (
t << 14);
285 t = (y1 ^ (y1 >> 7)) & AA;
286 y1 = y1 ^
t ^ (
t << 7);
287 t = (y1 ^ (y1 >> 14)) & CC;
288 y1 = y1 ^
t ^ (
t << 14);
291 t = (
x & FF) | ((
y >> 4) & FF2);
292 y = ((
x << 4) & FF) | (
y & FF2);
295 t = (x1 & FF) | ((y1 >> 4) & FF2);
296 y1 = ((x1 << 4) & FF) | (y1 & FF2);
300 (uint16_t)(((
x & 0xff000000) >> 8 | ((x1 & 0xff000000))) >> 16);
301 *((uint16_t *)(B + 3)) =
302 (uint16_t)(((
x & 0xff0000) >> 16 | ((x1 & 0xff0000) >> 8)));
303 *((uint16_t *)(B + 6)) =
304 (uint16_t)(((
x & 0xff00) | ((x1 & 0xff00) << 8)) >> 8);
305 *((uint16_t *)(B + 9)) = (uint16_t)((
x & 0xff) | ((x1 & 0xff) << 8));
306 *((uint16_t *)(B + 12)) =
307 (uint16_t)(((
y & 0xff000000) >> 8 | ((y1 & 0xff000000))) >> 16);
308 *((uint16_t *)(B + 15)) =
309 (uint16_t)(((
y & 0xff0000) | ((y1 & 0xff0000) << 8)) >> 16);
310 *((uint16_t *)(B + 18)) =
311 (uint16_t)(((
y & 0xff00) | ((y1 & 0xff00) << 8)) >> 8);
312 *((uint16_t *)(B + 21)) = (uint16_t)((
y & 0xff) | ((y1 & 0xff) << 8));
315esp_lcd_panel_io_handle_t led_io_handle = NULL;
317class I2SClocklessLedDriveresp32S3 {
321 uint16_t *buffers[2];
322 uint16_t *led_output = NULL;
323 uint16_t *led_output2 = NULL;
324 uint8_t *ledsbuff = NULL;
325 int num_leds_per_strip;
329 uint8_t __green_map[256];
330 uint8_t __blue_map[256];
331 uint8_t __red_map[256];
332 uint8_t __white_map[256];
334 float _gammar, _gammab, _gammag, _gammaw;
339 for (
int i = 0; i < 256; i++) {
340 tmp = powf((
float)i / 255, 1 / _gammag);
342 tmp = powf((
float)i / 255, 1 / _gammab);
344 tmp = powf((
float)i / 255, 1 / _gammar);
346 tmp = powf((
float)i / 255, 1 / _gammaw);
351 void setGamma(
float gammar,
float gammab,
float gammag,
float gammaw) {
356 setBrightness(_brightness);
359 void setGamma(
float gammar,
float gammab,
float gammag) {
363 setBrightness(_brightness);
366 void _initled(uint8_t *
leds,
const int *pins,
int numstrip,
367 int NUM_LED_PER_STRIP) {
372 esp_lcd_i80_bus_handle_t i80_bus = NULL;
374 esp_lcd_i80_bus_config_t bus_config;
376 bus_config.clk_src = LCD_CLK_SRC_PLL160M;
377 bus_config.dc_gpio_num = 0;
378 bus_config.wr_gpio_num = 0;
380 for (
int i = 0; i < numstrip; i++) {
381 bus_config.data_gpio_nums[i] = pins[i];
384 for (
int i = numstrip; i < 16; i++) {
385 bus_config.data_gpio_nums[i] = 0;
388 bus_config.bus_width = 16;
389 bus_config.max_transfer_bytes =
390 _nb_components * NUM_LED_PER_STRIP * 8 * 3 * 2 + __OFFSET + __OFFSET_END;
391 #if IDF_5_4_OR_EARLIER
392 #pragma GCC diagnostic push
393 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
397 bus_config.psram_trans_align = LCD_DRIVER_PSRAM_DATA_ALIGNMENT;
398 bus_config.sram_trans_align = 4;
399 #if IDF_5_4_OR_EARLIER
400 #pragma GCC diagnostic pop
403 esp_err_t bus_err = esp_lcd_new_i80_bus(&bus_config, &i80_bus);
404 FASTLED_ASSERT(bus_err == ESP_OK,
"Failed to create ESP32 I2S LCD bus");
406 esp_lcd_panel_io_i80_config_t io_config;
408 io_config.cs_gpio_num = -1;
409 io_config.pclk_hz = FASTLED_ESP32S3_I2S_CLOCK_HZ;
410 io_config.trans_queue_depth = 1;
411 io_config.dc_levels = {
419 io_config.lcd_cmd_bits = 0;
420 io_config.lcd_param_bits = 0;
421 io_config.user_ctx =
this;
423 io_config.on_color_trans_done = flush_ready;
424 esp_err_t panel_err = esp_lcd_new_panel_io_i80(i80_bus, &io_config, &led_io_handle);
425 FASTLED_ASSERT(panel_err == ESP_OK,
"Failed to create ESP32 I2S LCD panel IO");
428 void initled(uint8_t *
leds,
const int *pins,
int numstrip,
429 int NUM_LED_PER_STRIP) {
436 if (I2SClocklessLedDriverS3_sem == NULL) {
437 I2SClocklessLedDriverS3_sem = xSemaphoreCreateBinary();
441 led_output = (uint16_t *)heap_caps_aligned_alloc(
442 LCD_DRIVER_PSRAM_DATA_ALIGNMENT,
443 8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
445 MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
446 memset(led_output, 0,
447 8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
450 led_output2 = (uint16_t *)heap_caps_aligned_alloc(
451 LCD_DRIVER_PSRAM_DATA_ALIGNMENT,
452 8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
454 MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
455 memset(led_output2, 0,
456 8 * _nb_components * NUM_LED_PER_STRIP * 3 * 2 + __OFFSET +
458 buffers[0] = led_output;
459 buffers[1] = led_output2;
463 led_output2 += __OFFSET / 2;
464 led_output += __OFFSET / 2;
466 for (
int i = 0; i < NUM_LED_PER_STRIP * _nb_components * 8; i++) {
467 led_output[3 * i + 1] =
470 led_output2[3 * i + 1] = 0xFFFF;
473 _numstrips = numstrip;
474 num_leds_per_strip = NUM_LED_PER_STRIP;
475 _initled(
leds, pins, numstrip, NUM_LED_PER_STRIP);
478 void transposeAll(uint16_t *ledoutput) {
480 uint16_t ledToDisplay = 0;
481 Lines secondPixel[_nb_components];
484 uint16_t jump = num_leds_per_strip * _nb_components;
485 for (
int j = 0; j < num_leds_per_strip; j++) {
486 uint8_t *poli = ledsbuff + ledToDisplay * _nb_components;
487 for (
int i = 0; i < _numstrips; i++) {
489 secondPixel[_p_g].bytes[i] = __green_map[*(poli + 1)];
490 secondPixel[_p_r].bytes[i] = __red_map[*(poli + 0)];
491 secondPixel[_p_b].bytes[i] = __blue_map[*(poli + 2)];
492 if (_nb_components > 3)
493 secondPixel[3].bytes[i] = __white_map[*(poli + 3)];
498 transpose16x1_noinline2(secondPixel[0].bytes, buff);
500 transpose16x1_noinline2(secondPixel[1].bytes, buff);
502 transpose16x1_noinline2(secondPixel[2].bytes, buff);
504 if (_nb_components > 3) {
505 transpose16x1_noinline2(secondPixel[3].bytes, buff);
512 transposeAll(buffers[currentframe]);
516 if (I2SClocklessLedDriverS3_sem == NULL)
517 I2SClocklessLedDriverS3_sem = xSemaphoreCreateBinary();
518 xSemaphoreTake(I2SClocklessLedDriverS3_sem, portMAX_DELAY);
522 if (FASTLED_EXPERIMENTAL_YVES_EXTRA_WAIT_MICROS) {
523 delayMicroseconds(FASTLED_EXPERIMENTAL_YVES_EXTRA_WAIT_MICROS);
526 led_io_handle->tx_color(led_io_handle, 0x2C, buffers[currentframe],
527 _nb_components * num_leds_per_strip * 8 * 3 *
529 __OFFSET + __OFFSET_END);
531 currentframe = (currentframe + 1) % 2;
535static bool IRAM_ATTR flush_ready(esp_lcd_panel_io_handle_t panel_io,
536 esp_lcd_panel_io_event_data_t *edata,
539 isDisplaying =
false;
540 I2SClocklessLedDriveresp32S3 *cont =
541 (I2SClocklessLedDriveresp32S3 *)user_ctx;
544 portBASE_TYPE HPTaskAwoken = 0;
546 xSemaphoreGiveFromISR(I2SClocklessLedDriverS3_sem, &HPTaskAwoken);
547 if (HPTaskAwoken == pdTRUE)
548 portYIELD_FROM_ISR(HPTaskAwoken);
553#pragma GCC diagnostic pop
557#pragma pop_macro("AA")
558#pragma pop_macro("CC")
559#pragma pop_macro("FF")
560#pragma pop_macro("FF2")
UISlider brightness("Brightness", 128, 0, 255, 1)