Commit Graph

671 Commits

Author SHA1 Message Date
Frank
49130c9ec9 (chores) cleanup some compiler warnings
* switch-cases that fall through
* potential buffer overflow in improv.cpp
* potentially uninitialized variables in FX.cpp
* potential array out-of-range on segment::col[]
* minor optimization: only apply gamma correction when result is needed
* tag some possibly unused variables with   [[maybe_unused]]
2026-03-11 13:54:58 +01:00
Frank Möhle
cce3c0b5d3 psram-aware malloc functions (backport of upstream #4895) (#342)
Introduces new memory allocation functions, based on wled#4895 by @DedeHai

* keep a minimum of 15KB RAM available to UI - improves stability
* S3/S2/C3 automatically use "fast RTC Ram" for small data (reduces fragmentation)
* auto-detects PSRAM (or no PSRAM) when firmware was built with -D BOARD_HAS_PSRAM
* d_malloc() and d_calloc() prefer DRAM if possible (faster), but fall back to PSRAM when free RAM gets low.
2026-02-18 17:57:47 +01:00
Damian Schneider
532c9b762c replacement for fastled sqrt16() (#4426)
* added bitwise operation based sqrt16

- replacement for fastled, it is about 10% slower for numbers smaller 128 but faster for larger numbers. speed difference is irrelevant to WLED but it saves some flash.

* updated to 32bit, improved for typical WLED use

- making it 32bits allows for larger numbers
- added another initial condition check for medium sized numbers
- increased the "small number" optimization to larger numbers: the function is currently only used to calculate sqrt(x^2+y^2) which even for small segments is larger than the initially used 64, so optimizing for 1024 makes more sense, although the value is arbitrarily chosen
2026-01-17 12:18:35 +01:00
Frank
428becc301 inline segment palette functions for speed
* make currentMode() inline
* move currentColor() to FX.h
* move Segment::color_wheel() and Segment::color_from_palette() to FX.h
* add a little helper function to fx.h, so it can access strip.paletteBlend which is not defined yet
2026-01-10 01:25:24 +01:00
Frank
0541a1f5b4 make manual and dual auto-white mode work with palettes (upstream backport)
extract white channel from first custom color, instead of setting it to black
2026-01-09 23:50:30 +01:00
Frank
f9c7828eeb fix parameter order in calloc() calls
calloc(nmemb, bytes) allocates memory for an array of _nmemb_ elements of size _bytes_
2026-01-01 22:02:06 +01:00
Frank
0901d903b9 Merge branch 'mdev' into pixelforge_backport 2026-01-01 18:07:41 +01:00
Frank
32ed6cafc1 ledmap parser robustness improvements
* do not read past end of array "]"
* digest "unexpected" order of tags (always rewind input)
* better user message on success
2025-12-30 22:07:12 +01:00
Frank
9db1022b9d ledmap parser bugfix
make our custom parser robust against pretty printed ledmap.json 

expected <"map":[> but user file had <"map": [>
2025-12-30 20:13:40 +01:00
Frank
35c847404c Merge branch 'mdev' into pixelforge_backport 2025-12-29 19:47:51 +01:00
Frank
103e7db83f post merge fix, build 2512291 2025-12-29 14:45:11 +01:00
Will Tatam
45e8c63c2c Merge pull request #5031 from wled/add-check-diff
Add segment checkmarks to `differs()` check
2025-12-29 14:30:49 +01:00
Frank
4345b32f97 protect WS2812FX::resetSegments boundsOnly path
the "boundsOnly" case can lead to ldsrgb re-allocation - better to protect it with segmentMux, too
2025-12-22 18:33:46 +01:00
Frank
39344382c7 WS2812FX::service() cleanup
- _isServicing is not critical any more -> move back into bitfield
- remove experimental deactivated code from WS2812FX::service()
2025-12-22 18:10:51 +01:00
Frank
68a76ff442 minor refactoring of critical sections
- define dummy macros for 8266, to avoid #ifdef ESP32
- small hint for readers who were not able to play arcade games in the 1980's ;-)
2025-12-22 17:59:22 +01:00
Frank
cb94cfafae extra debug message when Segment::setUp cannot get the mutex 2025-12-22 00:59:57 +01:00
Frank
1038421544 atomic pointer swap in allocLeds() 2025-12-22 00:31:53 +01:00
Frank
50cc6f4c28 comment correction 2025-12-22 00:07:27 +01:00
Frank
73c54d7a57 replace potentially infinite wait with 2100ms max
better to end with an inconsistent state, than risk a lock-up until reset
2025-12-22 00:05:54 +01:00
Frank
30fcd6efad segment & bus.show mutex redesign
* separate mutexes for improved performance:
  - busses.show and effect drawing
  - critical changes to segment vector
  - block out critical segment changes while strip.service() loops over segments
* UDP realtime acquires mutex before drawing
  - prevents corrupted outputs, caused by parallel tasks updating pixels while busses.show() runs
2025-12-21 23:56:09 +01:00
Frank
577d80d2ef segment drawing robustness improvements
* segment::fill() is also called outside the service loop - make sure that size is always calculated correctly
* leave _currentSeg in a meaningful state after strip.service()
2025-12-21 23:08:50 +01:00
Frank
7df63db744 and mutex for all
revised mutex and critical section handling for segment drawing
- simplified code with macros (no more #if ESP32 ... #endif)
- remove some critical sections (prevents interrupt stalling)
- added mutex to functions that change the list of segments
- added mutexes to all (potential) background drawing code
- use recursive mutexes to prevent accidental self-locking of tasks
2025-12-20 17:13:52 +01:00
Frank
c25f082231 improve stability of DDP via tcp_task (websockets)
* protect pixel buffer changes with critical section
* protect segment list modification with critical section
* make _isServicing and _triggered atomic (move out of packed bitarray)
* allow custom timeout for waitUntilIdle - DDP needs a longer timeout
* protect strip.show() and effect drawing functions with mutex, to prevent crashes
2025-12-19 18:13:20 +01:00
Frank
5849e02e23 no effect data limits for PSRAM boards (upstream backport) 2025-12-17 01:19:24 +01:00
Frank
87fc226213 more segment data for PSRAM boards 2025-12-17 01:10:05 +01:00
Frank
02d23b3316 fixing some compiler warnings
signed vs. unsigned, deprecated functions, printf parameter size mismatch
2025-12-17 00:03:18 +01:00
Frank
1ba2749343 more renaming
to avoid name clashes with vLength()
2025-12-16 23:26:02 +01:00
Frank
15451c16f9 reduce debug noise on serial
downgraded a few USER_PRINT to DEBUG_PRINT
2025-11-30 01:22:34 +01:00
Frank
c36e493b47 Fix strlcpy destination size parameters 2025-11-21 00:16:25 +01:00
Frank
7ef94bc6c7 use strlcpy instead of strcpy 2025-11-21 00:08:15 +01:00
Frank
e63dc7e71e longer segment names
* introducing WLED_MAX_SEGNAME_LEN from upstream
* default: max name length = 48
* hopefully found all places where the segment name length was hardcoded (32, 33, 34)
* some comments still refer to "32" but wtf
2025-11-20 23:49:26 +01:00
Frank
1583452c86 oops
fixes a mistake in previous commit
2025-11-18 23:19:25 +01:00
Frank
bc7a96d7d4 strip wait function: increase idle wait time to 120ms
Updated strip wait function to use longer idle wait time (similar to the timeout used by upstream WLED 0.16)
2025-11-18 23:13:47 +01:00
Damian Schneider
e5ab0b6077 Bugfix for gif player WRT inactive segment and bugfix in copy FX
- if a segment is destroyed or turned inactive, disable the gif player: only one gif player instance can run at a time, if a inactive or destroyed segment uses it, the effect is broken for other segments.

- copy FX ironically copied the source segment on each call, should use reference not a copy!
2025-11-16 20:48:27 +01:00
Frank
737b7cc471 bus robustness improvement
ABL and SerializeConfig explicitly check bus->isOK(), instead of relying on bus->getLength() == 0
2025-11-16 14:52:18 +01:00
Frank
9f31f2444f some precautions to prevent buffer out-of-bounds access and concurrency problems
* make sure that filenames can hold 32chars of segment.name
* fix logic error in Segment::drawCharacter
* protect free(Segment::_globalLeds) with a critical section
2025-11-14 22:43:44 +01:00
Frank
a833cb5706 JMap robustness and use-after-free fixes
* increased ArrayAndSize.size from 8bit to 16bit
* prevent out-of-bounds access in JMapC::getPixelColor
* do not delete[] SEGMENT.name from outside of segment class !!
2025-11-11 23:17:50 +01:00
Frank
1e14e4b4e5 fix minor bug (errorflag reset not working)
typo: == instead of =
2025-11-11 23:09:09 +01:00
Frank
e4c964ebaf deserializeMap robustness improvements
* make sure that fileName is big enough for segmentName".json"
* fix possible buffer overflow in f.readBytesUntil
* stop reading map{ } entries when customMappingSize is reached
* raise "low mem" error when malloc failed
2025-11-11 21:59:19 +01:00
Damian Schneider
71b7121ded bugfix: do not reset segments if unchanged #4969
lines were swapped, causing segment reset on every preset call.
2025-11-09 21:57:12 +01:00
Frank
d78ea5ae2e prevent bad filenames in "segment names as ledmap names"
Increase buffer size for fileName to accommodate long segment names (max 32 chars) without producing broken filenames.
2025-11-07 15:07:13 +01:00
Frank
5177ebd271 fix false warnings when temporarily exceeding MAX_SEGMENT_DATA
The segment copy constructors can temporarily exceed the budget of MAX_SEGMENT_DATA. The original segment will be de-allocated a few milliseconds later.
This change introduced an "overdraft" budget of 50% that can be used for temporary segment copies.
2025-11-06 22:09:11 +01:00
Frank
bb44dd8616 robustness improvements for image presets
prevent errors / crashes when drawing "i" images from a preset.
- prevent out-of-bounds writing (segment smaller than image)
- make sure that segment properties are cached correctly
- always do "show" when strip was triggered (avoids lost frames)
2025-11-04 20:28:26 +01:00
Frank
40064490ad strip level setPixelColor and getPixelColor optimization
* moved sPC and gPC functions out of their .cpp files into FX.h, so the compiler can optimize better.

depending of effect used, this gives a 2% up to 8% speedup.
2025-11-01 16:50:20 +01:00
Frank
3752409b46 no more ORANGE on effect memory failure
For maintainers of custom effects: replace "return mode_solid()" with "return mode_oops()"

Effect errors fall back to Akemi (2D) or Rainbow(1D) instead of SOLID ORANGE.
2025-10-27 11:24:12 +01:00
Frank
56380ce04c slightly faster to keep IRAM_ATTR for sPC and color_add 2025-10-26 01:41:30 +02:00
Frank
4713f26bb8 additional constants to improve upstream compatibility
* a few new error constants
*  WLED_O2_ATTR - ask the compiler for stronger optimization of a single function
*  WLED_O3_ATTR (WLEDMM) optimize even more
2025-10-25 23:43:44 +02:00
Will Tatam
c5a28c2977 only call endImagePlayback if reset true in resetIfRequired 2025-06-15 12:13:16 +01:00
Will Tatam
d9ab878503 Swap to WLED_ENABLE_GIF 2025-02-22 12:56:47 +00:00
Christian Schwinne
9caa7cb4e9 Fix missing GIF enable macros 2025-02-22 12:40:42 +00:00