Repository navigation
Random red pixel fix - #943
MisterGoodDeal wants to merge 1 commit into
Conversation
Issue related to the post FastLED#668 and FastLED#942
|
Hi and thanks for the PR. We're just starting to work on the backlog of contributions, and I just wanted to let you know that I was taking a look at this now. I really appreciate the help. |
|
Thank you a lot, man. |
jasoncoon
left a comment
There was a problem hiding this comment.
👍 Looks good to me, I generally prefer my rainbows fully saturated. 😄
|
Fixed my jumping red led with: in all places in hsv2rgb_rainbow() where the scale8_LEAVING_R1_DIRTY appeared... Haven't tested it in other cases but mine, don't exactly understand the issue and don't know if it changes the execution time (on AVRs, it shouldn't, right?). But I do understand the lower saturation in |
|
I'm not in favor of changing the saturation of the rainbow at this time. Too risky. The asm noop fix is very interesting. But the AVR chipsets are becoming less relevant each year. If someone has a new PR with the ASM changes (the comment above is not definitive) then I'll accept it. |
|
Hi there, I'm looking at this again and would like to get this old PR fix in. Overall it looks good and I have absolutely noticed bad color with the hue algorithm in many tests. What I'm noticing here is that you missed a few places. Wanted to give you a chance to review before I proceed. In src/colorutils.cpp I notice that there are four rainbow functions that each set the set Here is what I currently see with ripgrep: 1 void fill_rainbow( struct CRGB * targetArray, int numToFill,
uint8_t initialhue,
uint8_t deltahue )
{
CHSV hsv;
hsv.hue = initialhue;
hsv.val = 255;
hsv.sat = 240;
for( int i = 0; i < numToFill; ++i) {
targetArray[i] = hsv;
hsv.hue += deltahue;
}
}2 void fill_rainbow( struct CHSV * targetArray, int numToFill,
uint8_t initialhue,
uint8_t deltahue )
{
CHSV hsv;
hsv.hue = initialhue;
hsv.val = 255;
hsv.sat = 240;
for( int i = 0; i < numToFill; ++i) {
targetArray[i] = hsv;
hsv.hue += deltahue;
}
}3 void fill_rainbow_circular(struct CRGB* targetArray, int numToFill, uint8_t initialhue, bool reversed)
{
if (numToFill == 0) return; // avoiding div/0
CHSV hsv;
hsv.hue = initialhue;
hsv.val = 255;
hsv.sat = 240;
const uint16_t hueChange = 65535 / (uint16_t)numToFill; // hue change for each LED, * 256 for precision (256 * 256 - 1)
uint16_t hueOffset = 0; // offset for hue value, with precision (*256)
for (int i = 0; i < numToFill; ++i) {
targetArray[i] = hsv;
if (reversed) hueOffset -= hueChange;
else hueOffset += hueChange;
hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit)
}
}4 void fill_rainbow_circular(struct CHSV* targetArray, int numToFill, uint8_t initialhue, bool reversed)
{
if (numToFill == 0) return; // avoiding div/0
CHSV hsv;
hsv.hue = initialhue;
hsv.val = 255;
hsv.sat = 240;
const uint16_t hueChange = 65535 / (uint16_t) numToFill; // hue change for each LED, * 256 for precision (256 * 256 - 1)
uint16_t hueOffset = 0; // offset for hue value, with precision (*256)
for (int i = 0; i < numToFill; ++i) {
targetArray[i] = hsv;
if (reversed) hueOffset -= hueChange;
else hueOffset += hueChange;
hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit)
}
} |
|
@zackees can we please get the suggested changes for AVR at the same time. Iirc, this value of 240 for saturation was reduced from 255 to work around a very old, and previously misunderstood issue on AVR. Since then, I've seen it manifest in my own uses of scale8_LEAVING_R1_DIRTY. The proposed |
Thanks @sutaburosu Here is the new pr that fixes this: #1907 I'll leave feedback open for 48 hours, unless someone gives me a LGTM before. |
Fixes jumping red pixel - see #943
|
@sutaburosu okay the |
|
I'm sorry, I haven't had time in the last couple of days to put together the visual test case that I wanted to provide. I tried briefly, but this problem can be difficult to reproduce when you actually want to see it. After skimming the linked issues, I notice this commentor reached the same conclusion: prevent the compiler re-ordering anything in this stanza. My vote is to close this and the others. |
|
ok it's fixed. Will reopen if not fixed |
…668) (#3808) #668 is the "unexpected red pixel" in fill_rainbow: on AVR one pixel mid-ramp comes out with a wrong channel, the affected pixel moves with the hue, and unrelated edits to the sketch make it appear and disappear. The community diagnosed it correctly as compiler reordering around the scale8_LEAVING_R1_DIRTY inline asm, and #943 fixed the reordering half by inserting asm volatile("") barriers between those calls. This fixes a second, separate half of the same underlying hazard. scale8*_LEAVING_R1_DIRTY skips restoring AVR's __zero_reg__ so that several calls can share one cleanup_R1(); its docs say "You MUST call cleanup_R1() after using this function". hsv2rgb_rainbow has three paths that return without doing so: 1. `if (Gscale) g = scale8_video_LEAVING_R1_DIRTY(g, Gscale)` dirties R1, then `sat == 255` skips the saturation block and `val == 255` skips the value block -- nothing cleans up. 2. Same call, then the `sat == 0` branch, which only assigns 255s. 3. `val = scale8_video_LEAVING_R1_DIRTY(val, val)` dirties R1, then the `val == 0` branch assigns zeros; only the else branch batches into a cleanup_R1(). Leaving r1 non-zero on return violates the AVR ABI -- the compiler assumes r1 is a hard zero -- so whatever runs next can compute garbage. That matches every reported symptom: which pixel is wrong depends on which hue takes which branch, and it moves under recompilation because what lands after the call changes. For the Gscale call, use the cleaning scale8_video(): the DIRTY variant only pays off when calls are batched, and this is a lone call whose cleanup would have to be duplicated onto three exit paths. For val == 0, add the cleanup_R1() that branch was missing. Verified: `bash test --cpp --clean` 359/359, and `bash compile uno` (AVR, where this matters) builds clean at 4.92 KB flash. Refs #668, #943 Co-authored-by: Claude <[email protected]>

This change fix the issue with the random red pixel while using the rainbow effect based on issues #668 and #942