Skip to content

Commit a1f228b

Browse files
committed
fix(rmt): GPIO HAL only
1 parent 2fdbe44 commit a1f228b

File tree

8 files changed

+18
-29
lines changed

8 files changed

+18
-29
lines changed

cores/esp32/esp32-hal-gpio.c

+10-2
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
@@ -151,7 +161,6 @@ uint8_t RGB_BUILTIN_storage = 0;
151161
#endif
152162

153163
extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
154-
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
155164
#ifdef RGB_BUILTIN
156165
if (pin == RGB_BUILTIN) {
157166
//use RMT to set all channels on/off
@@ -161,7 +170,6 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
161170
return;
162171
}
163172
#endif // RGB_BUILTIN
164-
#endif // ESP32_ARDUINO_NEW_RMT_DRV_OFF
165173
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
166174
gpio_set_level((gpio_num_t)pin, val);
167175
} else {

cores/esp32/esp32-hal-rgb-led.c

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "soc/soc_caps.h"
22

3-
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
4-
53
#include "esp32-hal-rgb-led.h"
64

75
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) {
@@ -42,4 +40,3 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
4240
log_e("RMT is not supported on " CONFIG_IDF_TARGET);
4341
#endif /* SOC_RMT_SUPPORTED */
4442
}
45-
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */

cores/esp32/esp32-hal-rgb-led.h

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef MAIN_ESP32_HAL_RGB_LED_H_
22
#define MAIN_ESP32_HAL_RGB_LED_H_
33

4-
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
54
#ifdef __cplusplus
65
extern "C" {
76
#endif
@@ -19,4 +18,3 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
1918
#endif
2019

2120
#endif /* MAIN_ESP32_HAL_RGB_LED_H_ */
22-
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */

cores/esp32/esp32-hal-rmt.c

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#include "soc/soc_caps.h"
16-
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
1716

1817
#if SOC_RMT_SUPPORTED
1918
#include "esp32-hal.h"
@@ -629,4 +628,3 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
629628
}
630629

631630
#endif /* SOC_RMT_SUPPORTED */
632-
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */

cores/esp32/esp32-hal-rmt.h

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define MAIN_ESP32_HAL_RMT_H_
1717

1818
#include "soc/soc_caps.h"
19-
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
2019

2120
#if SOC_RMT_SUPPORTED
2221

@@ -236,4 +235,3 @@ bool rmtDeinit(int pin);
236235

237236
#endif /* SOC_RMT_SUPPORTED */
238237
#endif /* MAIN_ESP32_HAL_RMT_H_ */
239-
#endif /* ESP32_ARDUINO_NEW_RMT_DRV_OFF */

cores/esp32/io_pin_remap.h

-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
7979
// cores/esp32/esp32-hal-rgb-led.h
8080
#define neopixelWrite(pin, red_val, green_val, blue_val) neopixelWrite(digitalPinToGPIONumber(pin), red_val, green_val, blue_val)
8181

82-
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
8382
// cores/esp32/esp32-hal-rmt.h
8483
#define rmtInit(pin, channel_direction, memsize, frequency_Hz) rmtInit(digitalPinToGPIONumber(pin), channel_direction, memsize, frequency_Hz)
8584
#define rmtSetEOT(pin, EOT_Level) rmtSetEOT(digitalPinToGPIONumber(pin), EOT_Level)
@@ -95,7 +94,6 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber);
9594
rmtSetCarrier(digitalPinToGPIONumber(pin), carrier_en, carrier_level, frequency_Hz, duty_percent)
9695
#define rmtSetRxMinThreshold(pin, filter_pulse_ticks) rmtSetRxMinThreshold(digitalPinToGPIONumber(pin), filter_pulse_ticks)
9796
#define rmtDeinit(pin) rmtDeinit(digitalPinToGPIONumber(pin))
98-
#endif // ESP32_ARDUINO_NEW_RMT_DRV_OFF
9997

10098
// cores/esp32/esp32-hal-sigmadelta.h
10199
#define sigmaDeltaAttach(pin, freq) sigmaDeltaAttach(digitalPinToGPIONumber(pin), freq)

libraries/ESP32/examples/RMT/Legacy_RMT_Driver_Compatible/Legacy_RMT_Driver_Compatible.ino

+7-15
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@
77
*
88
*/
99

10-
#ifndef ESP32_ARDUINO_NEW_RMT_DRV_OFF
10+
#ifndef ESP32_ARDUINO_NO_RGB_BUILTIN
1111

12-
// add the file "build_opt.h" to your Arduino project folder with "-DESP32_ARDUINO_NEW_RMT_DRV_OFF" to use the RMT Legacy driver
13-
#warning "ESP32_ARDUINO_NEW_RMT_DRV_OFF is not defined, using new RMT driver"
14-
15-
#define RMT_PIN 4 // Valid GPIO for ESP32, S2, S3, C3, C6 and H2
16-
bool installed = false;
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+
#warning "ESP32_ARDUINO_NO_RGB_BUILTIN is not defined, this example is intended to demonstrate the RMT Legacy driver.
14+
#warning "Please add the file 'build_opt.h' with '-DESP32_ARDUINO_NO_RGB_BUILTIN' to your Arduino project folder."
15+
#warning "Another way to disable the RGB_BUILTIN is to define it in the platformio.ini file, for instance: '-D ESP32_ARDUINO_NO_RGB_BUILTIN'"
1716

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

2420
void loop() {
25-
String msg = "RMT New driver is installed: ";
26-
msg += (char*)(installed ? "Yes." : "No.");
27-
Serial.println(msg);
28-
delay(5000);
2921
}
3022

3123
#else
3224

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

@@ -49,4 +41,4 @@ void loop() {
4941
delay(5000);
5042
}
5143

52-
#endif // ESP32_ARDUINO_NEW_RMT_DRV_OFF
44+
#endif // ESP32_ARDUINO_NO_RGB_BUILTIN
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-DESP32_ARDUINO_NEW_RMT_DRV_OFF
1+
-DESP32_ARDUINO_NO_RGB_BUILTIN

0 commit comments

Comments
 (0)