ws2812-esp32-rmt-driver icon indicating copy to clipboard operation
ws2812-esp32-rmt-driver copied to clipboard

Using the driver with non-blocking write() to drive 8 channels in parallel

Open Ant01n3 opened this issue 7 months ago • 2 comments

Hello,

Thank you for this library. I managed to use it easily to light 8 strips of leds using 8 Ws2812Esp32Rmt and their write() function. Each driver uses one of the 8 channels of the RMT. I can use them in a loop to update all the leds to animate them.

However when doing this, write() is blocking. This means that we have to wait for write() to finish updating the first strip to start writing to the second strip etc... The animation becomes very slow as I have a lot of leds to light (444 per strip). If I understand well, the time used to update the leds is proportional to the number of leds.

I would like, if this is possible, to write to each strip in parallel, in a loop. Before trying to use threads (is this a good idea by the way?), I saw that the Ws2812Esp32RmtDriver has both write() and write_blocking(). I imagined that maybe the non blocking write() could solve my problem. However, up until now, I did not have found a way to make it work... I am fighting against the borrow checker... I imagine this is possible however since this function exist.

And here is my question: is there an example of how this should be used ?

Ant01n3 avatar Apr 14 '25 21:04 Ant01n3

Thank you for using my lib.

To be honest, I have never written code taking such parallelism into account, nor have I ever heard of implementation report.

w.r.t. non-blocking write(), there are many other restrictions of parameters. For example, as I mentioned in rustdoc, pixel data cannot be stored in stack memory, but must be Boxed. I wonder it may be reasonable to make the lifetime of the pixel data (semi-)persistent by using cell_once or something like that.

Since transfer completion notification is not supported (not exist in the esp-idf-hal crate API), it would be necessary to do it by design guarantee using such as timer-based.

cat-in-136 avatar Apr 15 '25 13:04 cat-in-136

Thank you for your answer, yes I understand. I will try to go in this direction. Thanks a lot.

Ant01n3 avatar Apr 16 '25 06:04 Ant01n3