Skip to content

Commit 3686344

Browse files
SuGliderpre-commit-ci-lite[bot]lucasssvaz
authored
RMT Legacy Driver option (#9941)
* feat(rmt): allow legacy driver * feat(rmt): legacy driver example * fix(rmt): legacy driver example * fix(rmt): ESP32_ARDUINO_NEW_RMT_DRV_OFF * fix(rmt): ESP32_ARDUINO_NEW_RMT_DRV_OFF * fix(rmt): ESP32_ARDUINO_NEW_RMT_DRV_OFF * fix(rmt): GPIO HAL only * fix(rmt): error case * fix(rmt): not necessary change * ci(pre-commit): Apply automatic fixes * ci(pre-commit): Ignore build_opt in clangformat --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Lucas Saavedra Vaz <[email protected]>
1 parent 4a6437d commit 3686344

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

Diff for: .pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ repos:
3434
hooks:
3535
- id: clang-format
3636
types_or: [c, c++]
37+
exclude: ^.*\/build_opt\.h$
3738
- repo: https://github.com/psf/black-pre-commit-mirror
3839
rev: "22.10.0"
3940
hooks:

Diff for: cores/esp32/esp32-hal-gpio.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
#include "hal/gpio_hal.h"
1818
#include "soc/soc_caps.h"
1919

20+
// RGB_BUILTIN is defined in pins_arduino.h
21+
// If RGB_BUILTIN is defined, it will be used as a pin number for the RGB LED
22+
// If RGB_BUILTIN has a side effect that prevents using RMT Legacy driver in IDF 5.1
23+
// Define ESP32_ARDUINO_NO_RGB_BUILTIN in build_opt.h or through CLI to disable RGB_BUILTIN
24+
#ifdef ESP32_ARDUINO_NO_RGB_BUILTIN
25+
#ifdef RGB_BUILTIN
26+
#undef RGB_BUILTIN
27+
#endif
28+
#endif
29+
2030
// It fixes lack of pin definition for S3 and for any future SoC
2131
// this function works for ESP32, ESP32-S2 and ESP32-S3 - including the C3, it will return -1 for any pin
2232
#if SOC_TOUCH_SENSOR_NUM > 0
@@ -159,7 +169,7 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
159169
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
160170
return;
161171
}
162-
#endif
172+
#endif // RGB_BUILTIN
163173
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
164174
gpio_set_level((gpio_num_t)pin, val);
165175
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This example demonstrates how to use the file build_opt.h to disable the new RMT Driver
3+
* Note that this file shall be added the Arduino project
4+
*
5+
* If the content of this file changes, it is necessary to delete the compiled Arduino IDE cache
6+
* It can be done by changing, for instance, the "Core Debug Level" option, forcing the system to rebuild the Arduino Core
7+
*
8+
*/
9+
10+
#ifndef ESP32_ARDUINO_NO_RGB_BUILTIN
11+
12+
// add the file "build_opt.h" to your Arduino project folder with "-DESP32_ARDUINO_NO_RGB_BUILTIN" to use the RMT Legacy driver
13+
#error "ESP32_ARDUINO_NO_RGB_BUILTIN is not defined, this example is intended to demonstrate the RMT Legacy driver.
14+
#error "Please add the file 'build_opt.h' with '-DESP32_ARDUINO_NO_RGB_BUILTIN' to your Arduino project folder."
15+
#error "Another way to disable the RGB_BUILTIN is to define it in the platformio.ini file, for instance: '-D ESP32_ARDUINO_NO_RGB_BUILTIN'"
16+
17+
#else
18+
19+
// add the file "build_opt.h" to your Arduino project folder with "-DESP32_ARDUINO_NO_RGB_BUILTIN" to use the RMT Legacy driver
20+
// neoPixelWrite() is a function that writes to the RGB LED and it won't be available here
21+
#include "driver/rmt.h"
22+
23+
bool installed = false;
24+
25+
void setup() {
26+
Serial.begin(115200);
27+
Serial.println("This sketch is using the RMT Legacy driver.");
28+
installed = rmt_driver_install(RMT_CHANNEL_0, 0, 0) == ESP_OK;
29+
}
30+
31+
void loop() {
32+
String msg = "RMT Legacy driver is installed: ";
33+
msg += (char *)(installed ? "Yes." : "No.");
34+
Serial.println(msg);
35+
delay(5000);
36+
}
37+
38+
#endif // ESP32_ARDUINO_NO_RGB_BUILTIN
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-DESP32_ARDUINO_NO_RGB_BUILTIN

0 commit comments

Comments
 (0)