Skip to content
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: add RMT hardware support for ESP32x SoCs #19424

Merged
merged 8 commits into from
Mar 29, 2023

Conversation

gschorcht
Copy link
Contributor

Contribution description

This PR provides support for ESP32x RMT that is used to generate WS2812B signals.

All ESP32x SoCs have a Remote Control Peripheral (RMT) that can be used to generate digital waveforms, such as NEC remote control signals or WS2812B RGB LED signals. Each RMT peripheral has either 4 or 8 channels. Some ESP32x SoCs support configuring the clock sources used for each channel separately, while other ESP32x SoCs can only use a single clock source for all channels.

The advantages using the RMT 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 the ESP-IDF high-level driver for RMT is used.This requires about 6 kBytes more ROM, about 3 kBytes more IRAM, and 88 bytes more RAM.

Therefore, either the RMT hardware implementation (module ws2812x_esp32_hw) as well as the bit-banging software implementation (module ws2812x_esp32_hw) can be used. RMT hardware implementation (module ws2812x_esp32_hw) is used by default.

Timing with hardware implementation:
ws281x_esp32_rmt

Testing procedure

tests/driver_ws281x should still work, for example:

CFLAGS='-DWS281X_PARAM_PIN=GPIO45 -DWS281X_PARAM_NUMOF=47' BOARD=esp32s3-devkit make -j8 -C tests/driver_ws281x flash

Test Output:
https://user-images.githubusercontent.com/31932013/227791753-e6d2924e-3364-4387-870f-a56d3a9a8a80.mp4

Issues/PRs references

@github-actions github-actions bot added Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: tests Area: tests and testing framework Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Mar 26, 2023
Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. I'll take a second look tomorrow on a big monitor just in case. I tend to do betters on that compared to a review on a phone screen 😅

cpu/esp32/esp-idf/include/driver/gpio.h Outdated Show resolved Hide resolved
cpu/esp32/include/periph_cpu.h Show resolved Hide resolved
@gschorcht gschorcht force-pushed the drivers/ws281x_esp32_use_rmt branch from a73d494 to 862e0c7 Compare March 28, 2023 16:51
@github-actions github-actions bot removed the Area: build system Area: Build system label Mar 28, 2023
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 28, 2023
@riot-ci
Copy link

riot-ci commented Mar 28, 2023

Murdock results

✔️ PASSED

be03323 tests/driver_ws281x: add ESP32x CI boards to test ws281x_esp32_sw

Success Failures Total Runtime
6882 0 6882 09m:57s

Artifacts

@gschorcht gschorcht force-pushed the drivers/ws281x_esp32_use_rmt branch from 862e0c7 to 0224941 Compare March 28, 2023 22:47
@gschorcht gschorcht added the Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation label Mar 28, 2023
@maribu
Copy link
Member

maribu commented Mar 29, 2023

bors r+

bors bot added a commit that referenced this pull request Mar 29, 2023
19424: drivers/ws281x: add RMT hardware support for ESP32x SoCs r=maribu a=gschorcht

### Contribution description

This PR provides support for ESP32x RMT that is used to generate WS2812B signals.

All ESP32x SoCs have a [Remote Control Peripheral (RMT)](https://docs.espressif.com/projects/esp-idf/en/v4.4.4/esp32/api-reference/peripherals/rmt.html) that can be used to generate digital waveforms, such as NEC remote control signals or WS2812B RGB LED signals. Each RMT peripheral has either 4 or 8 channels. Some ESP32x SoCs support configuring the clock sources used for each channel separately, while other ESP32x SoCs can only use a single clock source for all channels.

The advantages using the RMT 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 the [ESP-IDF high-level driver for RMT](https://docs.espressif.com/projects/esp-idf/en/v4.4.4/esp32c3/api-reference/peripherals/rmt.html) is used.This requires about 6 kBytes more ROM, about 3 kBytes more IRAM, and 88 bytes more RAM.

Therefore, either the RMT hardware implementation (module `ws2812x_esp32_hw`) as well as the bit-banging software implementation  (module  `ws2812x_esp32_hw`) can be used. RMT hardware implementation (module `ws2812x_esp32_hw`) is used by default.

Timing with hardware implementation:
![ws281x_esp32_rmt](https://user-images.githubusercontent.com/31932013/227791452-5cc1f95e-04ac-43bb-b11c-f131ab7ab1d5.png)

### Testing procedure

`tests/driver_ws281x` should still work, for example:
```
CFLAGS='-DWS281X_PARAM_PIN=GPIO45 -DWS281X_PARAM_NUMOF=47' BOARD=esp32s3-devkit make -j8 -C tests/driver_ws281x flash
```
Test Output:
https://user-images.githubusercontent.com/31932013/227791753-e6d2924e-3364-4387-870f-a56d3a9a8a80.mp4


### Issues/PRs references


Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@bors
Copy link
Contributor

bors bot commented Mar 29, 2023

Build failed:

@gschorcht
Copy link
Contributor Author

🙄 I had to add CONFIG_MODULE_WS281X_ESP32_HW=n to the CI boards to enable ws281x_esp32_sw also with TEST_KCONFIG=1.

@maribu
Copy link
Member

maribu commented Mar 29, 2023

bors retry

@bors
Copy link
Contributor

bors bot commented Mar 29, 2023

👎 Rejected by PR status

@maribu
Copy link
Member

maribu commented Mar 29, 2023

Ah, squashing is still missing

fixup! tests/driver_ws281x: add ESP32x CI boards to test ws281x_esp32_sw
@gschorcht gschorcht force-pushed the drivers/ws281x_esp32_use_rmt branch from 05f78ff to be03323 Compare March 29, 2023 06:58
@gschorcht
Copy link
Contributor Author

Ah, squashing is still missing

Yes, by intention to show the last changes.

@gschorcht
Copy link
Contributor Author

bors retry

@bors
Copy link
Contributor

bors bot commented Mar 29, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@maribu
Copy link
Member

maribu commented Mar 29, 2023

bors retry

@bors
Copy link
Contributor

bors bot commented Mar 29, 2023

Build succeeded:

@bors bors bot merged commit 198aadf into RIOT-OS:master Mar 29, 2023
@gschorcht
Copy link
Contributor Author

Thanks.

@gschorcht gschorcht deleted the drivers/ws281x_esp32_use_rmt branch March 30, 2023 22:26
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ESP Platform: This PR/issue effects ESP-based platforms Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants