Skip to content

Commit

Permalink
Tweak Virtual driver settings, no flickering on software mapping
Browse files Browse the repository at this point in the history
pio.ini
- rename STARLIGHT_ICVLD variables
- move ICLD to esp32 (but commented)

LedLayer
- use STARLIGHT_MAXLEDS instead of  NUM_VLEDS_Max

LedModFixture
- tweak icvld values
- mapfunction only if mapping mode (WIP)
- driver.setGamma !!! (Check values)
  • Loading branch information
ewowi committed Oct 31, 2024
1 parent a7a6667 commit 508ee1a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 81 deletions.
12 changes: 6 additions & 6 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ lib_deps =
[STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER]
build_flags =
-D STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER
-D SCVD_CLOCK_PIN=26
-D SCVD_LATCH_PIN=27
-D NBIS2SERIALPINS=6 ;nr of shift registers (6 * 8 * 256 = 12288)
-D SVCD_PINS=14,12,13,25,33,32
-D STARLIGHT_ICVLD_CLOCK_PIN=26
-D STARLIGHT_ICVLD_LATCH_PIN=27
-D NBIS2SERIALPINS=6 ;nr of shift registers (6 * 8 * 256 = 12288) I2SClocklessVirtualLedDriver variable!
-D STARLIGHT_ICVLD_PINS=14,12,13,25,33,32 ; must be 6, see initLeds
lib_deps =
; https://github.com/hpwit/I2SClocklessVirtualLedDriver#9464ff0 ;#integration at 20241010 (latest at 20241023)
https://github.com/ewowi/I2SClocklessVirtualLedDriver#9c19699 ;temp until PR processed
Expand Down Expand Up @@ -186,8 +186,10 @@ build_flags =
${env.build_flags}
-D CONFIG_IDF_TARGET_ESP32=1
-D ARDUINO_USB_CDC_ON_BOOT=0 ; Make sure that the right HardwareSerial driver is picked in arduino-esp32 (needed on "classic ESP32")
; ${STARLIGHT_CLOCKLESS_LED_DRIVER.build_flags} ; temporary here, until there is one driver for s3 and non s3
lib_deps =
${env.lib_deps}
; ${STARLIGHT_CLOCKLESS_LED_DRIVER.lib_deps} ; temporary here, until there is one driver for s3 and non s3

; ;LEDs specific builds
[env:esp32devICVLD]
Expand All @@ -199,12 +201,10 @@ build_flags =
${env.build_flags}
-D CONFIG_IDF_TARGET_ESP32=1
-D ARDUINO_USB_CDC_ON_BOOT=0 ; Make sure that the right HardwareSerial driver is picked in arduino-esp32 (needed on "classic ESP32")
; ${STARLIGHT_CLOCKLESS_LED_DRIVER.build_flags} ; temporary here, until there is one driver for s3 and non s3
${STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER.build_flags} ; temporary here, until there is one driver for s3 and non s3
-D STARLIGHT_MAXLEDS=12288 ;LEDs specific
lib_deps =
${env.lib_deps}
; ${STARLIGHT_CLOCKLESS_LED_DRIVER.lib_deps} ; temporary here, until there is one driver for s3 and non s3
${STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER.lib_deps} ; temporary here, until there is one driver for s3 and non s3

; https://github.com/platformio/platform-espressif32/issues/1360
Expand Down
14 changes: 8 additions & 6 deletions src/App/LedLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ void LedsLayer::setPixelColor(int indexV, CRGB color) {
break;
}
}
else if (indexV < NUM_LEDS_Max) //no projection
else if (indexV < STARLIGHT_MAXLEDS) //no projection
fix->ledsP[indexV] = fix->pixelsToBlend[indexV]?blend(color, fix->ledsP[indexV], fix->globalBlend): color;
// some operations will go out of bounds e.g. VUMeter, uncomment below lines if you wanna test on a specific effect
// else //if (indexV != UINT16_MAX) //assuming UINT16_MAX is set explicitly (e.g. in XYZ)
// ppf(" dev sPC %d >= %d", indexV, NUM_LEDS_Max);
// ppf(" dev sPC %d >= %d", indexV, STARLIGHT_MAXLEDS);
}

void LedsLayer::setPixelColorPal(int indexV, uint8_t palIndex, uint8_t palBri) {
Expand Down Expand Up @@ -193,11 +193,11 @@ CRGB LedsLayer::getPixelColor(int indexV) {
break;
}
}
else if (indexV < NUM_LEDS_Max) //no mapping
else if (indexV < STARLIGHT_MAXLEDS) //no mapping
return fix->ledsP[indexV];
else {
// some operations will go out of bounds e.g. VUMeter, uncomment below lines if you wanna test on a specific effect
// ppf(" dev gPC %d >= %d", indexV, NUM_LEDS_Max);
// ppf(" dev gPC %d >= %d", indexV, STARLIGHT_MAXLEDS);
return CRGB::Black;
}
}
Expand Down Expand Up @@ -343,8 +343,8 @@ void LedsLayer::fill_rainbow(uint8_t initialhue, uint8_t deltahue) {
mdl->getValueRowNr = UINT8_MAX; // end of run projection functions in the right rowNr context

if (indexV != UINT16_MAX) {
if (indexV >= nrOfLeds || indexV >= NUM_VLEDS_Max)
ppf("dev leds[%d] pre indexV too high %d>=%d or %d (m:%d p:%d) p:%d,%d,%d s:%d,%d,%d\n", rowNr, indexV, nrOfLeds, NUM_VLEDS_Max, mappingTableSizeUsed, fix->indexP, pixel.x, pixel.y, pixel.z, size.x, size.y, size.z);
if (indexV >= nrOfLeds || indexV >= STARLIGHT_MAXLEDS)
ppf("dev leds[%d] pre indexV too high %d>=%d or %d (m:%d p:%d) p:%d,%d,%d s:%d,%d,%d\n", rowNr, indexV, nrOfLeds, STARLIGHT_MAXLEDS, mappingTableSizeUsed, fix->indexP, pixel.x, pixel.y, pixel.z, size.x, size.y, size.z);
else {

//create new physMaps if needed
Expand All @@ -362,6 +362,8 @@ void LedsLayer::fill_rainbow(uint8_t initialhue, uint8_t deltahue) {
// ppf("mapping b:%d t:%d V:%d\n", indexV, indexP, mappingTableSizeUsed);
} //indexV not too high
} //indexV
else
ppf("dev check this case indexV != UINT16_MAX %d\n", indexV);

} //if x,y,z between start and end
} //if projection && doMap
Expand Down
2 changes: 0 additions & 2 deletions src/App/LedLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#define STARLIGHT_MAXLEDS 8192 //any board can do this
#endif

#define NUM_VLEDS_Max STARLIGHT_MAXLEDS

class LedsLayer; //forward

#define _1D 1
Expand Down
6 changes: 3 additions & 3 deletions src/App/LedModEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ inline uint16_t getRGBWsize(uint16_t nleds){
}});
currentVar["dash"] = true;

