pre-merge

cleanup:
- version increase
- clean up debug messages
- minor fixes in platformio.ini
- fix compilation with -D WLED_DISABLE_2D

helping the compiler to optimize:
- a few more __attribute__((pure))
- fx.cpp marked a few local functions as "static"
This commit is contained in:
Frank
2023-07-13 19:58:48 +02:00
parent 3295579e05
commit 9a3a97eff1
7 changed files with 35 additions and 30 deletions

View File

@@ -887,6 +887,7 @@ build_flags_S =
-Wno-attributes -Wno-unused-variable -Wno-unused-function -Wno-deprecated-declarations ;disables some stupid warnings -Wno-attributes -Wno-unused-variable -Wno-unused-function -Wno-deprecated-declarations ;disables some stupid warnings
;-D WLED_DISABLE_BROWNOUT_DET ; enable if you get "brownout detected" errors at startup ;-D WLED_DISABLE_BROWNOUT_DET ; enable if you get "brownout detected" errors at startup
-D WLED_USE_MY_CONFIG -D WLED_USE_MY_CONFIG
; -D WLED_DISABLE_2D ;; un-comment to build a firmware without 2D matrix support
; -D WLED_USE_CIE_BRIGHTNESS_TABLE ;; experimental: use different color / brightness lookup table ; -D WLED_USE_CIE_BRIGHTNESS_TABLE ;; experimental: use different color / brightness lookup table
-D USERMOD_AUDIOREACTIVE -D USERMOD_AUDIOREACTIVE
-D UM_AUDIOREACTIVE_USE_NEW_FFT ; use latest (upstream) FFTLib, instead of older library modified by blazoncek. Slightly faster, more accurate, needs 2KB RAM extra -D UM_AUDIOREACTIVE_USE_NEW_FFT ; use latest (upstream) FFTLib, instead of older library modified by blazoncek. Slightly faster, more accurate, needs 2KB RAM extra
@@ -1009,6 +1010,7 @@ build_flags = ${common.build_flags} ${esp32.build_flagsV4} ${common_mm.build_fla
-Wno-misleading-indentation -Wno-format-truncation -Wno-misleading-indentation -Wno-format-truncation
-Wshadow=compatible-local ;; emit warning in case a local variable "shadows" another local one -Wshadow=compatible-local ;; emit warning in case a local variable "shadows" another local one
;-Wstack-usage=2732 ;; warn if a function needs more that 30% of availeable stack ("stack usage might be unbounded", "stack usage is 2824 bytes") ;-Wstack-usage=2732 ;; warn if a function needs more that 30% of availeable stack ("stack usage might be unbounded", "stack usage is 2824 bytes")
;-Wsuggest-attribute=const -Wsuggest-attribute=pure ;; ask compiler for hints on attributes
-D WLED_ENABLE_DMX_INPUT -D WLED_ENABLE_DMX_INPUT
lib_deps = ${esp32.lib_depsV4} ${common_mm.lib_deps_S} lib_deps = ${esp32.lib_depsV4} ${common_mm.lib_deps_S}
https://github.com/someweisguy/esp_dmx.git#v3.0.2-beta ;; for DMX_INPUT https://github.com/someweisguy/esp_dmx.git#v3.0.2-beta ;; for DMX_INPUT
@@ -1124,7 +1126,7 @@ build_unflags = ${common.build_unflags}
-D CORE_DEBUG_LEVEL=0 -D CORE_DEBUG_LEVEL=0
build_flags = ${esp32_4MB_M_base.build_flags} build_flags = ${esp32_4MB_M_base.build_flags}
${Debug_Flags.build_flags} ${Debug_Flags.build_flags}
-D WLED_DEBUG_HEAP ;; WLEDMM enable heap debugging ; -D WLED_DEBUG_HEAP ;; WLEDMM enable heap debugging (needs newer framework versions)
-D CORE_DEBUG_LEVEL=2 ;; 2=warning -D CORE_DEBUG_LEVEL=2 ;; 2=warning
-D WLED_RELEASE_NAME=esp32_16MB_M_debug -D WLED_RELEASE_NAME=esp32_16MB_M_debug
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder

View File

@@ -214,9 +214,11 @@ float ARTI::arti_external_function(uint8_t function, float par1, float par2, flo
case F_millis: case F_millis:
return millis(); return millis();
#ifndef WLED_DISABLE_2D
case F_jsonToPixels: case F_jsonToPixels:
SEGMENT.jsonToPixels(SEGMENT.name,(uint8_t)par1); SEGMENT.jsonToPixels(SEGMENT.name,(uint8_t)par1);
return floatNull; return floatNull;
#endif
default: {} default: {}
} }

