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

RMT Legacy Driver option #9941

Merged
merged 11 commits into from
Jun 28, 2024
4 changes: 3 additions & 1 deletion cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ uint8_t RGB_BUILTIN_storage = 0;
#endif

extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
#ifdef RGB_BUILTIN
if (pin == RGB_BUILTIN) {
//use RMT to set all channels on/off
Expand All @@ -159,7 +160,8 @@ 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
#endif // ESP32_ARDUINO_NEW_RMT_DRV_OFF
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
gpio_set_level((gpio_num_t)pin, val);
} else {
Expand Down
3 changes: 3 additions & 0 deletions cores/esp32/esp32-hal-rgb-led.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "soc/soc_caps.h"

#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF

#include "esp32-hal-rgb-led.h"

void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) {
Expand Down Expand Up @@ -40,3 +42,4 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
log_e("RMT is not supported on " CONFIG_IDF_TARGET);
#endif /* SOC_RMT_SUPPORTED */
}
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */
2 changes: 2 additions & 0 deletions cores/esp32/esp32-hal-rgb-led.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MAIN_ESP32_HAL_RGB_LED_H_
#define MAIN_ESP32_HAL_RGB_LED_H_

#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -18,3 +19,4 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
#endif

#endif /* MAIN_ESP32_HAL_RGB_LED_H_ */
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */
2 changes: 2 additions & 0 deletions cores/esp32/esp32-hal-rmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "soc/soc_caps.h"
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF

#if SOC_RMT_SUPPORTED
#include "esp32-hal.h"
Expand Down Expand Up @@ -628,3 +629,4 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
}

#endif /* SOC_RMT_SUPPORTED */
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */
3 changes: 3 additions & 0 deletions cores/esp32/esp32-hal-rmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define MAIN_ESP32_HAL_RMT_H_

#include "soc/soc_caps.h"
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF

#if SOC_RMT_SUPPORTED

#ifdef __cplusplus
Expand Down Expand Up @@ -234,3 +236,4 @@ bool rmtDeinit(int pin);

#endif /* SOC_RMT_SUPPORTED */
#endif /* MAIN_ESP32_HAL_RMT_H_ */
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */
2 changes: 2 additions & 0 deletions cores/esp32/io_pin_remap.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
// cores/esp32/esp32-hal-rgb-led.h
#define neopixelWrite(pin, red_val, green_val, blue_val) neopixelWrite(digitalPinToGPIONumber(pin), red_val, green_val, blue_val)

#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
// cores/esp32/esp32-hal-rmt.h
#define rmtInit(pin, channel_direction, memsize, frequency_Hz) rmtInit(digitalPinToGPIONumber(pin), channel_direction, memsize, frequency_Hz)
#define rmtSetEOT(pin, EOT_Level) rmtSetEOT(digitalPinToGPIONumber(pin), EOT_Level)
Expand All @@ -94,6 +95,7 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
rmtSetCarrier(digitalPinToGPIONumber(pin), carrier_en, carrier_level, frequency_Hz, duty_percent)
#define rmtSetRxMinThreshold(pin, filter_pulse_ticks) rmtSetRxMinThreshold(digitalPinToGPIONumber(pin), filter_pulse_ticks)
#define rmtDeinit(pin) rmtDeinit(digitalPinToGPIONumber(pin))
#endif // ESP32_ARDUINO_NEW_RMT_DRV_OFF

// cores/esp32/esp32-hal-sigmadelta.h
#define sigmaDeltaAttach(pin, freq) sigmaDeltaAttach(digitalPinToGPIONumber(pin), freq)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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_NEW_RMT_DRV_OFF

// add the file "build_opt.h" to your Arduino project folder with "-DESP32_ARDUINO_NEW_RMT_DRV_OFF" to use the RMT Legacy driver
#warning "ESP32_ARDUINO_NEW_RMT_DRV_OFF is not defined, using new RMT driver"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Imho a warning for using a actual function is not correct.
It should be the other way around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is part of the example, it is just a way to say "this example is intended to demonstrate how to use RMT Legacy Driver within Arduino Core 3.0.x + IDF 5.x"

Please elaborate futher.

Copy link
Member

@me-no-dev me-no-dev Jun 26, 2024

Choose a reason for hiding this comment

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

I would say: make it an error and no extra code. It should never fail, right? except if we mess up platform.txt, in which case it will be used as notification that the feature broke.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have modified it. Please review it.


#define RMT_PIN 4 // Valid GPIO for ESP32, S2, S3, C3, C6 and H2
bool installed = false;

void setup() {
Serial.begin(115200);
Serial.println("This sketch uses the new RMT driver.");
installed = rmtInit(RMT_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000);
}

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

#else

// add the file "build_opt.h" to your Arduino project folder with "-DESP32_ARDUINO_NEW_RMT_DRV_OFF" 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_NEW_RMT_DRV_OFF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-DESP32_ARDUINO_NEW_RMT_DRV_OFF
Loading