Makuna / NeoPixelBus

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.
GNU Lesser General Public License v3.0
1.17k stars 255 forks source link

Esp bitbang interrupt workaround #759

Closed willmmiles closed 5 months ago

willmmiles commented 5 months ago

This patch attempts to work around hard WDT resets on ESP8266 with too-long strands by periodically permitting interrupts to trigger when bit-banging. If interrupt processing delays exceed the reset interval, the update is retried, up to a (currently fixed) limit. Interrupts are only checked in between pixel elements, so while a strand update may be incomplete, no flashes of strange colors should occur.

Essentially the goal is ensure that the microcontroller remains stable even if the full update can't be successfully completed. I can't speak for others, but I'd rather a partial update than a crash. If there are some unreachable pixels, that provides a "soft" failure mode for people who are trying to strech their micro too far, rather than the system just seeming randomly flaky when network activity and pixel updates collide.

willmmiles commented 5 months ago

Thanks for the thorough review, and being generally receptive to this approach. I'll update my submission based on your recommendations.

I particularly appreciate your validation of the specific timings -- actually I'm surprised the WS2812s could tolerate 150us, I thought I read in the datasheet that their latch interval was supposed to be only 50us! I'd missed entirely that the maximum interpixel delay ought to be less than the complete reset interval in many cases. One complication there is that the retry sequence will need to wait the whole reset time if it misses the latch time - it might be cleaner to return to a loop in the outer code instead.

+1 on making the whole approach optional with compile-time resolution. I'm a little worried about the combinatoric explosion of flavors (esp32/8266, inverted/not, interrupts/no). I'm going to think on this for a bit and run some tests on the templating before resubmitting.

Makuna commented 5 months ago

actually I'm surprised the WS2812s could tolerate 150us, I thought I read in the datasheet that their latch interval was supposed to be only 50us!

I am sorry, I typed the wrong units. Its 150ns not 150us. That is 0.150us. But from the playing around with the old interpixel delays code, we found many that also supported at least10us of no signal between pixels. Didn't test how far it extended though. So, this change would be useful to some.

I generally don't recommend the BitBang methods on ESPs at all.

willmmiles commented 5 months ago

Next draft of updated code pushed. Some high level comments: