const const const

adding hints for the compiler for optimization.
In case your custom build complains about "const", just remove the keyword. based on e82f38e277, but going further :-)

* "const" class functions : function does not modify any class attributes ( --> "this" becomes const)

* __attribute__((pure)) :  function return value depends only on the parameters and/or global variables. The function does not modify any global or static variables.
* __attribute__((const)) : function only examines arguments (no globals), and has no effects except the return value. This slightly more strict than "pure"
* hot: tells the compiler "this functions is called very often"
* cold: the opposite of hot
This commit is contained in:
Frank
2024-08-07 14:58:38 +02:00
parent 273154db76
commit 7f9da309c9
14 changed files with 148 additions and 145 deletions

View File

@@ -285,7 +285,7 @@ static volatile float micReal_max2 = 0.0f; // MicIn data max afte
// some prototypes, to ensure consistent interfaces // some prototypes, to ensure consistent interfaces
static float mapf(float x, float in_min, float in_max, float out_min, float out_max); // map function for float static float mapf(float x, float in_min, float in_max, float out_min, float out_max); // map function for float
static float fftAddAvg(int from, int to); // average of several FFT result bins static float fftAddAvg(int from, int to); // average of several FFT result bins
void FFTcode(void * parameter); // audio processing task: read samples, run FFT, fill GEQ channels from FFT results void FFTcode(void * parameter) __attribute__((noreturn)); // audio processing task: read samples, run FFT, fill GEQ channels from FFT results
static void runMicFilter(uint16_t numSamples, float *sampleBuffer); // pre-filtering of raw samples (band-pass) static void runMicFilter(uint16_t numSamples, float *sampleBuffer); // pre-filtering of raw samples (band-pass)
static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels, bool i2sFastpath); // post-processing and post-amp of GEQ channels static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels, bool i2sFastpath); // post-processing and post-amp of GEQ channels

View File

@@ -33,7 +33,7 @@
bool canUseSerial(void); // WLEDMM implemented in wled_serial.cpp bool canUseSerial(void); // WLEDMM implemented in wled_serial.cpp
void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn.cpp void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn.cpp
bool strip_uses_global_leds(void); // WLEDMM implemented in FX_fcn.cpp bool strip_uses_global_leds(void) __attribute__((pure)); // WLEDMM implemented in FX_fcn.cpp
#define FASTLED_INTERNAL //remove annoying pragma messages #define FASTLED_INTERNAL //remove annoying pragma messages
#define USE_GET_MILLISECOND_TIMER #define USE_GET_MILLISECOND_TIMER
@@ -640,7 +640,7 @@ typedef struct Segment {
void setPixelColor(float i, uint32_t c, bool aa = true); void setPixelColor(float i, uint32_t c, bool aa = true);
inline void setPixelColor(float i, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0, bool aa = true) { setPixelColor(i, RGBW32(r,g,b,w), aa); } inline void setPixelColor(float i, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0, bool aa = true) { setPixelColor(i, RGBW32(r,g,b,w), aa); }
inline void setPixelColor(float i, CRGB c, bool aa = true) { setPixelColor(i, RGBW32(c.r,c.g,c.b,0), aa); } inline void setPixelColor(float i, CRGB c, bool aa = true) { setPixelColor(i, RGBW32(c.r,c.g,c.b,0), aa); }
uint32_t __attribute__((pure)) getPixelColor(int i); // WLEDMM attribute added uint32_t __attribute__((pure)) getPixelColor(int i) const; // WLEDMM attribute added
// 1D support functions (some implement 2D as well) // 1D support functions (some implement 2D as well)
void blur(uint8_t, bool smear = false); void blur(uint8_t, bool smear = false);
void fill(uint32_t c); void fill(uint32_t c);
@@ -652,7 +652,7 @@ typedef struct Segment {
inline void addPixelColor(int n, byte r, byte g, byte b, byte w = 0, bool fast = false) { addPixelColor(n, RGBW32(r,g,b,w), fast); } // automatically inline inline void addPixelColor(int n, byte r, byte g, byte b, byte w = 0, bool fast = false) { addPixelColor(n, RGBW32(r,g,b,w), fast); } // automatically inline
inline void addPixelColor(int n, CRGB c, bool fast = false) { addPixelColor(n, RGBW32(c.r,c.g,c.b,0), fast); } // automatically inline 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) const;
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 __attribute__((pure)) color_wheel(uint8_t pos); uint32_t __attribute__((pure)) color_wheel(uint8_t pos);
@@ -693,7 +693,7 @@ typedef struct Segment {
void deletejMap(); //WLEDMM jMap void deletejMap(); //WLEDMM jMap
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
inline uint16_t XY(uint_fast16_t x, uint_fast16_t y) { // support function to get relative index within segment (for leds[]) // WLEDMM inline for speed inline uint16_t XY(uint_fast16_t x, uint_fast16_t y) const { // support function to get relative index within segment (for leds[]) // WLEDMM inline for speed
uint_fast16_t width = max(uint16_t(1), virtualWidth()); // segment width in logical pixels -- softhack007 avoid div/0 uint_fast16_t width = max(uint16_t(1), virtualWidth()); // segment width in logical pixels -- softhack007 avoid div/0
uint_fast16_t height = max(uint16_t(1), virtualHeight()); // segment height in logical pixels -- softhack007 avoid div/0 uint_fast16_t height = max(uint16_t(1), virtualHeight()); // segment height in logical pixels -- softhack007 avoid div/0
return (x%width) + (y%height) * width; return (x%width) + (y%height) * width;
@@ -726,7 +726,7 @@ typedef struct Segment {
inline void setPixelColorXY(float x, float y, byte r, byte g, byte b, byte w = 0, bool aa = true) { setPixelColorXY(x, y, RGBW32(r,g,b,w), aa); } inline void setPixelColorXY(float x, float y, byte r, byte g, byte b, byte w = 0, bool aa = true) { setPixelColorXY(x, y, RGBW32(r,g,b,w), aa); }
inline void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), aa); } inline void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), aa); }
//#endif //#endif
uint32_t __attribute__((pure)) getPixelColorXY(int x, int y); uint32_t __attribute__((pure)) getPixelColorXY(int x, int y) const;
// 2D support functions // 2D support functions
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend); void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend);
inline void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), blend); } inline void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), blend); }
@@ -792,7 +792,7 @@ typedef struct Segment {
inline void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB c, CRGB c2, int8_t rotate = 0) {} inline void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB c, CRGB c2, int8_t rotate = 0) {}
inline void wu_pixel(uint32_t x, uint32_t y, CRGB c) {} inline void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
#endif #endif
uint8_t * getAudioPalette(int pal); //WLEDMM netmindz ar palette uint8_t * getAudioPalette(int pal) const; //WLEDMM netmindz ar palette
} segment; } segment;
//static int segSize = sizeof(Segment); //static int segSize = sizeof(Segment);
@@ -915,64 +915,64 @@ class WS2812FX { // 96 bytes
bool bool
checkSegmentAlignment(void), checkSegmentAlignment(void),
hasRGBWBus(void), hasRGBWBus(void) const,
hasCCTBus(void), hasCCTBus(void) const,
// return true if the strip is being sent pixel updates // return true if the strip is being sent pixel updates
isUpdating(void), isUpdating(void) const,
deserializeMap(uint8_t n=0), deserializeMap(uint8_t n=0),
useLedsArray = false; useLedsArray = false;
inline bool isServicing(void) { return _isServicing; } inline bool isServicing(void) const { return _isServicing; }
inline bool hasWhiteChannel(void) {return _hasWhiteChannel;} inline bool hasWhiteChannel(void) const {return _hasWhiteChannel;}
inline bool isOffRefreshRequired(void) {return _isOffRefreshRequired;} inline bool isOffRefreshRequired(void) const {return _isOffRefreshRequired;}
uint8_t uint8_t
paletteFade, paletteFade,
paletteBlend, paletteBlend,
milliampsPerLed, milliampsPerLed,
cctBlending, cctBlending,
getActiveSegmentsNum(void), getActiveSegmentsNum(void) const,
getFirstSelectedSegId(void), getFirstSelectedSegId(void) __attribute__((pure)),
getLastActiveSegmentId(void), getLastActiveSegmentId(void) const,
getActiveSegsLightCapabilities(bool selectedOnly = false), getActiveSegsLightCapabilities(bool selectedOnly = false) __attribute__((pure)),
setPixelSegment(uint8_t n); setPixelSegment(uint8_t n);
inline uint8_t getBrightness(void) { return _brightness; } inline uint8_t getBrightness(void) const { return _brightness; }
inline uint8_t getMaxSegments(void) { return MAX_NUM_SEGMENTS; } // returns maximum number of supported segments (fixed value) inline uint8_t getMaxSegments(void) const { return MAX_NUM_SEGMENTS; } // returns maximum number of supported segments (fixed value)
inline uint8_t getSegmentsNum(void) { return _segments.size(); } // returns currently present segments inline uint8_t getSegmentsNum(void) const { return _segments.size(); } // returns currently present segments
inline uint8_t getCurrSegmentId(void) { return _segment_index; } inline uint8_t getCurrSegmentId(void) const { return _segment_index; }
inline uint8_t getMainSegmentId(void) { return _mainSegment; } inline uint8_t getMainSegmentId(void) const { return _mainSegment; }
inline uint8_t getPaletteCount() { return 13 + GRADIENT_PALETTE_COUNT; } // will only return built-in palette count inline uint8_t getPaletteCount() const { return 13 + GRADIENT_PALETTE_COUNT; } // will only return built-in palette count
inline uint8_t getTargetFps() { return _targetFps; } inline uint8_t getTargetFps() const { return _targetFps; }
inline uint8_t getModeCount() { return _modeCount; } inline uint8_t getModeCount() const { return _modeCount; }
uint16_t uint16_t
ablMilliampsMax, ablMilliampsMax,
currentMilliamps, currentMilliamps,
getLengthPhysical(void), getLengthPhysical(void) const,
__attribute__((pure)) getLengthTotal(void), // will include virtual/nonexistent pixels in matrix //WLEDMM attribute added __attribute__((pure)) getLengthTotal(void) const, // will include virtual/nonexistent pixels in matrix //WLEDMM attribute added
getFps(); getFps() const;
inline uint16_t getFrameTime(void) { return _frametime; } inline uint16_t getFrameTime(void) const { return _frametime; }
inline uint16_t getMinShowDelay(void) { return MIN_SHOW_DELAY; } inline uint16_t getMinShowDelay(void) const { return MIN_SHOW_DELAY; }
inline uint16_t getLength(void) { return _length; } // 2D matrix may have less pixels than W*H inline uint16_t getLength(void) const { return _length; } // 2D matrix may have less pixels than W*H
inline uint16_t getTransition(void) { return _transitionDur; } inline uint16_t getTransition(void) const { return _transitionDur; }
uint32_t uint32_t
now, now,
timebase; timebase;
uint32_t __attribute__((pure)) getPixelColor(uint_fast16_t); // WLEDMM attribute pure = does not have side-effects uint32_t __attribute__((pure)) getPixelColor(uint_fast16_t) const; // WLEDMM attribute pure = does not have side-effects
inline uint32_t getLastShow(void) { return _lastShow; } inline uint32_t getLastShow(void) const { return _lastShow; }
inline uint32_t segColor(uint8_t i) { return _colors_t[i]; } inline uint32_t segColor(uint8_t i) const { return _colors_t[i]; }
const char * const char *
getModeData(uint8_t id = 0) { return (id && id<_modeCount) ? _modeData[id] : PSTR("Solid"); } getModeData(uint8_t id = 0) const { return (id && id<_modeCount) ? _modeData[id] : PSTR("Solid"); }
const char ** const char **
getModeDataSrc(void) { return &(_modeData[0]); } // vectors use arrays for underlying data getModeDataSrc(void) { return &(_modeData[0]); } // vectors use arrays for underlying data
Segment& getSegment(uint8_t id); Segment& getSegment(uint8_t id) __attribute__((pure));
inline Segment& getFirstSelectedSeg(void) { return _segments[getFirstSelectedSegId()]; } inline Segment& getFirstSelectedSeg(void) { return _segments[getFirstSelectedSegId()]; }
inline Segment& getMainSegment(void) { return _segments[getMainSegmentId()]; } inline Segment& getMainSegment(void) { return _segments[getMainSegmentId()]; }
inline Segment* getSegments(void) { return &(_segments[0]); } inline Segment* getSegments(void) { return &(_segments[0]); }
@@ -1039,7 +1039,7 @@ class WS2812FX { // 96 bytes
inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); } inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); }
uint32_t uint32_t
getPixelColorXY(uint16_t, uint16_t); getPixelColorXY(uint16_t, uint16_t) const;
// end 2D support // end 2D support

