-
8000
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers/ws281x: improve timing for ESP32x #19422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers/ws281x: improve timing for ESP32x #19422
Conversation
If overhead like the loop control or the calculation of the waiting times for the next bit are performed while waiting for the end of the LOW phase, the time required for such operations is included in the LOW phase. This makes both the LOW phase and the period more precise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors merge
Nice one, thx :)
Build succeeded: |
Thanks for reviewing and merging. BTW, I already have a prototypic driver version that uses the RMT controller of the ESP32x SoC. With the RMT it is possible to generate arbitrary digital waveforms like NEC remote control signals or even WS2812 signals. The advantages are that the CPU is not busy when generating the WS218x signal and the phase times are accurate to nanoseconds. The disadvantage is that the configuration of the RMT is so complex due to its flexibility that I simply used the ESP-IDF API for RMT. However, this requires about 6 kBytes more ROM, about 3 kBytes more IRAM, and 88 bytes more RAM. I also decided to use the ESP-IDF API to keep the flexibility of the RMT for other applications. The WS218x driver just needs only one channel of 4 or 8 available channels. We could try to hard-code the configuration of the RMT for WS218x driver, but this would prevent other applications using RMT if the WS281x driver is used. |
We could make the use of the hardware driver optional. |
Sounds like a plan. Since the ws281x backend can be flexible be chosen, one could even opt for the bit-banging driver if ROM and RAM is scarce. But given that all ESP32 MCUs are in the high end hardware leage, most use cases likely can affort to spend RAM and ROM for it. So I'd even say the RMT should be the default backend on ESP32, and people with special use cases that are heavy on memory can opt for the bit-banging driver instead. |
Contribution description
This PR provides a small change which improves the timing for ESP32x SoCs.
If overhead like the loop control or the calculation of the waiting times for the next bit are performed while waiting for the end of the LOW phase, the time required for such operations is included in the LOW phase. This makes both the LOW phase and the period more precise.
According to the definitions
the following timing is used:
Timing with current master:

Timing with this PR:

Testing procedure
tests/driver_ws281x
should still work.Issues/PRs references