Skip to content

Commit

Permalink
RMT Legacy Driver option (#9941)
Browse files Browse the repository at this point in the history
* 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 <32426024+lucasssvaz@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 28, 2024
1 parent 4a6437d commit 3686344
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ repos:
hooks:
- id: clang-format
types_or: [c, c++]
exclude: ^.*\/build_opt\.h$
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "22.10.0"
hooks:
Expand Down
12 changes: 11 additions & 1 deletion cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#include "hal/gpio_hal.h"
#include "soc/soc_caps.h"

// RGB_BUILTIN is defined in pins_arduino.h
// If RGB_BUILTIN is defined, it will be used as a pin number for the RGB LED
// If RGB_BUILTIN has a side effect that prevents using RMT Legacy driver in IDF 5.1
// Define ESP32_ARDUINO_NO_RGB_BUILTIN in build_opt.h or through CLI to disable RGB_BUILTIN
#ifdef ESP32_ARDUINO_NO_RGB_BUILTIN
#ifdef RGB_BUILTIN
#undef RGB_BUILTIN
#endif
#endif

// It fixes lack of pin definition for S3 and for any future SoC
// this function works for ESP32, ESP32-S2 and ESP32-S3 - including the C3, it will return -1 for any pin
#if SOC_TOUCH_SENSOR_NUM > 0
Expand Down Expand Up @@ -159,7 +169,7 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
return;
}
#endif
#endif // RGB_BUILTIN
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
gpio_set_level((gpio_num_t)pin, val);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This example demonstrates how to use the file build_opt.h to disable the new RMT Driver
* Note that this file shall be added the Arduino project
*
* If the content of this file changes, it is necessary to delete the compiled Arduino IDE cache
* It can be done by changing, for instance, the "Core Debug Level" option, forcing the system to rebuild the Arduino Core
*
*/

#ifndef ESP32_ARDUINO_NO_RGB_BUILTIN

// add the file "build_opt.h" to your Arduino project folder with "-DESP32_ARDUINO_NO_RGB_BUILTIN" to use the RMT Legacy driver
#error "ESP32_ARDUINO_NO_RGB_BUILTIN is not defined, this example is intended to demonstrate the RMT Legacy driver.
#error "Please add the file 'build_opt.h' with '-DESP32_ARDUINO_NO_RGB_BUILTIN' to your Arduino project folder."
#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'"

#else

// add the file "build_opt.h" to your Arduino project folder with "-DESP32_ARDUINO_NO_RGB_BUILTIN" to use the RMT Legacy driver
// neoPixelWrite() is a function that writes to the RGB LED and it won't be available here
#include "driver/rmt.h"

bool installed = false;

void setup() {
Serial.begin(115200);
Serial.println("This sketch is using the RMT Legacy driver.");
installed = rmt_driver_install(RMT_CHANNEL_0, 0, 0) == ESP_OK;
}

void loop() {
String msg = "RMT Legacy driver is installed: ";
msg += (char *)(installed ? "Yes." : "No.");
Serial.println(msg);
delay(5000);
}

#endif // ESP32_ARDUINO_NO_RGB_BUILTIN
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-DESP32_ARDUINO_NO_RGB_BUILTIN

0 comments on commit 3686344

Please sign in to comment.