ui->initCoord3D(tableVar, "start", {0,0,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
ui->initCoord3D(tableVar, "start", {0,0,0}, 0, STARLIGHT_MAXLEDS, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case onSetValue:
//is this needed?
for (size_t rowNr = 0; rowNr < fix->layers.size(); rowNr++) {
Expand All @@ -311,7 +311,7 @@ inline uint16_t getRGBWsize(uint16_t nleds){
default: return false;
}});

ui->initCoord3D(tableVar, "middle", {0,0,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
ui->initCoord3D(tableVar, "middle", {0,0,0}, 0, STARLIGHT_MAXLEDS, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case onSetValue:
//is this needed?
for (size_t rowNr = 0; rowNr < fix->layers.size(); rowNr++) {
Expand All @@ -338,7 +338,7 @@ inline uint16_t getRGBWsize(uint16_t nleds){
default: return false;
}});

ui->initCoord3D(tableVar, "end", {8,8,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
ui->initCoord3D(tableVar, "end", {8,8,0}, 0, STARLIGHT_MAXLEDS, false, [this](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case onSetValue:
//is this needed?
for (size_t rowNr = 0; rowNr < fix->layers.size(); rowNr++) {
Expand Down
80 changes: 43 additions & 37 deletions src/App/LedModFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,39 @@
#define PACKAGE_SIZE 5120 //4096 is not ideal as also header info, multiples of 1024 sounds good...

#ifdef STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER
uint16_t mapfunction(uint16_t pos)
{
int panelnumber = pos / 256;
int datainpanel = pos % 256;
int Xp = 7 - panelnumber % 8;
#if (I2S_MAPPING_MODE & (I2S_MAPPING_MODE_OPTION_MAPPING_IN_MEMORY | I2S_MAPPING_MODE_OPTION_MAPPING_SOFTWARE)) > 0

//fix for ewowi panels
Xp=Xp+1;
if (Xp==8) {Xp=0;}
uint16_t mapfunction(uint16_t pos)
{
int panelnumber = pos / 256;
int datainpanel = pos % 256;
int Xp = 7 - panelnumber % 8;

int yp = panelnumber / 8;
int X = Xp; //panel on the x axis
int Y = yp; //panel on the y axis
//fix for ewowi panels
Xp=Xp+1;
if (Xp==8) {Xp=0;}

int y = datainpanel % 16;
int x = datainpanel / 16;
int yp = panelnumber / 8;
int X = Xp; //panel on the x axis
int Y = yp; //panel on the y axis

if (x % 2 == 0) //serpentine
{
Y = Y * 16 + y;
X = X * 16 + x;
}
else
{
Y = Y * 16 + 16 -y-1;
X = X * 16 + x;
}
int y = datainpanel % 16;
int x = datainpanel / 16;

return (95-Y) * 16 * 8 + (127-X);
}
if (x % 2 == 0) //serpentine
{
Y = Y * 16 + y;
X = X * 16 + x;
}
else
{
Y = Y * 16 + 16 -y-1;
X = X * 16 + x;
}

return (95-Y) * 16 * 8 + (127-X);
}
#endif
#endif

void LedModFixture::setup() {
Expand Down Expand Up @@ -238,13 +241,13 @@
default: return false;
}}); //fixture

ui->initCoord3D(currentVar, "size", &fixSize, 0, NUM_LEDS_Max, true, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
ui->initCoord3D(currentVar, "size", &fixSize, 0, STARLIGHT_MAXLEDS, true, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
default: return false;
}});

ui->initNumber(currentVar, "count", &nrOfLeds, 0, UINT16_MAX, true, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case onUI:
web->addResponse(var, "comment", "Max %d", NUM_LEDS_Max, 0); //0 is to force format overload used
web->addResponse(var, "comment", "Max %d", STARLIGHT_MAXLEDS, 0); //0 is to force format overload used
return true;
default: return false;
}});
Expand Down Expand Up @@ -707,10 +710,13 @@
// driver.setBrightness(setMaxPowerBrightnessFactor / 256); //not brighter then the set limit (WIP)
}
#elif STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER
int svcd_pins[6] = { SVCD_PINS };
driver.initled(ledsP, svcd_pins, SCVD_CLOCK_PIN, SCVD_LATCH_PIN);
int pins[6] = { STARLIGHT_ICVLD_PINS };
driver.initled(ledsP, pins, STARLIGHT_ICVLD_CLOCK_PIN, STARLIGHT_ICVLD_LATCH_PIN);
// driver.enableShowPixelsOnCore(1);
// driver.setMapLed(&mapfunction);
#if (I2S_MAPPING_MODE & (I2S_MAPPING_MODE_OPTION_MAPPING_IN_MEMORY | I2S_MAPPING_MODE_OPTION_MAPPING_SOFTWARE)) > 0
driver.setMapLed(&mapfunction);
#endif
driver.setGamma(255.0/255.0, 176.0/255.0, 240.0/255.0);
driver.setBrightness(10);
#endif

Expand All @@ -726,7 +732,7 @@ void LedModFixture::addPixelsPre() {
if (pass == 1) {
fixSize = {0, 0, 0}; //start counting
nrOfLeds = 0; //start counting
} else if (nrOfLeds <= NUM_LEDS_Max) {
} else if (nrOfLeds <= STARLIGHT_MAXLEDS) {

// reset leds
uint8_t rowNr = 0;
Expand Down Expand Up @@ -781,9 +787,9 @@ void LedModFixture::addPixel(Coord3D pixel) {
// ppf(".");
fixSize = fixSize.maximum(pixel);
nrOfLeds++;
} else if (nrOfLeds <= NUM_LEDS_Max) {
} else if (nrOfLeds <= STARLIGHT_MAXLEDS) {

if (indexP < NUM_LEDS_Max) {
if (indexP < STARLIGHT_MAXLEDS) {

if (bytesPerPixel && doSendFixtureDefinition) {
//send pixel to ui ...
Expand Down Expand Up @@ -827,7 +833,7 @@ void LedModFixture::addPixel(Coord3D pixel) {
} //for layers
} //indexP < max
else
ppf("dev post indexP too high %d>=%d or %d p:%d,%d,%d\n", indexP, nrOfLeds, NUM_LEDS_Max, pixel.x, pixel.y, pixel.z);
ppf("dev post indexP too high %d>=%d or %d p:%d,%d,%d\n", indexP, nrOfLeds, STARLIGHT_MAXLEDS, pixel.x, pixel.y, pixel.z);

indexP++; //also increase if no buffer created
}
Expand All @@ -836,7 +842,7 @@ void LedModFixture::addPixel(Coord3D pixel) {
void LedModFixture::addPin(uint8_t pin) {
if (pass == 1) {
// ppf("addPin calc\n");
} else if (nrOfLeds <= NUM_LEDS_Max) {
} else if (nrOfLeds <= STARLIGHT_MAXLEDS) {
if (doAllocPins) {
//check if pin already allocated, if so, extend range in details
PinObject pinObject = pinsM->pinObjects[pin];
Expand Down Expand Up @@ -877,7 +883,7 @@ void LedModFixture::addPixelsPost() {
if (pass == 1) {
fixSize = fixSize / factor + Coord3D{1,1,1};
ppf("addPixelsPost(%d) size s:%d,%d,%d #:%d %d ms\n", pass, fixSize.x, fixSize.y, fixSize.z, nrOfLeds);
} else if (nrOfLeds <= NUM_LEDS_Max) {
} else if (nrOfLeds <= STARLIGHT_MAXLEDS) {

if (bytesPerPixel && doSendFixtureDefinition) {
if (wsBuf) {
Expand Down Expand Up @@ -918,7 +924,7 @@ void LedModFixture::addPixelsPost() {
pixelsToBlend.push_back(false);
}

ppf("addPixelsPost(%d) fixture.size = so:%d + l:(%d * %d) B %d ms\n", pass, sizeof(this), NUM_LEDS_Max, sizeof(CRGB), millis() - start); //56
ppf("addPixelsPost(%d) fixture.size = so:%d + l:(%d * %d) B %d ms\n", pass, sizeof(this), STARLIGHT_MAXLEDS, sizeof(CRGB), millis() - start); //56
}

if (pass == 2)
Expand Down
40 changes: 22 additions & 18 deletions src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,41 @@
#endif
#endif
#ifdef STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER
#define NUM_LEDS_PER_STRIP 256 //used in I2SClocklessVirtualLedDriver.h, should not be needed here...
//used in I2SClocklessVirtualLedDriver.h,
//see https://github.com/ewowi/I2SClocklessVirtualLedDriver read me
#define NUM_LEDS_PER_STRIP 256 // for I2S_MAPPING_MODE_OPTION_MAPPING_IN_MEMORY ...
#define CORE_DEBUG_LEVEL 1 //surpress ESP_LOGE compile error
#define USE_FASTLED //so CRGB is supported e.g. in initled
#define NB_DMA_BUFFER 10
#define BRIGHTNESS_BIT 5
#ifndef NBIS2SERIALPINS
#define USE_FASTLED //so CRGB is supported e.g. in initLed
#define __NB_DMA_BUFFER 10 //underscore ! default 2. Sometimes interrupts can distrub the pixel buffer calculations hence making some artifacts. A solution against that is to caculate several buffers in advance. BY defualt we have 2 dma buffers. this can be increase to cope with unwanted interupts.
#define __BRIGHTNESS_BIT 5 //underscore ! default 8. the max brightness will be 2^5=32 If you remember when I have discussed about the fact that the showPixels is not always occupied with gives time for other processes to run. Well the less time we 'spent' in buffer calcualtion the better.for instance if you do not use gamma calculation and you can cope with a brightness that is a power of 2:
#ifndef NBIS2SERIALPINS //no underscore !
#define NBIS2SERIALPINS 6 //6 shift registers
#endif
#ifndef SVCD_PINS
#define SVCD_PINS 14,12,13,25,33,32
#endif
// #include "esp_heap_caps.h"
#define I2S_MAPPING_MODE (I2S_MAPPING_MODE_OPTION_NONE) //works but mapping using mappingTable Needed
// #define I2S_MAPPING_MODE (I2S_MAPPING_MODE_OPTION_MAPPING_SOFTWARE) //works but flickering!
// #define I2S_MAPPING_MODE (I2S_MAPPING_MODE_OPTION_MAPPING_IN_MEMORY) //not working
// #define I2S_MAPPING_MODE (I2S_MAPPING_MODE_OPTION_NONE) //works but mapping using mappingTable Needed
#define I2S_MAPPING_MODE (I2S_MAPPING_MODE_OPTION_MAPPING_SOFTWARE) //works no flickering anymore (due to __NB_DMA_BUFFER)!
// #define I2S_MAPPING_MODE (I2S_MAPPING_MODE_OPTION_MAPPING_IN_MEMORY) //not working: IllegalInstruction Backtrace: 0x5515d133:0x3ffb1fc0 |<-CORRUPTED

#include "I2SClocklessVirtualLedDriver.h"
#ifndef SCVD_CLOCK_PIN
#define SCVD_CLOCK_PIN 26

//StarLight only
#ifndef STARLIGHT_ICVLD_PINS
#define STARLIGHT_ICVLD_PINS 14,12,13,25,33,32 // must be 6, see initLed
#endif
#ifndef SCVD_LATCH_PIN
#define SCVD_LATCH_PIN 27

#ifndef STARLIGHT_ICVLD_CLOCK_PIN
#define STARLIGHT_ICVLD_CLOCK_PIN 26
#endif
#ifndef STARLIGHT_ICVLD_LATCH_PIN
#define STARLIGHT_ICVLD_LATCH_PIN 27
#endif
#endif

#define NUM_LEDS_Max STARLIGHT_MAXLEDS

class LedModFixture: public SysModule {

public:

CRGB ledsP[NUM_LEDS_Max];
CRGB ledsP[STARLIGHT_MAXLEDS];

// CRGB *leds = nullptr;
// if (!leds)
Expand Down
Loading

0 comments on commit 508ee1a

Please sign in to comment.