View File

@@ -177,7 +177,7 @@ void WS2812FX::setUpMatrix() {
} }
// absolute matrix version of setPixelColor(), without error checking // absolute matrix version of setPixelColor(), without error checking
void IRAM_ATTR WS2812FX::setPixelColorXY_fast(int x, int y, uint32_t col) //WLEDMM: IRAM_ATTR conditionally void IRAM_ATTR __attribute__((hot)) WS2812FX::setPixelColorXY_fast(int x, int y, uint32_t col) //WLEDMM: IRAM_ATTR conditionally
{ {
uint_fast16_t index = y * Segment::maxWidth + x; uint_fast16_t index = y * Segment::maxWidth + x;
if (index < customMappingSize) index = customMappingTable[index]; if (index < customMappingSize) index = customMappingTable[index];
@@ -200,7 +200,7 @@ void IRAM_ATTR_YN WS2812FX::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM
} }
// returns RGBW values of pixel // returns RGBW values of pixel
uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) { uint32_t __attribute__((hot)) WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) const {
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
uint_fast16_t index = (y * Segment::maxWidth + x); //WLEDMM: use fast types uint_fast16_t index = (y * Segment::maxWidth + x); //WLEDMM: use fast types
#else #else
@@ -239,7 +239,7 @@ void Segment::startFrame(void) {
// Simplified version of Segment::setPixelColorXY - without error checking. Does not support grouping or spacing // Simplified version of Segment::setPixelColorXY - without error checking. Does not support grouping or spacing
// * expects scaled color (final brightness) as additional input parameter, plus segment virtualWidth() and virtualHeight() // * expects scaled color (final brightness) as additional input parameter, plus segment virtualWidth() and virtualHeight()
void IRAM_ATTR Segment::setPixelColorXY_fast(int x, int y, uint32_t col, uint32_t scaled_col, int cols, int rows) //WLEDMM void IRAM_ATTR __attribute__((hot)) Segment::setPixelColorXY_fast(int x, int y, uint32_t col, uint32_t scaled_col, int cols, int rows) //WLEDMM
{ {
unsigned i = UINT_MAX; unsigned i = UINT_MAX;
bool sameColor = false; bool sameColor = false;
@@ -406,7 +406,7 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
} }
// returns RGBW values of pixel // returns RGBW values of pixel
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) { uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) const {
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
if (ledsrgb) { if (ledsrgb) {
int i = XY(x,y); int i = XY(x,y);

View File

@@ -882,7 +882,7 @@ uint16_t Segment::virtualLength() const {
} }
//WLEDMM used for M12_sBlock //WLEDMM used for M12_sBlock
void xyFromBlock(uint16_t &x,uint16_t &y, uint16_t i, uint16_t vW, uint16_t vH, uint16_t vStrip) { static void xyFromBlock(uint16_t &x,uint16_t &y, uint16_t i, uint16_t vW, uint16_t vH, uint16_t vStrip) {
float i2; float i2;
if (i<=SEGLEN*0.25) { //top, left to right if (i<=SEGLEN*0.25) { //top, left to right
i2 = i/(SEGLEN*0.25); i2 = i/(SEGLEN*0.25);
@@ -907,7 +907,7 @@ void xyFromBlock(uint16_t &x,uint16_t &y, uint16_t i, uint16_t vW, uint16_t vH,
} }
void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATTR conditionally void IRAM_ATTR_YN __attribute__((hot)) Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATTR conditionally
{ {
if (!isActive()) return; // not active if (!isActive()) return; // not active
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
@@ -1171,7 +1171,7 @@ void Segment::setPixelColor(float i, uint32_t col, bool aa)
} }
} }
uint32_t Segment::getPixelColor(int i) uint32_t __attribute__((hot)) Segment::getPixelColor(int i) const
{ {
if (!isActive()) return 0; // not active if (!isActive()) return 0; // not active
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
@@ -1345,7 +1345,7 @@ void Segment::refreshLightCapabilities() {
/* /*
* Fills segment with color - WLEDMM using faster sPC if possible * Fills segment with color - WLEDMM using faster sPC if possible
*/ */
void Segment::fill(uint32_t c) { void __attribute__((hot)) Segment::fill(uint32_t c) {
if (!isActive()) return; // not active if (!isActive()) return; // not active
#if 0 && defined(WLED_ENABLE_HUB75MATRIX) && defined(WLEDMM_FASTPATH) #if 0 && defined(WLED_ENABLE_HUB75MATRIX) && defined(WLEDMM_FASTPATH)
@@ -1457,7 +1457,7 @@ void Segment::fade_out(uint8_t rate) {
} }
// fades all pixels to black using nscale8() // fades all pixels to black using nscale8()
void Segment::fadeToBlackBy(uint8_t fadeBy) { void __attribute__((hot)) Segment::fadeToBlackBy(uint8_t fadeBy) {
if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply
const uint_fast16_t cols = is2D() ? virtualWidth() : virtualLength(); // WLEDMM use fast int types const uint_fast16_t cols = is2D() ? virtualWidth() : virtualLength(); // WLEDMM use fast int types
const uint_fast16_t rows = virtualHeight(); // will be 1 for 1D const uint_fast16_t rows = virtualHeight(); // will be 1 for 1D
@@ -1480,7 +1480,7 @@ void Segment::fadeToBlackBy(uint8_t fadeBy) {
/* /*
* blurs segment content, source: FastLED colorutils.cpp * blurs segment content, source: FastLED colorutils.cpp
*/ */
void Segment::blur(uint8_t blur_amount, bool smear) { void __attribute__((hot)) Segment::blur(uint8_t blur_amount, bool smear) {
if (!isActive() || blur_amount == 0) return; // optimization: 0 means "don't blur" if (!isActive() || blur_amount == 0) return; // optimization: 0 means "don't blur"
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
if (is2D()) { if (is2D()) {
@@ -1541,7 +1541,7 @@ uint32_t Segment::color_wheel(uint8_t pos) {
/* /*
* Returns a new, random wheel index with a minimum distance of 42 from pos. * Returns a new, random wheel index with a minimum distance of 42 from pos.
*/ */
uint8_t Segment::get_random_wheel_index(uint8_t pos) { // WLEDMM use fast int types, use native min/max uint8_t Segment::get_random_wheel_index(uint8_t pos) const { // WLEDMM use fast int types, use native min/max
uint_fast8_t r = 0, x = 0, y = 0, d = 0; uint_fast8_t r = 0, x = 0, y = 0, d = 0;
while(d < 42) { while(d < 42) {
@@ -1562,7 +1562,7 @@ uint8_t Segment::get_random_wheel_index(uint8_t pos) { // WLEDMM use fast int ty
* @param pbri Value to scale the brightness of the returned color by. Default is 255. (no scaling) * @param pbri Value to scale the brightness of the returned color by. Default is 255. (no scaling)
* @returns Single color from palette * @returns Single color from palette
*/ */
uint32_t Segment::color_from_palette(uint_fast16_t i, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri) // WLEDMM use fast int types uint32_t __attribute__((hot)) Segment::color_from_palette(uint_fast16_t i, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri) // WLEDMM use fast int types
{ {
// default palette or no RGB support on segment // default palette or no RGB support on segment
if ((palette == 0 && mcol < NUM_COLORS) || !_isRGB) { if ((palette == 0 && mcol < NUM_COLORS) || !_isRGB) {
@@ -1582,7 +1582,7 @@ uint32_t Segment::color_from_palette(uint_fast16_t i, bool mapping, bool wrap, u
} }
//WLEDMM netmindz ar palette //WLEDMM netmindz ar palette
uint8_t * Segment::getAudioPalette(int pal) { uint8_t * Segment::getAudioPalette(int pal) const {
// https://forum.makerforums.info/t/hi-is-it-possible-to-define-a-gradient-palette-at-runtime-the-define-gradient-palette-uses-the/63339 // https://forum.makerforums.info/t/hi-is-it-possible-to-define-a-gradient-palette-at-runtime-the-define-gradient-palette-uses-the/63339
um_data_t *um_data; um_data_t *um_data;
@@ -1891,7 +1891,7 @@ void IRAM_ATTR WS2812FX::setPixelColor(int i, uint32_t col)
busses.setPixelColor(i, col); busses.setPixelColor(i, col);
} }
uint32_t WS2812FX::getPixelColor(uint_fast16_t i) // WLEDMM fast int types uint32_t WS2812FX::getPixelColor(uint_fast16_t i) const // WLEDMM fast int types
{ {
if (i < customMappingSize) i = customMappingTable[i]; if (i < customMappingSize) i = customMappingTable[i];
if (i >= _length) return 0; if (i >= _length) return 0;
@@ -2029,7 +2029,7 @@ void WS2812FX::show(void) {
* Returns a true value if any of the strips are still being updated. * Returns a true value if any of the strips are still being updated.
* On some hardware (ESP32), strip updates are done asynchronously. * On some hardware (ESP32), strip updates are done asynchronously.
*/ */
bool WS2812FX::isUpdating() { bool WS2812FX::isUpdating() const {
return !busses.canAllShow(); return !busses.canAllShow();
} }
@@ -2037,7 +2037,7 @@ bool WS2812FX::isUpdating() {
* Returns the refresh rate of the LED strip. Useful for finding out whether a given setup is fast enough. * Returns the refresh rate of the LED strip. Useful for finding out whether a given setup is fast enough.
* Only updates on show() or is set to 0 fps if last show is more than 2 secs ago, so accuracy varies * Only updates on show() or is set to 0 fps if last show is more than 2 secs ago, so accuracy varies
*/ */
uint16_t WS2812FX::getFps() { uint16_t WS2812FX::getFps() const {
if (millis() - _lastShow > 2000) return 0; if (millis() - _lastShow > 2000) return 0;
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
return ((_cumulativeFps500 + 250) / 500); // +250 for proper rounding return ((_cumulativeFps500 + 250) / 500); // +250 for proper rounding
@@ -2128,14 +2128,14 @@ void WS2812FX::setMainSegmentId(uint8_t n) {
return; return;
} }
uint8_t WS2812FX::getLastActiveSegmentId(void) { uint8_t WS2812FX::getLastActiveSegmentId(void) const {
for (size_t i = _segments.size() -1; i > 0; i--) { for (size_t i = _segments.size() -1; i > 0; i--) {
if (_segments[i].isActive()) return i; if (_segments[i].isActive()) return i;
} }
return 0; return 0;
} }
uint8_t WS2812FX::getActiveSegmentsNum(void) { uint8_t WS2812FX::getActiveSegmentsNum(void) const {
uint8_t c = 0; uint8_t c = 0;
for (size_t i = 0; i < _segments.size(); i++) { for (size_t i = 0; i < _segments.size(); i++) {
if (_segments[i].isActive()) c++; if (_segments[i].isActive()) c++;
@@ -2143,13 +2143,13 @@ uint8_t WS2812FX::getActiveSegmentsNum(void) {
return c; return c;
} }
uint16_t WS2812FX::getLengthTotal(void) { // WLEDMM fast int types uint16_t WS2812FX::getLengthTotal(void) const { // WLEDMM fast int types
uint_fast16_t len = Segment::maxWidth * Segment::maxHeight; // will be _length for 1D (see finalizeInit()) but should cover whole matrix for 2D uint_fast16_t len = Segment::maxWidth * Segment::maxHeight; // will be _length for 1D (see finalizeInit()) but should cover whole matrix for 2D
if (isMatrix && _length > len) len = _length; // for 2D with trailing strip if (isMatrix && _length > len) len = _length; // for 2D with trailing strip
return len; return len;
} }
uint16_t WS2812FX::getLengthPhysical(void) { // WLEDMM fast int types uint16_t WS2812FX::getLengthPhysical(void) const { // WLEDMM fast int types
uint_fast16_t len = 0; uint_fast16_t len = 0;
for (unsigned b = 0; b < busses.getNumBusses(); b++) { // WLEDMM use native (fast) types for (unsigned b = 0; b < busses.getNumBusses(); b++) { // WLEDMM use native (fast) types
Bus *bus = busses.getBus(b); Bus *bus = busses.getBus(b);
@@ -2162,7 +2162,7 @@ uint16_t WS2812FX::getLengthPhysical(void) { // WLEDMM fast int types
//used for JSON API info.leds.rgbw. Little practical use, deprecate with info.leds.rgbw. //used for JSON API info.leds.rgbw. Little practical use, deprecate with info.leds.rgbw.
//returns if there is an RGBW bus (supports RGB and White, not only white) //returns if there is an RGBW bus (supports RGB and White, not only white)
//not influenced by auto-white mode, also true if white slider does not affect output white channel //not influenced by auto-white mode, also true if white slider does not affect output white channel
bool WS2812FX::hasRGBWBus(void) { bool WS2812FX::hasRGBWBus(void) const {
for (unsigned b = 0; b < busses.getNumBusses(); b++) { // WLEDMM use native (fast) types for (unsigned b = 0; b < busses.getNumBusses(); b++) { // WLEDMM use native (fast) types
Bus *bus = busses.getBus(b); Bus *bus = busses.getBus(b);
if (bus == nullptr || bus->getLength()==0) break; if (bus == nullptr || bus->getLength()==0) break;
@@ -2171,7 +2171,7 @@ bool WS2812FX::hasRGBWBus(void) {
return false; return false;
} }
bool WS2812FX::hasCCTBus(void) { bool WS2812FX::hasCCTBus(void) const {
if (cctFromRgb && !correctWB) return false; if (cctFromRgb && !correctWB) return false;
for (unsigned b = 0; b < busses.getNumBusses(); b++) { // WLEDMM use native (fast) types for (unsigned b = 0; b < busses.getNumBusses(); b++) { // WLEDMM use native (fast) types
Bus *bus = busses.getBus(b); Bus *bus = busses.getBus(b);

View File

@@ -86,7 +86,7 @@ uint8_t IRAM_ATTR ColorOrderMap::getPixelColorOrder(uint16_t pix, uint8_t defaul
} }
uint32_t Bus::autoWhiteCalc(uint32_t c) { uint32_t Bus::autoWhiteCalc(uint32_t c) const {
uint8_t aWM = _autoWhiteMode; uint8_t aWM = _autoWhiteMode;
if (_gAWM != AW_GLOBAL_DISABLED) aWM = _gAWM; if (_gAWM != AW_GLOBAL_DISABLED) aWM = _gAWM;
if (aWM == RGBW_MODE_MANUAL_ONLY) return c; if (aWM == RGBW_MODE_MANUAL_ONLY) return c;
@@ -139,7 +139,7 @@ void BusDigital::show() {
PolyBus::show(_busPtr, _iType); PolyBus::show(_busPtr, _iType);
} }
bool BusDigital::canShow() { bool BusDigital::canShow() const {
return PolyBus::canShow(_busPtr, _iType); return PolyBus::canShow(_busPtr, _iType);
} }
@@ -182,7 +182,7 @@ void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co); PolyBus::setPixelColor(_busPtr, _iType, pix, c, co);
} }
uint32_t IRAM_ATTR_YN BusDigital::getPixelColor(uint16_t pix) { uint32_t IRAM_ATTR_YN BusDigital::getPixelColor(uint16_t pix) const {
if (reversed) pix = _len - pix -1; if (reversed) pix = _len - pix -1;
else pix += _skip; else pix += _skip;
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder); uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
@@ -200,7 +200,7 @@ uint32_t IRAM_ATTR_YN BusDigital::getPixelColor(uint16_t pix) {
return PolyBus::getPixelColor(_busPtr, _iType, pix, co); return PolyBus::getPixelColor(_busPtr, _iType, pix, co);
} }
uint8_t BusDigital::getPins(uint8_t* pinArray) { uint8_t BusDigital::getPins(uint8_t* pinArray) const {
uint8_t numPins = IS_2PIN(_type) ? 2 : 1; uint8_t numPins = IS_2PIN(_type) ? 2 : 1;
for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i]; for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i];
return numPins; return numPins;
@@ -317,7 +317,7 @@ void BusPwm::setPixelColor(uint16_t pix, uint32_t c) {
} }
//does no index check //does no index check
uint32_t BusPwm::getPixelColor(uint16_t pix) { uint32_t BusPwm::getPixelColor(uint16_t pix) const {
if (!_valid) return 0; if (!_valid) return 0;
#if 1 #if 1
// WLEDMM stick with the old code - we don't have cctICused // WLEDMM stick with the old code - we don't have cctICused
@@ -356,7 +356,7 @@ void BusPwm::show() {
} }
} }
uint8_t BusPwm::getPins(uint8_t* pinArray) { uint8_t BusPwm::getPins(uint8_t* pinArray) const {
if (!_valid) return 0; if (!_valid) return 0;
uint8_t numPins = NUM_PWM_PINS(_type); uint8_t numPins = NUM_PWM_PINS(_type);
for (uint8_t i = 0; i < numPins; i++) { for (uint8_t i = 0; i < numPins; i++) {
@@ -408,7 +408,7 @@ void BusOnOff::setPixelColor(uint16_t pix, uint32_t c) {
_data = bool(r|g|b|w) && bool(_bri) ? 0xFF : 0; _data = bool(r|g|b|w) && bool(_bri) ? 0xFF : 0;
} }
uint32_t BusOnOff::getPixelColor(uint16_t pix) { uint32_t BusOnOff::getPixelColor(uint16_t pix) const {
if (!_valid) return 0; if (!_valid) return 0;
return RGBW32(_data, _data, _data, _data); return RGBW32(_data, _data, _data, _data);
} }
@@ -418,7 +418,7 @@ void BusOnOff::show() {
digitalWrite(_pin, reversed ? !(bool)_data : (bool)_data); digitalWrite(_pin, reversed ? !(bool)_data : (bool)_data);
} }
uint8_t BusOnOff::getPins(uint8_t* pinArray) { uint8_t BusOnOff::getPins(uint8_t* pinArray) const {
if (!_valid) return 0; if (!_valid) return 0;
pinArray[0] = _pin; pinArray[0] = _pin;
return 1; return 1;
@@ -467,7 +467,7 @@ void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
if (_rgbw) _data[offset+3] = W(c); if (_rgbw) _data[offset+3] = W(c);
} }
uint32_t BusNetwork::getPixelColor(uint16_t pix) { uint32_t BusNetwork::getPixelColor(uint16_t pix) const {
if (!_valid || pix >= _len) return 0; if (!_valid || pix >= _len) return 0;
uint16_t offset = pix * _UDPchannels; uint16_t offset = pix * _UDPchannels;
return RGBW32(_data[offset], _data[offset+1], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0); return RGBW32(_data[offset], _data[offset+1], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0);
@@ -480,7 +480,7 @@ void BusNetwork::show() {
_broadcastLock = false; _broadcastLock = false;
} }
uint8_t BusNetwork::getPins(uint8_t* pinArray) { uint8_t BusNetwork::getPins(uint8_t* pinArray) const {
for (uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
pinArray[i] = _client[i]; pinArray[i] = _client[i];
} }
@@ -698,7 +698,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
USER_PRINTLN("MatrixPanel_I2S_DMA started"); USER_PRINTLN("MatrixPanel_I2S_DMA started");
} }
void BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c) { void __attribute__((hot)) BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c) {
if (!_valid || pix >= _len) return; if (!_valid || pix >= _len) return;
#ifndef NO_CIE1931 #ifndef NO_CIE1931
c = unGamma24(c); // to use the driver linear brightness feature, we first need to undo WLED gamma correction c = unGamma24(c); // to use the driver linear brightness feature, we first need to undo WLED gamma correction
@@ -823,7 +823,7 @@ void BusManager::setStatusPixel(uint32_t c) {
} }
} }
void IRAM_ATTR BusManager::setPixelColor(uint16_t pix, uint32_t c, int16_t cct) { void IRAM_ATTR __attribute__((hot)) BusManager::setPixelColor(uint16_t pix, uint32_t c, int16_t cct) {
if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) {
// WLEDMM same bus as last time - no need to search again // WLEDMM same bus as last time - no need to search again
lastBus->setPixelColor(pix - laststart, c); lastBus->setPixelColor(pix - laststart, c);
@@ -851,7 +851,7 @@ void BusManager::setBrightness(uint8_t b, bool immediate) {
} }
} }
void BusManager::setSegmentCCT(int16_t cct, bool allowWBCorrection) { void __attribute__((cold)) BusManager::setSegmentCCT(int16_t cct, bool allowWBCorrection) {
if (cct > 255) cct = 255; if (cct > 255) cct = 255;
if (cct >= 0) { if (cct >= 0) {
//if white balance correction allowed, save as kelvin value instead of 0-255 //if white balance correction allowed, save as kelvin value instead of 0-255
@@ -860,7 +860,7 @@ void BusManager::setSegmentCCT(int16_t cct, bool allowWBCorrection) {
Bus::setCCT(cct); Bus::setCCT(cct);
} }
uint32_t IRAM_ATTR BusManager::getPixelColor(uint_fast16_t pix) { // WLEDMM use fast native types, IRAM_ATTR uint32_t IRAM_ATTR __attribute__((hot)) BusManager::getPixelColor(uint_fast16_t pix) { // WLEDMM use fast native types, IRAM_ATTR
if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) {
// WLEDMM same bus as last time - no need to search again // WLEDMM same bus as last time - no need to search again
return lastBus->getPixelColor(pix - laststart); return lastBus->getPixelColor(pix - laststart);
@@ -881,20 +881,20 @@ uint32_t IRAM_ATTR BusManager::getPixelColor(uint_fast16_t pix) { // WLEDMM
return 0; return 0;
} }
bool BusManager::canAllShow() { bool BusManager::canAllShow() const {
for (uint8_t i = 0; i < numBusses; i++) { for (uint8_t i = 0; i < numBusses; i++) {
if (!busses[i]->canShow()) return false; if (!busses[i]->canShow()) return false;
} }
return true; return true;
} }
Bus* BusManager::getBus(uint8_t busNr) { Bus* BusManager::getBus(uint8_t busNr) const {
if (busNr >= numBusses) return nullptr; if (busNr >= numBusses) return nullptr;
return busses[busNr]; return busses[busNr];
} }
//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit()) //semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
uint16_t BusManager::getTotalLength() { uint16_t BusManager::getTotalLength() const {
uint_fast16_t len = 0; uint_fast16_t len = 0;
for (uint_fast8_t i=0; i<numBusses; i++) len += busses[i]->getLength(); // WLEDMM use fast native types for (uint_fast8_t i=0; i<numBusses; i++) len += busses[i]->getLength(); // WLEDMM use fast native types
return len; return len;

View File

@@ -113,35 +113,35 @@ class Bus {
virtual bool canShow() { return true; } virtual bool canShow() { return true; }
virtual void setStatusPixel(uint32_t c) {} virtual void setStatusPixel(uint32_t c) {}
virtual void setPixelColor(uint16_t pix, uint32_t c) = 0; virtual void setPixelColor(uint16_t pix, uint32_t c) = 0;
virtual uint32_t getPixelColor(uint16_t pix) { return 0; } virtual uint32_t getPixelColor(uint16_t pix) const { return 0; }
virtual void setBrightness(uint8_t b, bool immediate=false) { _bri = b; }; virtual void setBrightness(uint8_t b, bool immediate=false) { _bri = b; };
virtual void cleanup() = 0; virtual void cleanup() = 0;
virtual uint8_t getPins(uint8_t* pinArray) { return 0; } virtual uint8_t getPins(uint8_t* pinArray) const { return 0; }
virtual uint16_t getLength() { return _len; } virtual uint16_t getLength() const { return _len; }
virtual void setColorOrder() {} virtual void setColorOrder() {}
virtual uint8_t getColorOrder() { return COL_ORDER_RGB; } virtual uint8_t getColorOrder() const { return COL_ORDER_RGB; }
virtual uint8_t skippedLeds() { return 0; } virtual uint8_t skippedLeds() { return 0; }
virtual uint16_t getFrequency() { return 0U; } virtual uint16_t getFrequency() const { return 0U; }
inline uint16_t getStart() { return _start; } inline uint16_t getStart() const { return _start; }
inline void setStart(uint16_t start) { _start = start; } inline void setStart(uint16_t start) { _start = start; }
inline uint8_t getType() { return _type; } inline uint8_t getType() const { return _type; }
inline bool isOk() { return _valid; } inline bool isOk() const { return _valid; }
inline bool isOffRefreshRequired() { return _needsRefresh; } inline bool isOffRefreshRequired() const { return _needsRefresh; }
bool containsPixel(uint16_t pix) { return pix >= _start && pix < _start+_len; } bool containsPixel(uint16_t pix) const { return pix >= _start && pix < _start+_len; }
virtual uint16_t getMaxPixels() { return MAX_LEDS_PER_BUS; }; virtual uint16_t getMaxPixels() const { return MAX_LEDS_PER_BUS; };
virtual bool hasRGB() { virtual bool hasRGB() const {
if ((_type >= TYPE_WS2812_1CH && _type <= TYPE_WS2812_WWA) || _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ONOFF) return false; if ((_type >= TYPE_WS2812_1CH && _type <= TYPE_WS2812_WWA) || _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ONOFF) return false;
return true; return true;
} }
virtual bool hasWhite() { return Bus::hasWhite(_type); } virtual bool hasWhite() const { return Bus::hasWhite(_type); }
static bool hasWhite(uint8_t type) { static bool hasWhite(uint8_t type) {
if ((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_SK6812_RGBW || type == TYPE_TM1814 || type == TYPE_UCS8904) return true; // digital types with white channel if ((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_SK6812_RGBW || type == TYPE_TM1814 || type == TYPE_UCS8904) return true; // digital types with white channel
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; // analog types with white channel if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; // analog types with white channel
if (type == TYPE_NET_DDP_RGBW) return true; // network types with white channel if (type == TYPE_NET_DDP_RGBW) return true; // network types with white channel
return false; return false;
} }
virtual bool hasCCT() { virtual bool hasCCT() const {
if (_type == TYPE_WS2812_2CH_X3 || _type == TYPE_WS2812_WWA || if (_type == TYPE_WS2812_2CH_X3 || _type == TYPE_WS2812_WWA ||
_type == TYPE_ANALOG_2CH || _type == TYPE_ANALOG_5CH) return true; _type == TYPE_ANALOG_2CH || _type == TYPE_ANALOG_5CH) return true;
return false; return false;
@@ -158,7 +158,7 @@ class Bus {
#endif #endif
} }
inline void setAutoWhiteMode(uint8_t m) { if (m < 5) _autoWhiteMode = m; } inline void setAutoWhiteMode(uint8_t m) { if (m < 5) _autoWhiteMode = m; }
inline uint8_t getAutoWhiteMode() { return _autoWhiteMode; } inline uint8_t getAutoWhiteMode() const { return _autoWhiteMode; }
inline static void setGlobalAWMode(uint8_t m) { if (m < 5) _gAWM = m; else _gAWM = AW_GLOBAL_DISABLED; } inline static void setGlobalAWMode(uint8_t m) { if (m < 5) _gAWM = m; else _gAWM = AW_GLOBAL_DISABLED; }
inline static uint8_t getGlobalAWMode() { return _gAWM; } inline static uint8_t getGlobalAWMode() { return _gAWM; }
@@ -176,7 +176,7 @@ class Bus {
static int16_t _cct; static int16_t _cct;
static uint8_t _cctBlend; static uint8_t _cctBlend;
uint32_t autoWhiteCalc(uint32_t c); uint32_t autoWhiteCalc(uint32_t c) const;
}; };
@@ -186,7 +186,7 @@ class BusDigital : public Bus {
inline void show(); inline void show();
bool canShow(); bool canShow() const;
void setBrightness(uint8_t b, bool immediate); void setBrightness(uint8_t b, bool immediate);
@@ -194,25 +194,25 @@ class BusDigital : public Bus {
void setPixelColor(uint16_t pix, uint32_t c); void setPixelColor(uint16_t pix, uint32_t c);
uint32_t getPixelColor(uint16_t pix); uint32_t getPixelColor(uint16_t pix) const;
uint8_t getColorOrder() { uint8_t getColorOrder() const {
return _colorOrder; return _colorOrder;
} }
uint16_t getLength() { uint16_t getLength() const {
return _len - _skip; return _len - _skip;
} }
uint8_t getPins(uint8_t* pinArray); uint8_t getPins(uint8_t* pinArray) const;
void setColorOrder(uint8_t colorOrder); void setColorOrder(uint8_t colorOrder);
uint8_t skippedLeds() { uint8_t skippedLeds() const {
return _skip; return _skip;
} }
uint16_t getFrequency() { return _frequencykHz; } uint16_t getFrequency() const { return _frequencykHz; }
void reinit(); void reinit();
@@ -240,13 +240,13 @@ class BusPwm : public Bus {
void setPixelColor(uint16_t pix, uint32_t c); void setPixelColor(uint16_t pix, uint32_t c);
//does no index check //does no index check
uint32_t getPixelColor(uint16_t pix); uint32_t getPixelColor(uint16_t pix) const;
void show(); void show();
uint8_t getPins(uint8_t* pinArray); uint8_t getPins(uint8_t* pinArray) const;
uint16_t getFrequency() { return _frequency; } uint16_t getFrequency() const { return _frequency; }
void cleanup() { void cleanup() {
deallocatePins(); deallocatePins();
@@ -274,11 +274,11 @@ class BusOnOff : public Bus {
void setPixelColor(uint16_t pix, uint32_t c); void setPixelColor(uint16_t pix, uint32_t c);
uint32_t getPixelColor(uint16_t pix); uint32_t getPixelColor(uint16_t pix) const;
void show(); void show();
uint8_t getPins(uint8_t* pinArray); uint8_t getPins(uint8_t* pinArray) const;
void cleanup() { void cleanup() {
pinManager.deallocatePin(_pin, PinOwner::BusOnOff); pinManager.deallocatePin(_pin, PinOwner::BusOnOff);
@@ -298,24 +298,24 @@ class BusNetwork : public Bus {
public: public:
BusNetwork(BusConfig &bc); BusNetwork(BusConfig &bc);
uint16_t getMaxPixels() override { return 4096; }; uint16_t getMaxPixels() const override { return 4096; };
bool hasRGB() { return true; } bool hasRGB() const { return true; }
bool hasWhite() { return _rgbw; } bool hasWhite() const { return _rgbw; }
void setPixelColor(uint16_t pix, uint32_t c); void setPixelColor(uint16_t pix, uint32_t c);
uint32_t __attribute__((pure)) getPixelColor(uint16_t pix); // WLEDMM attribute added uint32_t __attribute__((pure)) getPixelColor(uint16_t pix) const; // WLEDMM attribute added
void show(); void show();
bool canShow() { bool canShow() const {
// this should be a return value from UDP routine if it is still sending data out // this should be a return value from UDP routine if it is still sending data out
return !_broadcastLock; return !_broadcastLock;
} }
uint8_t getPins(uint8_t* pinArray); uint8_t getPins(uint8_t* pinArray) const;
uint16_t getLength() { uint16_t getLength() const {
return _len; return _len;
} }
@@ -339,10 +339,10 @@ class BusHub75Matrix : public Bus {
public: public:
BusHub75Matrix(BusConfig &bc); BusHub75Matrix(BusConfig &bc);
uint16_t getMaxPixels() override { return 4096; }; uint16_t getMaxPixels() const override { return 4096; };
bool hasRGB() { return true; } bool hasRGB() const { return true; }
bool hasWhite() { return false; } bool hasWhite() const { return false; }
void setPixelColor(uint16_t pix, uint32_t c); void setPixelColor(uint16_t pix, uint32_t c);
@@ -356,7 +356,7 @@ class BusHub75Matrix : public Bus {
void setBrightness(uint8_t b, bool immediate); void setBrightness(uint8_t b, bool immediate);
uint8_t getPins(uint8_t* pinArray) { uint8_t getPins(uint8_t* pinArray) const {
pinArray[0] = mxconfig.chain_length; pinArray[0] = mxconfig.chain_length;
return 1; return 1;
} // Fake value due to keep finaliseInit happy } // Fake value due to keep finaliseInit happy
@@ -388,7 +388,7 @@ class BusManager {
BusManager() {}; BusManager() {};
//utility to get the approx. memory usage of a given BusConfig //utility to get the approx. memory usage of a given BusConfig
static uint32_t memUsage(BusConfig &bc); static uint32_t memUsage(BusConfig &bc) __attribute__((pure));
int add(BusConfig &bc); int add(BusConfig &bc);
@@ -407,12 +407,12 @@ class BusManager {
uint32_t __attribute__((pure)) getPixelColor(uint_fast16_t pix); // WLEDMM attribute added uint32_t __attribute__((pure)) getPixelColor(uint_fast16_t pix); // WLEDMM attribute added
bool canAllShow(); bool canAllShow() const;
Bus* getBus(uint8_t busNr); Bus* getBus(uint8_t busNr) const;
//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit()) //semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
uint16_t getTotalLength(); uint16_t getTotalLength() const;
inline void updateColorOrderMap(const ColorOrderMap &com) { inline void updateColorOrderMap(const ColorOrderMap &com) {
memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap)); memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap));
@@ -422,7 +422,7 @@ class BusManager {
return colorOrderMap; return colorOrderMap;
} }
inline uint8_t getNumBusses() { inline uint8_t getNumBusses() const {
return numBusses; return numBusses;
} }
@@ -435,7 +435,7 @@ class BusManager {
unsigned laststart = 0; unsigned laststart = 0;
unsigned lastend = 0; unsigned lastend = 0;
inline uint8_t getNumVirtualBusses() { inline uint8_t getNumVirtualBusses() const {
int j = 0; int j = 0;
for (int i=0; i<numBusses; i++) if (busses[i]->getType() >= TYPE_NET_DDP_RGB && busses[i]->getType() < 96) j++; for (int i=0; i<numBusses; i++) if (busses[i]->getType() >= TYPE_NET_DDP_RGB && busses[i]->getType() < 96) j++;
return j; return j;

View File

@@ -7,7 +7,7 @@
/* /*
* color blend function * color blend function
*/ */
IRAM_ATTR_YN uint32_t color_blend(uint32_t color1, uint32_t color2, uint_fast16_t blend, bool b16) { IRAM_ATTR_YN __attribute__((hot)) uint32_t color_blend(uint32_t color1, uint32_t color2, uint_fast16_t blend, bool b16) {
if(blend == 0) return color1; if(blend == 0) return color1;
if (color1 == color2) return color1; // WLEDMM shortcut if (color1 == color2) return color1; // WLEDMM shortcut
const uint_fast16_t blendmax = b16 ? 0xFFFF : 0xFF; const uint_fast16_t blendmax = b16 ? 0xFFFF : 0xFF;
@@ -71,7 +71,7 @@ IRAM_ATTR_YN uint32_t color_add(uint32_t c1, uint32_t c2, bool fast) // WLEDMM
* if using "video" method the resulting color will never become black unless it is already black * if using "video" method the resulting color will never become black unless it is already black
*/ */
IRAM_ATTR_YN uint32_t color_fade(uint32_t c1, uint8_t amount, bool video) IRAM_ATTR_YN __attribute__((hot)) uint32_t color_fade(uint32_t c1, uint8_t amount, bool video)
{ {
if (amount == 0) return 0; // WLEDMM shortcut if (amount == 0) return 0; // WLEDMM shortcut
@@ -297,7 +297,7 @@ static float maxf (float v, float w) // WLEDMM better use standard library fmax
// adjust RGB values based on color temperature in K (range [2800-10200]) (https://en.wikipedia.org/wiki/Color_balance) // adjust RGB values based on color temperature in K (range [2800-10200]) (https://en.wikipedia.org/wiki/Color_balance)
// called from bus manager when color correction is enabled! // called from bus manager when color correction is enabled!
uint32_t IRAM_ATTR_YN colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb) // WLEDMM: IRAM_ATTR_YN uint32_t __attribute__((hot)) IRAM_ATTR_YN colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb) // WLEDMM: IRAM_ATTR_YN
{ {
//remember so that slow colorKtoRGB() doesn't have to run for every setPixelColor() //remember so that slow colorKtoRGB() doesn't have to run for every setPixelColor()
static byte correctionRGB[4] = {0,0,0,0}; static byte correctionRGB[4] = {0,0,0,0};
@@ -406,7 +406,7 @@ static void calcInvGammaTable(float gamma)
gammaTinv[i] = (int)(powf((float)i / 255.0f, gammaInv) * 255.0f + 0.5f); gammaTinv[i] = (int)(powf((float)i / 255.0f, gammaInv) * 255.0f + 0.5f);
} }
} }
uint8_t unGamma8(uint8_t value) { uint8_t __attribute__((hot)) unGamma8(uint8_t value) {
//if (!gammaCorrectCol || (value == 0) || (value == 255)) return value; //if (!gammaCorrectCol || (value == 0) || (value == 255)) return value;
if ((value == 0) || (value == 255)) return value; if ((value == 0) || (value == 255)) return value;
if ((gammaCorrectVal < 0.999f) || (gammaCorrectVal > 3.0f)) return value; if ((gammaCorrectVal < 0.999f) || (gammaCorrectVal > 3.0f)) return value;
@@ -414,7 +414,7 @@ uint8_t unGamma8(uint8_t value) {
return gammaTinv[value]; return gammaTinv[value];
} }
uint32_t unGamma24(uint32_t c) { uint32_t __attribute__((hot)) unGamma24(uint32_t c) {
if ((gammaCorrectVal < 0.999f) || (gammaCorrectVal > 3.0f)) return c; if ((gammaCorrectVal < 0.999f) || (gammaCorrectVal > 3.0f)) return c;
if (gammaTinv[255] == 0) calcInvGammaTable(gammaCorrectVal); if (gammaTinv[255] == 0) calcInvGammaTable(gammaCorrectVal);
return RGBW32(gammaTinv[R(c)], gammaTinv[G(c)], gammaTinv[B(c)], W(c)); return RGBW32(gammaTinv[R(c)], gammaTinv[G(c)], gammaTinv[B(c)], W(c));
@@ -438,13 +438,13 @@ void calcGammaTable(float gamma)
} }
// used for individual channel or brightness gamma correction // used for individual channel or brightness gamma correction
IRAM_ATTR_YN uint8_t gamma8(uint8_t b) // WLEDMM added IRAM_ATTR_YN IRAM_ATTR_YN __attribute__((hot)) uint8_t gamma8(uint8_t b) // WLEDMM added IRAM_ATTR_YN
{ {
return gammaT[b]; return gammaT[b];
} }
// used for color gamma correction // used for color gamma correction
uint32_t gamma32(uint32_t color) uint32_t __attribute__((hot)) gamma32(uint32_t color)
{ {
if (!gammaCorrectCol) return color; if (!gammaCorrectCol) return color;
uint8_t w = W(color); uint8_t w = W(color);

View File

@@ -250,7 +250,7 @@ void refreshNodeList();
void sendSysInfoUDP(); void sendSysInfoUDP();
//network.cpp //network.cpp
int getSignalQuality(int rssi); int getSignalQuality(int rssi) __attribute__((const));
void WiFiEvent(WiFiEvent_t event); void WiFiEvent(WiFiEvent_t event);
//um_manager.cpp //um_manager.cpp
@@ -369,7 +369,7 @@ bool oappendi(int i); // append new number to temp buffer efficiently
void sappend(char stype, const char* key, int val); void sappend(char stype, const char* key, int val);
void sappends(char stype, const char* key, char* val); void sappends(char stype, const char* key, char* val);
void prepareHostname(char* hostname); void prepareHostname(char* hostname);
bool isAsterisksOnly(const char* str, byte maxLen); bool isAsterisksOnly(const char* str, byte maxLen) __attribute__((pure));
bool requestJSONBufferLock(uint8_t module=255); bool requestJSONBufferLock(uint8_t module=255);
void releaseJSONBufferLock(); void releaseJSONBufferLock();
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen); uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
@@ -410,13 +410,14 @@ void clearEEPROM();
//wled_math.cpp //wled_math.cpp
#ifndef WLED_USE_REAL_MATH #ifndef WLED_USE_REAL_MATH
template <typename T> T atan_t(T x); template <typename T> T atan_t(T x);
float cos_t(float phi); float cos_t(float phi) __attribute__((const));
float sin_t(float x); float sin_t(float x) __attribute__((const));
float tan_t(float x); float tan_t(float x) __attribute__((const));
float acos_t(float x); float acos_t(float x);
float asin_t(float x); float asin_t(float x);
float floor_t(float x); float atan_t(float x) __attribute__((const));
float fmod_t(float num, float denom); float floor_t(float x) __attribute__((const));
float fmod_t(float num, float denom) __attribute__((const));
#else #else
#include <math.h> // WLEDMM use "float" variants #include <math.h> // WLEDMM use "float" variants
#define sin_t sinf #define sin_t sinf

View File

@@ -68,7 +68,7 @@ void toggleOnOff()
//scales the brightness with the briMultiplier factor //scales the brightness with the briMultiplier factor
IRAM_ATTR_YN byte scaledBri(byte in) // WLEDMM added IRAM_ATTR_YN IRAM_ATTR_YN __attribute__((hot)) byte scaledBri(byte in) // WLEDMM added IRAM_ATTR_YN
{ {
if (briMultiplier == 100) return(in); // WLEDMM shortcut if (briMultiplier == 100) return(in); // WLEDMM shortcut
uint_fast16_t val = ((uint_fast16_t)in*(uint_fast16_t)briMultiplier)/100; // WLEDMM uint_fast16_t val = ((uint_fast16_t)in*(uint_fast16_t)briMultiplier)/100; // WLEDMM

View File

@@ -723,7 +723,7 @@ bool PinManagerClass::joinWire(int8_t pinSDA, int8_t pinSCL) {
*/ */
// Check if supplied GPIO is ok to use // Check if supplied GPIO is ok to use
bool PinManagerClass::isPinOk(byte gpio, bool output) bool PinManagerClass::isPinOk(byte gpio, bool output) const
{ {
#ifdef ESP32 #ifdef ESP32
if (digitalPinIsValid(gpio)) { if (digitalPinIsValid(gpio)) {
@@ -757,7 +757,7 @@ bool PinManagerClass::isPinOk(byte gpio, bool output)
return false; return false;
} }
PinOwner PinManagerClass::getPinOwner(byte gpio) { PinOwner PinManagerClass::getPinOwner(byte gpio) const {
if (gpio >= WLED_NUM_PINS) return PinOwner::None; // catch error case, to avoid array out-of-bounds access if (gpio >= WLED_NUM_PINS) return PinOwner::None; // catch error case, to avoid array out-of-bounds access
if (!isPinOk(gpio, false)) return PinOwner::None; if (!isPinOk(gpio, false)) return PinOwner::None;
return ownerTag[gpio]; return ownerTag[gpio];

View File

@@ -125,9 +125,9 @@ class PinManagerClass {
// will return true for reserved pins // will return true for reserved pins
bool isPinAllocated(byte gpio, PinOwner tag = PinOwner::None); bool isPinAllocated(byte gpio, PinOwner tag = PinOwner::None);
// will return false for reserved pins // will return false for reserved pins
bool isPinOk(byte gpio, bool output = true); bool isPinOk(byte gpio, bool output = true) const;
PinOwner getPinOwner(byte gpio); PinOwner getPinOwner(byte gpio) const;
// WLEDMM begin // WLEDMM begin
String getOwnerText(PinOwner tag); // WLEDMM - return PIN owner tag as text String getOwnerText(PinOwner tag); // WLEDMM - return PIN owner tag as text

View File

@@ -116,7 +116,7 @@ char* dayShortStr(uint8_t day);
/* low level functions to convert to and from system time */ /* low level functions to convert to and from system time */
void breakTime(time_t time, tmElements_t &tm); // break time_t into elements void breakTime(time_t time, tmElements_t &tm); // break time_t into elements
time_t makeTime(tmElements_t &tm); // convert time elements into time_t time_t makeTime(tmElements_t &tm) __attribute__((pure)); // convert time elements into time_t
} // extern "C++" } // extern "C++"
#endif // __cplusplus #endif // __cplusplus

View File

@@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2408060 #define VERSION 2408070
// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED. // WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
#define _MoonModules_WLED_ #define _MoonModules_WLED_
@@ -928,9 +928,9 @@ public:
} }
// boot starts here // boot starts here
void setup(); void setup() __attribute__((used));
void loop(); void loop() __attribute__((used));
void reset(); void reset();
void beginStrip(); void beginStrip();

View File

@@ -61,6 +61,7 @@ void esp_heap_trace_free_hook(void* ptr)
unsigned long lastMillis = 0; //WLEDMM unsigned long lastMillis = 0; //WLEDMM
unsigned long loopCounter = 0; //WLEDMM unsigned long loopCounter = 0; //WLEDMM
void setup() __attribute__((used)); // needed for -flto
void setup() { void setup() {
#ifdef WLED_DEBUG_HEAP #ifdef WLED_DEBUG_HEAP
esp_err_t error = heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook); esp_err_t error = heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook);
@@ -68,6 +69,7 @@ void setup() {
WLED::instance().setup(); WLED::instance().setup();
} }
void loop() __attribute__((used)); // needed for -flto
void loop() { void loop() {
//WLEDMM show loops per second //WLEDMM show loops per second
loopCounter++; loopCounter++;