From 9a3a97eff1e3cdb3643ea47a752aba10ffb5d412 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:58:48 +0200 Subject: [PATCH] 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" --- platformio.ini | 4 +++- usermods/artifx/arti_wled.h | 2 ++ wled00/FX.cpp | 6 +++--- wled00/FX.h | 15 +++++++-------- wled00/FX_2Dfcn.cpp | 4 ++-- wled00/FX_fcn.cpp | 32 +++++++++++++++++--------------- wled00/wled.h | 2 +- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/platformio.ini b/platformio.ini index d9bb0907..674217e1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -887,6 +887,7 @@ build_flags_S = -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_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 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 @@ -1009,6 +1010,7 @@ build_flags = ${common.build_flags} ${esp32.build_flagsV4} ${common_mm.build_fla -Wno-misleading-indentation -Wno-format-truncation -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") + ;-Wsuggest-attribute=const -Wsuggest-attribute=pure ;; ask compiler for hints on attributes -D WLED_ENABLE_DMX_INPUT lib_deps = ${esp32.lib_depsV4} ${common_mm.lib_deps_S} 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 build_flags = ${esp32_4MB_M_base.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 WLED_RELEASE_NAME=esp32_16MB_M_debug monitor_filters = esp32_exception_decoder diff --git a/usermods/artifx/arti_wled.h b/usermods/artifx/arti_wled.h index f905f743..8796e1c1 100644 --- a/usermods/artifx/arti_wled.h +++ b/usermods/artifx/arti_wled.h @@ -214,9 +214,11 @@ float ARTI::arti_external_function(uint8_t function, float par1, float par2, flo case F_millis: return millis(); +#ifndef WLED_DISABLE_2D case F_jsonToPixels: SEGMENT.jsonToPixels(SEGMENT.name,(uint8_t)par1); return floatNull; +#endif default: {} } diff --git a/wled00/FX.cpp b/wled00/FX.cpp index d2dcd814..dc786e54 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -37,12 +37,12 @@ #define indexToVStrip(index, stripNr) ((index) | (int((stripNr)+1)<<16)) // effect utility functions -uint8_t sin_gap(uint16_t in) { +static uint8_t sin_gap(uint16_t in) { if (in & 0x100) return 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; return 0xFFFF - (in - 0x8000)*2; } @@ -54,7 +54,7 @@ uint16_t triwave16(uint16_t in) { * @param attdec attac & decay, max. pulsewidth / 2 * @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; if (x > 127) { a = -127; diff --git a/wled00/FX.h b/wled00/FX.h index edcd3bcc..1175157e 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -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. */ #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 NUM_COLORS 3 /* number of colors per segment */ @@ -502,7 +501,7 @@ typedef struct Segment { Segment(Segment &&orig) noexcept; // move constructor ~Segment() { - //#ifdef WLED_DEBUG + #ifdef WLED_DEBUG if(canUseSerial()) { Serial.print(F("Destroying segment:")); 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)); Serial.println(); } - //#endif + #endif // WLEDMM only delete segments when they are not in use #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 fadePixelColor(uint16_t n, uint8_t fade); 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 color_wheel(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_wheel(uint8_t pos); // 2D matrix inline uint16_t virtualWidth() const { // WLEDMM use fast types, and make function inline @@ -762,9 +761,9 @@ class WS2812FX { // 96 bytes } ~WS2812FX() { - //#ifdef WLED_DEBUG + #ifdef WLED_DEBUG if (Serial) Serial.println(F("~WS2812FX destroying strip.")); // WLEDMM can't use DEBUG_PRINTLN here - //#endif + #endif if (customMappingTable) delete[] customMappingTable; _mode.clear(); _modeData.clear(); @@ -853,7 +852,7 @@ class WS2812FX { // 96 bytes ablMilliampsMax, currentMilliamps, 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(); inline uint16_t getFrameTime(void) { return _frametime; } diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 0556935c..1452de7d 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -79,7 +79,7 @@ void WS2812FX::setUpMatrix() { if ((size > 0) && (customMappingTable == nullptr)) { // second try DEBUG_PRINTLN("setUpMatrix: trying to get fresh memory block."); 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; } @@ -157,7 +157,7 @@ void WS2812FX::setUpMatrix() { #endif } else { // memory allocation error customMappingTableSize = 0; - DEBUG_PRINTLN(F("Ledmap alloc error.")); + USER_PRINTLN(F("Ledmap alloc error.")); isMatrix = false; panels = 0; panel.clear(); diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 21b199b1..b9938517 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -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! 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 transitional = false; // copied segment cannot be in transition name = nullptr; @@ -114,8 +114,7 @@ Segment::Segment(const Segment &orig) { void Segment::allocLeds() { 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) - USER_PRINTF("allocLeds warning: size == %u !!\n", size); - USER_FLUSH(); + DEBUG_PRINTF("allocLeds warning: size == %u !!\n", size); if (ledsrgb && (ledsrgbSize == 0)) { USER_PRINTLN("allocLeds warning: ledsrgbSize == 0 but ledsrgb!=NULL"); free(ledsrgb); ledsrgb=nullptr; @@ -135,7 +134,7 @@ void Segment::allocLeds() { // move constructor --> moves everything (including buffer) from orig to this Segment::Segment(Segment &&orig) noexcept { - USER_PRINTLN(F("-- Move segment constructor --")); + DEBUG_PRINTLN(F("-- Move segment constructor --")); memcpy((void*)this, (void*)&orig, sizeof(Segment)); orig.transitional = false; // old segment cannot be in transition any more 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! Segment& Segment::operator= (const Segment &orig) { - USER_PRINTLN(F("-- Copy-assignment segment --")); + DEBUG_PRINTLN(F("-- Copy-assignment segment --")); if (this != &orig) { // clean destination 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" Segment& Segment::operator= (Segment &&orig) noexcept { - USER_PRINTLN(F("-- Move-assignment segment --")); + DEBUG_PRINTLN(F("-- Move-assignment segment --")); if (this != &orig) { transitional = false; // just temporary 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. //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 - leds = &Segment::_globalLeds[start]; + ledsrgb = &Segment::_globalLeds[start]; + ledsrgbSize = length() * sizeof(CRGB); // also set this when using global leds. #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) //#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) @@ -630,12 +630,12 @@ class JMapC { char previousSegmentName[50] = ""; ~JMapC() { - USER_PRINTLN("~JMapC"); + DEBUG_PRINTLN("~JMapC"); deletejVectorMap(); } void deletejVectorMap() { if (jVectorMap.size() > 0) { - USER_PRINTLN("delete jVectorMap"); + DEBUG_PRINTLN("delete jVectorMap"); for (size_t i=0; i