View File

@@ -37,12 +37,12 @@
#define indexToVStrip(index, stripNr) ((index) | (int((stripNr)+1)<<16)) #define indexToVStrip(index, stripNr) ((index) | (int((stripNr)+1)<<16))
// effect utility functions // effect utility functions
uint8_t sin_gap(uint16_t in) { static uint8_t sin_gap(uint16_t in) {
if (in & 0x100) return 0; if (in & 0x100) return 0;
return sin8(in + 192); // correct phase shift of sine so that it starts and stops at 0 return sin8(in + 192); // correct phase shift of sine so that it starts and stops at 0
} }
uint16_t triwave16(uint16_t in) { static uint16_t triwave16(uint16_t in) {
if (in < 0x8000) return in *2; if (in < 0x8000) return in *2;
return 0xFFFF - (in - 0x8000)*2; return 0xFFFF - (in - 0x8000)*2;
} }
@@ -54,7 +54,7 @@ uint16_t triwave16(uint16_t in) {
* @param attdec attac & decay, max. pulsewidth / 2 * @param attdec attac & decay, max. pulsewidth / 2
* @returns signed waveform value * @returns signed waveform value
*/ */
int8_t tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) { static int8_t tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) {
int8_t a = 127; int8_t a = 127;
if (x > 127) { if (x > 127) {
a = -127; a = -127;

View File

@@ -97,7 +97,6 @@ void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn.
assuming each segment uses the same amount of data. 256 for ESP8266, 640 for ESP32. */ assuming each segment uses the same amount of data. 256 for ESP8266, 640 for ESP32. */
#define FAIR_DATA_PER_SEG (MAX_SEGMENT_DATA / strip.getMaxSegments()) #define FAIR_DATA_PER_SEG (MAX_SEGMENT_DATA / strip.getMaxSegments())
//#define MIN_SHOW_DELAY (_frametime < 16 ? 8 : 15)
#define MIN_SHOW_DELAY (_frametime < 16 ? (_frametime <8? (_frametime <7? (_frametime <6 ? 2 :3) :4) : 8) : 15) // WLEDMM support higher framerates (up to 250fps) #define MIN_SHOW_DELAY (_frametime < 16 ? (_frametime <8? (_frametime <7? (_frametime <6 ? 2 :3) :4) : 8) : 15) // WLEDMM support higher framerates (up to 250fps)
#define NUM_COLORS 3 /* number of colors per segment */ #define NUM_COLORS 3 /* number of colors per segment */
@@ -502,7 +501,7 @@ typedef struct Segment {
Segment(Segment &&orig) noexcept; // move constructor Segment(Segment &&orig) noexcept; // move constructor
~Segment() { ~Segment() {
//#ifdef WLED_DEBUG #ifdef WLED_DEBUG
if(canUseSerial()) { if(canUseSerial()) {
Serial.print(F("Destroying segment:")); Serial.print(F("Destroying segment:"));
if (name) Serial.printf(" name=%s (%p)", name, name); if (name) Serial.printf(" name=%s (%p)", name, name);
@@ -510,7 +509,7 @@ typedef struct Segment {
if (ledsrgb) Serial.printf(" [%sledsrgb %u bytes]", Segment::_globalLeds ? "global ":"",length()*sizeof(CRGB)); if (ledsrgb) Serial.printf(" [%sledsrgb %u bytes]", Segment::_globalLeds ? "global ":"",length()*sizeof(CRGB));
Serial.println(); Serial.println();
} }
//#endif #endif
// WLEDMM only delete segments when they are not in use // WLEDMM only delete segments when they are not in use
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
@@ -603,8 +602,8 @@ typedef struct Segment {
void addPixelColor(int n, CRGB c, bool fast = false) { addPixelColor(n, RGBW32(c.r,c.g,c.b,0), fast); } // automatically inline void addPixelColor(int n, CRGB c, bool fast = false) { addPixelColor(n, RGBW32(c.r,c.g,c.b,0), fast); } // automatically inline
void fadePixelColor(uint16_t n, uint8_t fade); void fadePixelColor(uint16_t n, uint8_t fade);
uint8_t get_random_wheel_index(uint8_t pos); uint8_t get_random_wheel_index(uint8_t pos);
uint32_t __attribute__((pure)) color_from_palette(uint_fast16_t, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri = 255); uint32_t __attribute__((pure)) color_from_palette(uint_fast16_t, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri = 255);
uint32_t color_wheel(uint8_t pos); uint32_t __attribute__((pure)) color_wheel(uint8_t pos);
// 2D matrix // 2D matrix
inline uint16_t virtualWidth() const { // WLEDMM use fast types, and make function inline inline uint16_t virtualWidth() const { // WLEDMM use fast types, and make function inline
@@ -762,9 +761,9 @@ class WS2812FX { // 96 bytes
} }
~WS2812FX() { ~WS2812FX() {
//#ifdef WLED_DEBUG #ifdef WLED_DEBUG
if (Serial) Serial.println(F("~WS2812FX destroying strip.")); // WLEDMM can't use DEBUG_PRINTLN here if (Serial) Serial.println(F("~WS2812FX destroying strip.")); // WLEDMM can't use DEBUG_PRINTLN here
//#endif #endif
if (customMappingTable) delete[] customMappingTable; if (customMappingTable) delete[] customMappingTable;
_mode.clear(); _mode.clear();
_modeData.clear(); _modeData.clear();
@@ -853,7 +852,7 @@ class WS2812FX { // 96 bytes
ablMilliampsMax, ablMilliampsMax,
currentMilliamps, currentMilliamps,
getLengthPhysical(void), getLengthPhysical(void),
getLengthTotal(void), // will include virtual/nonexistent pixels in matrix __attribute__((pure)) getLengthTotal(void), // will include virtual/nonexistent pixels in matrix //WLEDMM attribute added
getFps(); getFps();
inline uint16_t getFrameTime(void) { return _frametime; } inline uint16_t getFrameTime(void) { return _frametime; }

View File

@@ -79,7 +79,7 @@ void WS2812FX::setUpMatrix() {
if ((size > 0) && (customMappingTable == nullptr)) { // second try if ((size > 0) && (customMappingTable == nullptr)) { // second try
DEBUG_PRINTLN("setUpMatrix: trying to get fresh memory block."); DEBUG_PRINTLN("setUpMatrix: trying to get fresh memory block.");
customMappingTable = (uint16_t*) calloc(size, sizeof(uint16_t)); customMappingTable = (uint16_t*) calloc(size, sizeof(uint16_t));
if (customMappingTable == nullptr) DEBUG_PRINTLN("setUpMatrix: alloc failed"); if (customMappingTable == nullptr) USER_PRINTLN("setUpMatrix: alloc failed");
} }
if (customMappingTable != nullptr) customMappingTableSize = size; if (customMappingTable != nullptr) customMappingTableSize = size;
} }
@@ -157,7 +157,7 @@ void WS2812FX::setUpMatrix() {
#endif #endif
} else { // memory allocation error } else { // memory allocation error
customMappingTableSize = 0; customMappingTableSize = 0;
DEBUG_PRINTLN(F("Ledmap alloc error.")); USER_PRINTLN(F("Ledmap alloc error."));
isMatrix = false; isMatrix = false;
panels = 0; panels = 0;
panel.clear(); panel.clear();

View File

@@ -94,7 +94,7 @@ uint16_t Segment::maxHeight = 1;
// copy constructor - creates a new segment by copy from orig, but does not copy buffers. Does not modify orig! // copy constructor - creates a new segment by copy from orig, but does not copy buffers. Does not modify orig!
Segment::Segment(const Segment &orig) { Segment::Segment(const Segment &orig) {
USER_PRINTLN(F("-- Copy segment constructor --")); DEBUG_PRINTLN(F("-- Copy segment constructor --"));
memcpy((void*)this, (void*)&orig, sizeof(Segment)); //WLEDMM copy to this memcpy((void*)this, (void*)&orig, sizeof(Segment)); //WLEDMM copy to this
transitional = false; // copied segment cannot be in transition transitional = false; // copied segment cannot be in transition
name = nullptr; name = nullptr;
@@ -114,8 +114,7 @@ Segment::Segment(const Segment &orig) {
void Segment::allocLeds() { void Segment::allocLeds() {
size_t size = sizeof(CRGB)*max((size_t) length(), ledmapMaxSize); //TroyHack size_t size = sizeof(CRGB)*max((size_t) length(), ledmapMaxSize); //TroyHack
if ((size < sizeof(CRGB)) || (size > 164000)) { //softhack too small (<3) or too large (>160Kb) if ((size < sizeof(CRGB)) || (size > 164000)) { //softhack too small (<3) or too large (>160Kb)
USER_PRINTF("allocLeds warning: size == %u !!\n", size); DEBUG_PRINTF("allocLeds warning: size == %u !!\n", size);
USER_FLUSH();
if (ledsrgb && (ledsrgbSize == 0)) { if (ledsrgb && (ledsrgbSize == 0)) {
USER_PRINTLN("allocLeds warning: ledsrgbSize == 0 but ledsrgb!=NULL"); USER_PRINTLN("allocLeds warning: ledsrgbSize == 0 but ledsrgb!=NULL");
free(ledsrgb); ledsrgb=nullptr; free(ledsrgb); ledsrgb=nullptr;
@@ -135,7 +134,7 @@ void Segment::allocLeds() {
// move constructor --> moves everything (including buffer) from orig to this // move constructor --> moves everything (including buffer) from orig to this
Segment::Segment(Segment &&orig) noexcept { Segment::Segment(Segment &&orig) noexcept {
USER_PRINTLN(F("-- Move segment constructor --")); DEBUG_PRINTLN(F("-- Move segment constructor --"));
memcpy((void*)this, (void*)&orig, sizeof(Segment)); memcpy((void*)this, (void*)&orig, sizeof(Segment));
orig.transitional = false; // old segment cannot be in transition any more orig.transitional = false; // old segment cannot be in transition any more
orig.name = nullptr; orig.name = nullptr;
@@ -149,7 +148,7 @@ Segment::Segment(Segment &&orig) noexcept {
// copy assignment --> overwrite segment withg orig - deletes old buffers in "this", but does not change orig! // copy assignment --> overwrite segment withg orig - deletes old buffers in "this", but does not change orig!
Segment& Segment::operator= (const Segment &orig) { Segment& Segment::operator= (const Segment &orig) {
USER_PRINTLN(F("-- Copy-assignment segment --")); DEBUG_PRINTLN(F("-- Copy-assignment segment --"));
if (this != &orig) { if (this != &orig) {
// clean destination // clean destination
transitional = false; // copied segment cannot be in transition transitional = false; // copied segment cannot be in transition
@@ -182,7 +181,7 @@ Segment& Segment::operator= (const Segment &orig) {
// move assignment --> moves everything (including buffers) from "orig" to "this" // move assignment --> moves everything (including buffers) from "orig" to "this"
Segment& Segment::operator= (Segment &&orig) noexcept { Segment& Segment::operator= (Segment &&orig) noexcept {
USER_PRINTLN(F("-- Move-assignment segment --")); DEBUG_PRINTLN(F("-- Move-assignment segment --"));
if (this != &orig) { if (this != &orig) {
transitional = false; // just temporary transitional = false; // just temporary
if (name) { delete[] name; name = nullptr; } // free old name if (name) { delete[] name; name = nullptr; } // free old name
@@ -257,7 +256,8 @@ void Segment::setUpLeds() {
ledsrgbSize = length() * sizeof(CRGB); // also set this when using global leds. ledsrgbSize = length() * sizeof(CRGB); // also set this when using global leds.
//USER_PRINTF("\nsetUpLeds() Global LEDs: startX=%d stopx=%d startY=%d stopy=%d maxwidth=%d; length=%d, size=%d\n\n", start, stop, startY, stopY, Segment::maxWidth, length(), ledsrgbSize/3); //USER_PRINTF("\nsetUpLeds() Global LEDs: startX=%d stopx=%d startY=%d stopy=%d maxwidth=%d; length=%d, size=%d\n\n", start, stop, startY, stopY, Segment::maxWidth, length(), ledsrgbSize/3);
#else #else
leds = &Segment::_globalLeds[start]; ledsrgb = &Segment::_globalLeds[start];
ledsrgbSize = length() * sizeof(CRGB); // also set this when using global leds.
#endif #endif
} else if (length() > 0) { //WLEDMM we always want a new buffer //softhack007 quickfix - avoid malloc(0) which is undefined behaviour (should not happen, but i've seen it) } else if (length() > 0) { //WLEDMM we always want a new buffer //softhack007 quickfix - avoid malloc(0) which is undefined behaviour (should not happen, but i've seen it)
//#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) //#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
@@ -630,12 +630,12 @@ class JMapC {
char previousSegmentName[50] = ""; char previousSegmentName[50] = "";
~JMapC() { ~JMapC() {
USER_PRINTLN("~JMapC"); DEBUG_PRINTLN("~JMapC");
deletejVectorMap(); deletejVectorMap();
} }
void deletejVectorMap() { void deletejVectorMap() {
if (jVectorMap.size() > 0) { if (jVectorMap.size() > 0) {
USER_PRINTLN("delete jVectorMap"); DEBUG_PRINTLN("delete jVectorMap");
for (size_t i=0; i<jVectorMap.size(); i++) for (size_t i=0; i<jVectorMap.size(); i++)
if (jVectorMap[i].array) { delete[] jVectorMap[i].array; jVectorMap[i].array = nullptr; } // softhack007 quickfix for memory leak if (jVectorMap[i].array) { delete[] jVectorMap[i].array; jVectorMap[i].array = nullptr; } // softhack007 quickfix for memory leak
jVectorMap.clear(); jVectorMap.clear();
@@ -679,7 +679,7 @@ class JMapC {
else if (SEGMENT.name != nullptr && strcmp(SEGMENT.name, previousSegmentName) != 0) { else if (SEGMENT.name != nullptr && strcmp(SEGMENT.name, previousSegmentName) != 0) {
uint32_t dataSize = 0; uint32_t dataSize = 0;
deletejVectorMap(); deletejVectorMap();
USER_PRINT("New "); USER_PRINTLN(SEGMENT.name); DEBUG_PRINT("New "); DEBUG_PRINTLN(SEGMENT.name);
char jMapFileName[50]; char jMapFileName[50];
strcpy(jMapFileName, "/"); strcpy(jMapFileName, "/");
strcat(jMapFileName, SEGMENT.name); strcat(jMapFileName, SEGMENT.name);
@@ -699,6 +699,7 @@ class JMapC {
if (err) if (err)
{ {
USER_PRINTF("deserializeJson() of parseTree failed with code %s\n", err.c_str()); USER_PRINTF("deserializeJson() of parseTree failed with code %s\n", err.c_str());
USER_FLUSH();
if (SEGMENT.name) delete[] SEGMENT.name; SEGMENT.name = nullptr; //need to clear the name as otherwise continuously loaded // softhack007 avoid deleting nullptr if (SEGMENT.name) delete[] SEGMENT.name; SEGMENT.name = nullptr; //need to clear the name as otherwise continuously loaded // softhack007 avoid deleting nullptr
return; return;
} }
@@ -752,7 +753,7 @@ class JMapC {
//WLEDMM jMap //WLEDMM jMap
void Segment::createjMap() { void Segment::createjMap() {
if (!jMap) { if (!jMap) {
USER_PRINTLN("createjMap"); DEBUG_PRINTLN("createjMap");
jMap = new JMapC(); jMap = new JMapC();
} }
} }
@@ -761,7 +762,7 @@ void Segment::createjMap() {
void Segment::deletejMap() { void Segment::deletejMap() {
//Should be called from ~Segment but causes crash (and ~Segment is called quite often...) //Should be called from ~Segment but causes crash (and ~Segment is called quite often...)
if (jMap) { if (jMap) {
USER_PRINTLN("deletejMap"); DEBUG_PRINTLN("deletejMap");
delete (JMapC *)jMap; jMap = nullptr; delete (JMapC *)jMap; jMap = nullptr;
} }
} }
@@ -1991,7 +1992,7 @@ void WS2812FX::restartRuntime() {
} }
void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
USER_PRINTF("resetSegments %d %dx%d\n", boundsOnly, Segment::maxWidth, Segment::maxHeight); DEBUG_PRINTF("resetSegments %d %dx%d\n", boundsOnly, Segment::maxWidth, Segment::maxHeight);
if (!boundsOnly) { if (!boundsOnly) {
_segments.clear(); // destructs all Segment as part of clearing _segments.clear(); // destructs all Segment as part of clearing
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
@@ -2328,7 +2329,7 @@ bool WS2812FX::deserializeMap(uint8_t n) {
loadedLedmap = n; loadedLedmap = n;
f.close(); f.close();
DEBUG_PRINTF("Custom ledmap: %d\n", loadedLedmap); USER_PRINTF("Custom ledmap: %d\n", loadedLedmap);
#ifdef WLED_DEBUG_MAPS #ifdef WLED_DEBUG_MAPS
for (uint16_t j=0; j<customMappingSize; j++) { // fixing a minor warning: declaration of 'i' shadows a previous local for (uint16_t j=0; j<customMappingSize; j++) { // fixing a minor warning: declaration of 'i' shadows a previous local
if (!(j%Segment::maxWidth)) DEBUG_PRINTLN(); if (!(j%Segment::maxWidth)) DEBUG_PRINTLN();
@@ -2338,7 +2339,8 @@ bool WS2812FX::deserializeMap(uint8_t n) {
#endif #endif
} else { // memory allocation error } else { // memory allocation error
customMappingTableSize = 0; customMappingTableSize = 0;
DEBUG_PRINTLN(F("Deserializemap: Ledmap alloc error.")); USER_PRINTLN(F("Deserializemap: Ledmap alloc error."));
USER_FLUSH();
} }
releaseJSONBufferLock(); releaseJSONBufferLock();

View File

@@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2307100 #define VERSION 2307130
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG