Skip to content

Commit

Permalink
Use espShow() directly for WS2812 LEDs on ESP32 chips
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Jul 28, 2024
1 parent 041be66 commit 642449d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/lib/DenkoLEDArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//
#ifdef DENKO_LED_WS2812
#include <Adafruit_NeoPixel.h>
#ifdef ESP32
#include <esp.c>
#endif
#endif

//
Expand All @@ -22,20 +25,27 @@
// auxMsg[4+] = Raw pixel data, already in correct byte order (GRB, RGB, etc.).
//
void Denko::showLEDArray() {
// Setup a new LED array object.
Adafruit_NeoPixel ledArray(val, pin, NEO_GRB + NEO_KHZ800);
ledArray.begin();
// Avoid memcpy on ESP32 by calling espShow() directly.
#ifdef ESP32
espShow(pin, &auxMsg[4], val, true);

// Copy LED data into the pixel buffer.
memcpy(ledArray.getPixels(), &auxMsg[4], val);
// memcpy method for everything else.
#else
// Setup a new LED array object.
Adafruit_NeoPixel ledArray(val, pin, NEO_GRB + NEO_KHZ800);
ledArray.begin();

// ATmega4809 still needs this delay to avoid corrupt data. Not sure why.
#if defined(__AVR_ATmega4809__)
microDelay(64);
#endif
// Copy LED data into the pixel buffer.
memcpy(ledArray.getPixels(), &auxMsg[4], val);

// Write the pixel buffer to the array.
ledArray.show();
// ATmega4809 still needs this delay to avoid corrupt data. Not sure why.
#if defined(__AVR_ATmega4809__)
microDelay(64);
#endif

// Write the pixel buffer to the array.
ledArray.show();
#endif

// Tell the computer to resume sending data.
sendReady();
Expand Down

0 comments on commit 642449d

Please sign in to comment.