Skip to content

Fix #1853 - RGBWEmulated does not work with SAMD21 clockless - #1854

Merged
zackees merged 6 commits into
FastLED:masterfrom
kbob:samd21-rgbw
Jan 20, 2025
Merged

zackees merged 6 commits into
FastLED:masterfrom
kbob:samd21-rgbw

Conversation

@kbob

@kbob kbob commented Jan 19, 2025

Copy link
Copy Markdown
Contributor

The issue was that the RGBWEmulated controller did not call the device controller's init method. Also, it did an update by calling showPixels. showPixels bypasses the device's beginUpdateLeds and endUpdateLeds methods.

Keep in mind that the device controller is automatically linked into the global list of controllers (private to CLEDController). So when show occurs, the device controller's show methods (beginShowLeds, showLedsInternal and endShowLeds) are invoked. Because of the creation order, they are called immediately after RGBWEmulated's show methods.

I've changed RGBWEmulated to call the device controller at a higher level. Instead of the device owning no LEDs and using LEDs passed in via showPixels, RGGWEmulated gives the LEDs immediately after allocating them (usually on the first show), then calls CLEDController::showLeds (with full brightness). showLeds handles calling beginShowLeds, showLedsInternal, and endShowLeds.

To keep the device controller from displaying the same LEDs again when its show methods are invoked, RGBWController disables the controller (setEnable(false)).

Advantages of doing it this way.

  • less coupling between RGBWEmulated and CLEDController
  • works with controllers that use beginShowLeds and endShowLeds
  • works with controllers that are ill-behaved with empty LED arrays
  • works with controllers that incorrectly reference the LED array from showPixels

Disadvantages.

  • relies on CLEDController::showLeds which is not in the most-used code path
  • adds a few dozen instructions to each show (I guess. I didn't measure.)

CRGBW also calls the device controller's init method, which should be non-controversial, and it resets all the parameters that would let CPixelController modify the RGB values. Again, I changed the code to use higher-level interfaces to reduce coupling.

Sorry for the wall of text. I'm new here and erring on the side of overexplanation.

kbob added 6 commits January 14, 2025 15:38
RGBWEmulatedController was not calling beginShowLeds and endShowLeds.
This broke SAMD21's ClocklessController.  SAMD21 also crashed because
(I think) of FastLED#1101 .

I changed RGBWEmu* to call showLeds instead of show Pixels.  I also
changed it to use higher level interfaces to reduce coupling between
RGBWEmu* and CLEDController and keep m_Data non-null.
@kbob

kbob commented Jan 19, 2025

Copy link
Copy Markdown
Contributor Author

Is there some documentation I should be updating with this? I didn't find any docs that described what RGBWEmulated is supposed to do or how to use it, just the example.

Ditto tests. Should I be adding or updating a test?

@zackees

zackees commented Jan 19, 2025

Copy link
Copy Markdown
Member

Oh wow, what a gift!

I'm answer to your questions...

I'm a fan example-driven documentation enforced by automated testing.

Yes there are unit tests, you can add them if you want but will require some mocking to get this in.

Let me digest this on monday when I get back from my party weekend and get this in for 3.9.12.

Again, thank you very much for this!

@zackees
zackees merged commit 10312f2 into FastLED:master Jan 20, 2025
@kbob

kbob commented Jan 20, 2025

Copy link
Copy Markdown
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants