From 3078091b94b17ef06c57b4ba7341f7f406cc38e9 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Wed, 20 Aug 2025 11:23:54 -0300 Subject: [PATCH 01/39] feat(rmt): adds new function to send specific number of loops Adds a new function `rmtWriteLoopingCount()` to send a specific number of times, repeating the same RMT Symbols. --- cores/esp32/esp32-hal-rmt.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index c15eadfbcd1..358bad0102a 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -124,7 +124,9 @@ bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeou bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); /** - Writing data up to the reserved memsize, looping continuously + Writing data up to the reserved memsize, looping continuously (rmtWriteLooping) or fixed + number of times (rmtWriteLoopingCount()) + is a 32 bits structure as defined by rmt_data_t type. It is possible to use the macro RMT_SYMBOLS_OF(data), if data is an array of rmt_data_t @@ -136,6 +138,7 @@ bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); will return always while it is looping. */ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols); +bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count); /** Checks if transmission is completed and the rmtChannel ready for transmitting new data. From ddf778a08954331a37b1967624858df0a65bb089 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Wed, 20 Aug 2025 11:36:10 -0300 Subject: [PATCH 02/39] feat(rmt): adds new function to send specific number of loops Adds: bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) It will send a pattern defined by `*data` RMT Symbols for `loop_count` times (repeated). This is different from `rmtWriteLooping()`, which will repeat it for ever (endless looping). --- cores/esp32/esp32-hal-rmt.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 7bca1a1b529..12b9dcc459f 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -285,8 +285,7 @@ bool rmtDeinit(int pin) { return false; } -static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool blocking, bool loop, uint32_t timeout_ms) { - rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); +static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool blocking, uint32_t loop, uint32_t timeout_ms) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; } @@ -308,6 +307,10 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl "GPIO: %d - Currently in Loop Mode: [%s] | Asked to Loop: %s, LoopCancel: %s", pin, bus->rmt_ch_is_looping ? "YES" : "NO", loop ? "YES" : "NO", loopCancel ? "YES" : "NO" ); + // loop == 1 means infinite loop. + if (loop > 1) { + log_v("GPIO: %d - Loop count: %lu times", pin, loop); + } if ((xEventGroupGetBits(bus->rmt_events) & RMT_FLAG_TX_DONE) == 0) { log_v("GPIO %d - RMT Write still pending to be completed.", pin); @@ -336,8 +339,8 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl bus->rmt_ch_is_looping = false; } else { // new writing | looping request // looping | Writing over a previous looping state is valid - if (loop) { - transmit_cfg.loop_count = -1; // enable infinite loop mode + if (loop) { + transmit_cfg.loop_count = (loop == 1) ? -1 : loop; // keeps RMT_FLAG_TX_DONE set - it never changes } else { // looping mode never sets this flag (IDF 5.1) in the callback @@ -349,7 +352,8 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl log_w("GPIO %d - RMT Transmission failed.", pin); } else { // transmit OK if (loop) { - bus->rmt_ch_is_looping = true; // for ever... until a channel canceling or new writing + bus->rmt_ch_is_looping = true; // for ever... until a channel canceling or new writing. + // NOTE: even if loop count is finite number } else { if (blocking) { // wait for transmission confirmation | timeout @@ -402,15 +406,20 @@ static bool _rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, bool wa } bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeout_ms) { - return _rmtWrite(pin, data, num_rmt_symbols, true /*blocks*/, false /*looping*/, timeout_ms); + return _rmtWrite(pin, data, num_rmt_symbols, true /*blocks*/, 0 /*looping*/, timeout_ms); } bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols) { - return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, false /*looping*/, 0 /*N/A*/); + return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 0 /*looping*/, 0 /*N/A*/); } bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { - return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, true /*looping*/, 0 /*N/A*/); + return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 1 /*looping*/, 0 /*N/A*/); +} + +// Same as rmtWriteLooping(...) but limits number of loops to "loop_count" +bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { + return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); } bool rmtTransmitCompleted(int pin) { From a9fe74d7c09024f24ea7c8054684e70e7d8b40b0 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Wed, 20 Aug 2025 11:38:48 -0300 Subject: [PATCH 03/39] fix(rmt): bad code formatting --- cores/esp32/esp32-hal-rmt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 12b9dcc459f..6db65659c8a 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -285,7 +285,8 @@ bool rmtDeinit(int pin) { return false; } -static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool blocking, uint32_t loop, uint32_t timeout_ms) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); +static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool blocking, uint32_t loop, uint32_t timeout_ms) { + rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; } From 5413697d9c74a2993e83217b2420d0c9b2148210 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Wed, 20 Aug 2025 11:39:35 -0300 Subject: [PATCH 04/39] fix(rmt): bad code formatting --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 6db65659c8a..b42eb0589b0 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -340,7 +340,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl bus->rmt_ch_is_looping = false; } else { // new writing | looping request // looping | Writing over a previous looping state is valid - if (loop) { + if (loop) { transmit_cfg.loop_count = (loop == 1) ? -1 : loop; // keeps RMT_FLAG_TX_DONE set - it never changes } else { From f5d05130acfa04d7354d5ae59353d16031358e02 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 15:35:39 -0300 Subject: [PATCH 05/39] feat(rmt): check the loop count parameter Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index b42eb0589b0..8acd405ed09 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -420,6 +420,10 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { // Same as rmtWriteLooping(...) but limits number of loops to "loop_count" bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { + if (loop_count <= 1) { + log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be greater than 1.", loop_count); + return false; + } return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); } From e9aa3490199d0acf45a6d12cbb159232f364ca54 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 15:36:31 -0300 Subject: [PATCH 06/39] feat(rmt): improve commentaries Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 8acd405ed09..89e6014910c 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -308,7 +308,10 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl "GPIO: %d - Currently in Loop Mode: [%s] | Asked to Loop: %s, LoopCancel: %s", pin, bus->rmt_ch_is_looping ? "YES" : "NO", loop ? "YES" : "NO", loopCancel ? "YES" : "NO" ); - // loop == 1 means infinite loop. + // loop parameter semantics: + // loop == 0: no looping (single transmission) + // loop == 1: infinite looping + // loop > 1: transmit the data 'loop' times if (loop > 1) { log_v("GPIO: %d - Loop count: %lu times", pin, loop); } From 36414464fc6e927ab8021f20a69ea74aaf2cd7b5 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 15:45:02 -0300 Subject: [PATCH 07/39] feat(rmt): improve commentaries --- cores/esp32/esp32-hal-rmt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 89e6014910c..d66f4c886b3 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -356,8 +356,9 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl log_w("GPIO %d - RMT Transmission failed.", pin); } else { // transmit OK if (loop) { - bus->rmt_ch_is_looping = true; // for ever... until a channel canceling or new writing. - // NOTE: even if loop count is finite number + // Even if loop count is finite number, it shall keep looping ... until a channel canceling or new writing. + bus->rmt_ch_is_looping = true; + } else { if (blocking) { // wait for transmission confirmation | timeout From 6c8007feef97e1636e09c0d19fdd64ad0e49a46d Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 16:37:12 -0300 Subject: [PATCH 08/39] feat(rmt): Refine loop handling in RMT transmission Updated loop condition to allow for greater than zero looping and added comments for clarity. --- cores/esp32/esp32-hal-rmt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index d66f4c886b3..8be67284fdb 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -355,10 +355,10 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl retCode = false; log_w("GPIO %d - RMT Transmission failed.", pin); } else { // transmit OK - if (loop) { - // Even if loop count is finite number, it shall keep looping ... until a channel canceling or new writing. - bus->rmt_ch_is_looping = true; - + if (loop > 0) { + // rmt_ch_is_looping is used as a flag to indicate that RMT is in looping execution in order to + //be cancelled whenever a new _rmtWrite() is executed while it is looping + bus->rmt_ch_is_looping = true; } else { if (blocking) { // wait for transmission confirmation | timeout @@ -423,6 +423,8 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { } // Same as rmtWriteLooping(...) but limits number of loops to "loop_count" +// loop_count shall be higher than 1 because 0 means no looping (single trnasmission) +// 1 means infinite looping (it shall use rmtWriteLooping() instead) bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { if (loop_count <= 1) { log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be greater than 1.", loop_count); From 83466738991bed29715655b75c6983696e8a078a Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 16:39:53 -0300 Subject: [PATCH 09/39] fix(rmt): bad spelling in commentary Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 8be67284fdb..475ea96edac 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -423,7 +423,7 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { } // Same as rmtWriteLooping(...) but limits number of loops to "loop_count" -// loop_count shall be higher than 1 because 0 means no looping (single trnasmission) +// loop_count shall be higher than 1 because 0 means no looping (single transmission) // 1 means infinite looping (it shall use rmtWriteLooping() instead) bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { if (loop_count <= 1) { From 182eef86e342fbf4b84c614cccf394ecd9f08b8d Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 16:43:55 -0300 Subject: [PATCH 10/39] feat(rmt): improve code clarity Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 475ea96edac..7c4930a6a54 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -343,7 +343,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl bus->rmt_ch_is_looping = false; } else { // new writing | looping request // looping | Writing over a previous looping state is valid - if (loop) { + if (loop > 0) { transmit_cfg.loop_count = (loop == 1) ? -1 : loop; // keeps RMT_FLAG_TX_DONE set - it never changes } else { From 7d8bf25c400d217ed00f6bd0892ce1ab58609eb2 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:11:52 -0300 Subject: [PATCH 11/39] feat(rmt): single logv line for all looping cases --- cores/esp32/esp32-hal-rmt.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 7c4930a6a54..3db1e42e52b 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -304,17 +304,16 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl } log_v("GPIO: %d - Request: %d RMT Symbols - %s - Timeout: %d", pin, num_rmt_symbols, blocking ? "Blocking" : "Non-Blocking", timeout_ms); - log_v( - "GPIO: %d - Currently in Loop Mode: [%s] | Asked to Loop: %s, LoopCancel: %s", pin, bus->rmt_ch_is_looping ? "YES" : "NO", loop ? "YES" : "NO", - loopCancel ? "YES" : "NO" - ); // loop parameter semantics: // loop == 0: no looping (single transmission) // loop == 1: infinite looping // loop > 1: transmit the data 'loop' times - if (loop > 1) { - log_v("GPIO: %d - Loop count: %lu times", pin, loop); - } + log_v( + "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, + bus->rmt_ch_is_looping ? "YES" : "NO", + loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : ({ char buf[20]; sprintf(buf, "%lu times", loop); buf; })), + loopCancel ? "YES" : "NO" + ); if ((xEventGroupGetBits(bus->rmt_events) & RMT_FLAG_TX_DONE) == 0) { log_v("GPIO %d - RMT Write still pending to be completed.", pin); From 00989d42e7124790f53a717c19b2eed745996e93 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:27:35 -0300 Subject: [PATCH 12/39] feat(rmt): rmtWriteLoopingCount improvement Updated rmtWriteLoopingCount to handle loop_count validation and added logic for single transmission. --- cores/esp32/esp32-hal-rmt.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 3db1e42e52b..a527e4bb73e 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -421,15 +421,20 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 1 /*looping*/, 0 /*N/A*/); } -// Same as rmtWriteLooping(...) but limits number of loops to "loop_count" -// loop_count shall be higher than 1 because 0 means no looping (single transmission) -// 1 means infinite looping (it shall use rmtWriteLooping() instead) +// Same as rmtWriteLooping(...) but it transmits the data a fixed number of times ("loop_count"). +// loop_count == 0 is invalid (no transmission); loop_count >= 1 means transmit that many times. bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { - if (loop_count <= 1) { - log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be greater than 1.", loop_count); + if (loop_count == 0) { + log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be at least 1.", loop_count); return false; } - return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); + if (loop_count == 1) { + // send the RMT symbols once using non blocking write, like "looping" it a single time + return rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); + } else { + // write the RMT symbols for loop_count times + return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); + } } bool rmtTransmitCompleted(int pin) { From 3bb70e7868ecaa814bdd8f408d40bb671a276d87 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:37:19 -0300 Subject: [PATCH 13/39] feat(rmt): improve verbose logging code --- cores/esp32/esp32-hal-rmt.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index a527e4bb73e..3b5fdc37fa8 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -303,18 +303,23 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl } } + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE log_v("GPIO: %d - Request: %d RMT Symbols - %s - Timeout: %d", pin, num_rmt_symbols, blocking ? "Blocking" : "Non-Blocking", timeout_ms); // loop parameter semantics: // loop == 0: no looping (single transmission) // loop == 1: infinite looping // loop > 1: transmit the data 'loop' times - log_v( - "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, - bus->rmt_ch_is_looping ? "YES" : "NO", - loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : ({ char buf[20]; sprintf(buf, "%lu times", loop); buf; })), - loopCancel ? "YES" : "NO" - ); - + { + char buf[20]; + log_v( + "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, + bus->rmt_ch_is_looping ? "YES" : "NO", + loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : ({ sprintf(buf, "%lu times", loop); buf; })), + loopCancel ? "YES" : "NO" + ); + } + #endif + if ((xEventGroupGetBits(bus->rmt_events) & RMT_FLAG_TX_DONE) == 0) { log_v("GPIO %d - RMT Write still pending to be completed.", pin); return false; From f2218ba4d6656758de16a8b2b4a5deaabfd2bf3f Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:39:57 -0300 Subject: [PATCH 14/39] fix(rmt): code identation Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 3b5fdc37fa8..31d702e609d 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -429,11 +429,11 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { // Same as rmtWriteLooping(...) but it transmits the data a fixed number of times ("loop_count"). // loop_count == 0 is invalid (no transmission); loop_count >= 1 means transmit that many times. bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { - if (loop_count == 0) { - log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be at least 1.", loop_count); + if (loop_count == 0) { + log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be at least 1.", loop_count); return false; } - if (loop_count == 1) { + if (loop_count == 1) { // send the RMT symbols once using non blocking write, like "looping" it a single time return rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); } else { From 55b824447e3a755d7175006beba1374f4a1fe6a2 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:40:45 -0300 Subject: [PATCH 15/39] fix(rmt): bad copy & paste of function signature Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 31d702e609d..f95d87d614a 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -435,7 +435,7 @@ bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uin } if (loop_count == 1) { // send the RMT symbols once using non blocking write, like "looping" it a single time - return rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); + return rmtWriteAsync(pin, data, num_rmt_symbols); } else { // write the RMT symbols for loop_count times return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); From fdd3ac41bc8ae5ba45234578eccbb7d530a973b0 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:46:44 -0300 Subject: [PATCH 16/39] feat(rmt): code improvement and clarity --- cores/esp32/esp32-hal-rmt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index f95d87d614a..3f6c122bb12 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -310,11 +310,12 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl // loop == 1: infinite looping // loop > 1: transmit the data 'loop' times { - char buf[20]; + char buf[12]; // place holder up to 5 + 1 + 5 + 1 bytes + sprintf(buf, "%lu times", loop); log_v( "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, bus->rmt_ch_is_looping ? "YES" : "NO", - loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : ({ sprintf(buf, "%lu times", loop); buf; })), + loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : buf), loopCancel ? "YES" : "NO" ); } @@ -428,9 +429,9 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { // Same as rmtWriteLooping(...) but it transmits the data a fixed number of times ("loop_count"). // loop_count == 0 is invalid (no transmission); loop_count >= 1 means transmit that many times. -bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { +bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { if (loop_count == 0) { - log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be at least 1.", loop_count); + log_w("rmtWriteRepeated: Invalid loop_count (%u). Must be at least 1.", loop_count); return false; } if (loop_count == 1) { From 198a49cf4723441ce5319504a4f5f58eff7daef1 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:49:11 -0300 Subject: [PATCH 17/39] feat(rmt): improved commentaries and code clarity --- cores/esp32/esp32-hal-rmt.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index 358bad0102a..4e657b28390 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -124,8 +124,8 @@ bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeou bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); /** - Writing data up to the reserved memsize, looping continuously (rmtWriteLooping) or fixed - number of times (rmtWriteLoopingCount()) + Writing data up to the reserved memsize, looping continuously (rmtWriteLooping()) or fixed + number of times (rmtWriteRepeated()) is a 32 bits structure as defined by rmt_data_t type. It is possible to use the macro RMT_SYMBOLS_OF(data), if data is an array of rmt_data_t @@ -135,10 +135,11 @@ bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); Non-Blocking mode - returns right after execution Returns on execution success, otherwise - will return always while it is looping. + will return always while it is looping mode. + looping mode is active for rmtWriteLooping() and for rmtWriteRepeated() when loop_count > 1. */ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols); -bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count); +bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count); /** Checks if transmission is completed and the rmtChannel ready for transmitting new data. From a1988048fc03b49815b7303fa1eb7e88e003140a Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 17:51:26 -0300 Subject: [PATCH 18/39] rmt(fix): improve code reliability Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 3f6c122bb12..9b6eae64530 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -311,7 +311,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl // loop > 1: transmit the data 'loop' times { char buf[12]; // place holder up to 5 + 1 + 5 + 1 bytes - sprintf(buf, "%lu times", loop); + snprintf(buf, sizeof(buf), "%lu times", loop); log_v( "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, bus->rmt_ch_is_looping ? "YES" : "NO", From 8883c30c1f1b1cf26f77fe99bcfb9bb48538d66e Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 19:44:04 -0300 Subject: [PATCH 19/39] feat(rmt): improved code readness --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 9b6eae64530..5a2f976de06 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -436,7 +436,7 @@ bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_ } if (loop_count == 1) { // send the RMT symbols once using non blocking write, like "looping" it a single time - return rmtWriteAsync(pin, data, num_rmt_symbols); + return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 0 /*looping*/, 0 /*N/A*/); } else { // write the RMT symbols for loop_count times return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); From c9c00f8923d755f2db79039fc489011d03c5a87f Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 19:48:17 -0300 Subject: [PATCH 20/39] fix(rmt): typo in commentary Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 5a2f976de06..298e934bbb5 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -310,7 +310,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl // loop == 1: infinite looping // loop > 1: transmit the data 'loop' times { - char buf[12]; // place holder up to 5 + 1 + 5 + 1 bytes + char buf[12]; // placeholder up to 5 + 1 + 5 + 1 bytes snprintf(buf, sizeof(buf), "%lu times", loop); log_v( "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, From d4b31b2b20564d9915fa7a98d3aa4f50d701c6c5 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 19:51:18 -0300 Subject: [PATCH 21/39] fix(rmt): increase buffer size for loop count loop log msg --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 298e934bbb5..a62aadfd0b8 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -310,7 +310,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl // loop == 1: infinite looping // loop > 1: transmit the data 'loop' times { - char buf[12]; // placeholder up to 5 + 1 + 5 + 1 bytes + char buf[16]; // place holder for up to maximum uint32_t value (4294967295) = 10 digits + " times" + null terminator (16 bytes) snprintf(buf, sizeof(buf), "%lu times", loop); log_v( "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, From c5993be8c3e3178259861aed54422c67da655950 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 19:54:09 -0300 Subject: [PATCH 22/39] fix(rmt): typo in commentary Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index a62aadfd0b8..e9c1dde3a15 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -310,7 +310,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl // loop == 1: infinite looping // loop > 1: transmit the data 'loop' times { - char buf[16]; // place holder for up to maximum uint32_t value (4294967295) = 10 digits + " times" + null terminator (16 bytes) + char buf[16]; // placeholder for up to maximum uint32_t value (4294967295) = 10 digits + " times" + null terminator (16 bytes) snprintf(buf, sizeof(buf), "%lu times", loop); log_v( "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, From a92d64fba935330c44a0acf9d270a8923598ea03 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 19:54:39 -0300 Subject: [PATCH 23/39] fix(rmt): typo in commentary Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index e9c1dde3a15..464a478812d 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -362,7 +362,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl } else { // transmit OK if (loop > 0) { // rmt_ch_is_looping is used as a flag to indicate that RMT is in looping execution in order to - //be cancelled whenever a new _rmtWrite() is executed while it is looping + // be cancelled whenever a new _rmtWrite() is executed while it is looping bus->rmt_ch_is_looping = true; } else { if (blocking) { From 9915febbbce575b82b1c6dd31a3c190b7d15d7cc Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 19:56:27 -0300 Subject: [PATCH 24/39] fix(rmt): buffer size for log message Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 464a478812d..9f47786ab75 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -310,7 +310,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl // loop == 1: infinite looping // loop > 1: transmit the data 'loop' times { - char buf[16]; // placeholder for up to maximum uint32_t value (4294967295) = 10 digits + " times" + null terminator (16 bytes) + char buf[17]; // placeholder for up to maximum uint32_t value (4294967295) = 10 digits + " times" (6 chars) + null terminator (17 bytes) snprintf(buf, sizeof(buf), "%lu times", loop); log_v( "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, From eedf3684e329d4e45a531ebe717dc0ae55faaf3d Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 5 Sep 2025 19:57:15 -0300 Subject: [PATCH 25/39] rmt(fix): improve code readness Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 9f47786ab75..4f50efb5916 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -435,7 +435,7 @@ bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_ return false; } if (loop_count == 1) { - // send the RMT symbols once using non blocking write, like "looping" it a single time + // send the RMT symbols once using non-blocking write (single non-looping transmission) return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 0 /*looping*/, 0 /*N/A*/); } else { // write the RMT symbols for loop_count times From a4f3e63f8c231692785c9cc2dab5b66121a7a774 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:03:50 -0300 Subject: [PATCH 26/39] feat(rmt): guarding SOC_RMT_SUPPORT_TX_LOOP_COUNT --- cores/esp32/esp32-hal-rmt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 4f50efb5916..cfa0cbe8d58 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -431,7 +431,7 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { // loop_count == 0 is invalid (no transmission); loop_count >= 1 means transmit that many times. bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { if (loop_count == 0) { - log_w("rmtWriteRepeated: Invalid loop_count (%u). Must be at least 1.", loop_count); + log_e("RMT TX GPIO %d - rmtWriteRepeated: Invalid loop_count (%u). Must be at least 1.", pin, loop_count); return false; } if (loop_count == 1) { @@ -439,7 +439,11 @@ bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_ return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 0 /*looping*/, 0 /*N/A*/); } else { // write the RMT symbols for loop_count times +#if SOC_RMT_SUPPORT_TX_LOOP_COUNT return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); +#else + log_e("RMT TX GPIO %d - rmtWriteRepeated: Loop Count is not supported. Writing failed.", pin); +#endif } } From c3b19192d0bc6f8c3a75ccabf31889a2c5953c18 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:08:48 -0300 Subject: [PATCH 27/39] feat(rmt): adds new function to the example --- .../RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index 1cdd2224ea5..1f0061d5bb6 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -128,7 +128,7 @@ rmt_data_t blink_1s_rmt_data[] = { 0, }, // Looping mode needs a Zero ending data to mark the EOF - {0, 0, 0, 0} + { 0, 0, 0, 0 } }; // RMT is at 400KHz with a 2.5us tick @@ -185,7 +185,7 @@ rmt_data_t blink_500ms_rmt_data[] = { 0, }, // Looping mode needs a Zero ending data to mark the EOF - {0, 0, 0, 0} + { 0, 0, 0, 0 } }; // RMT is at 400KHz with a 2.5us tick @@ -218,7 +218,7 @@ rmt_data_t blink_250ms_rmt_data[] = { 0, }, // Looping mode needs a Zero ending data to mark the EOF - {0, 0, 0, 0} + { 0, 0, 0, 0 } }; void RMT_Mixed_Write_Blink() { @@ -244,7 +244,8 @@ void RMT_Mixed_Write_Blink() { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking OFF for 1 seconds"); delay(1000); @@ -269,13 +270,34 @@ void RMT_Loop_Write_Blink() { delay(5000); Serial.println("Blinking OFF for 2 seconds"); - rmt_data_t blink_STOP_rmt_data[] = {{0, 0, 0, 0}}; + rmt_data_t blink_STOP_rmt_data[] = { { 0, 0, 0, 0 } }; if (!rmtWrite(BLINK_GPIO, blink_STOP_rmt_data, RMT_SYMBOLS_OF(blink_STOP_rmt_data), RMT_WAIT_FOR_EVER)) { Serial.println("===> rmtWrite Blink STOP Error!"); } delay(2000); } +void RMT_Repeated_Write_Blink() { + Serial.println("Using RMT Writing repeated N times to blink an LED."); + Serial.println("Blinking at 1s on + 1s off :: 2 blinks"); + // repeating blink_1s_rmt_data (1s on + 1s off) 2 times for 2 blinks + if (!rmtWriteRepeated(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 1, 2)) { + Serial.println("===> rmtWrite Blink 1s Error!"); + } + Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks"); + // repeating blink_500ms_rmt_data (500ms on + 500ms off) 4 times for 4 blinks + if (!rmtWriteRepeated(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1, 4)) { + Serial.println("===> rmtWrite Blink 0.5s Error!"); + } + Serial.println("Blinking at 250ms on + 250ms off :: 8 blinks"); + // repeating blink_250ms_rmt_data (250ms on + 250ms off) 8 times for 8 blinks + if (!rmtWriteRepeated(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1, 8)) { + Serial.println("===> rmtWrite Blink 0.25s Error!"); + } + Serial.println("Blinking is OFF for 2 seconds"); + delay(2000); +} + void RMT_Single_Write_Blocking_Blink() { Serial.println("Using RMT Writing and its Completion to blink an LED."); Serial.println("Blinking at 1s on + 1s off :: 2 blinks"); @@ -308,7 +330,8 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 1s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking at 500ms on + 500ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { @@ -316,7 +339,8 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 0.5s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { @@ -324,7 +348,8 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking OFF for 1 seconds"); delay(1000); @@ -356,6 +381,7 @@ void setup() { void loop() { RMT_Write_Aync_Non_Blocking_Blink(); RMT_Loop_Write_Blink(); + RMT_Repeated_Write_Blink(); RMT_Single_Write_Blocking_Blink(); Serial.println("\nStarting OVER...\n"); } From b9a054f93a1356c2977bb35d5b3eb50525c6019a Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:19:56 -0300 Subject: [PATCH 28/39] fix(rmt): remove repeated function name in log msg --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index cfa0cbe8d58..6461f81a81f 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -431,7 +431,7 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { // loop_count == 0 is invalid (no transmission); loop_count >= 1 means transmit that many times. bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { if (loop_count == 0) { - log_e("RMT TX GPIO %d - rmtWriteRepeated: Invalid loop_count (%u). Must be at least 1.", pin, loop_count); + log_e("RMT TX GPIO %d : Invalid loop_count (%u). Must be at least 1.", pin, loop_count); return false; } if (loop_count == 1) { From 5ab1ee5db1e2d0920445d1eb7c59bedbeb54dee9 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:20:32 -0300 Subject: [PATCH 29/39] fix(rmt): remove repeated function name in log msg --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 6461f81a81f..6809ba4442a 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -442,7 +442,7 @@ bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_ #if SOC_RMT_SUPPORT_TX_LOOP_COUNT return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); #else - log_e("RMT TX GPIO %d - rmtWriteRepeated: Loop Count is not supported. Writing failed.", pin); + log_e("RMT TX GPIO %d : Loop Count is not supported. Writing failed.", pin); #endif } } From 0682d371fcdcbd6c631af00fdb91c4a36d7b80ee Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:53:40 -0300 Subject: [PATCH 30/39] fix(rmt): fixes the example to wait for rmt TX --- .../ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index 1f0061d5bb6..a639071d5b7 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -281,19 +281,22 @@ void RMT_Repeated_Write_Blink() { Serial.println("Using RMT Writing repeated N times to blink an LED."); Serial.println("Blinking at 1s on + 1s off :: 2 blinks"); // repeating blink_1s_rmt_data (1s on + 1s off) 2 times for 2 blinks - if (!rmtWriteRepeated(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 1, 2)) { + if (!rmtWriteRepeated(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data), 2)) { Serial.println("===> rmtWrite Blink 1s Error!"); } + delay(4000 + 1000); // it should blink 2 times and stop automatically Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks"); // repeating blink_500ms_rmt_data (500ms on + 500ms off) 4 times for 4 blinks - if (!rmtWriteRepeated(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1, 4)) { + if (!rmtWriteRepeated(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data), 4)) { Serial.println("===> rmtWrite Blink 0.5s Error!"); } + delay(4000 + 1000); // it should blink 4 times and stop automatically Serial.println("Blinking at 250ms on + 250ms off :: 8 blinks"); // repeating blink_250ms_rmt_data (250ms on + 250ms off) 8 times for 8 blinks - if (!rmtWriteRepeated(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1, 8)) { + if (!rmtWriteRepeated(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data), 8)) { Serial.println("===> rmtWrite Blink 0.25s Error!"); } + delay(4000 + 1000); // it should blink 8 times and stop automatically Serial.println("Blinking is OFF for 2 seconds"); delay(2000); } From 7da188541700a5e0779550a8792192ff80613ed7 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:56:02 -0300 Subject: [PATCH 31/39] fix(rmt): fixes bad code formating --- libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index a639071d5b7..b079e4a2b4b 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -351,8 +351,7 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)) - ; + while (!rmtTransmitCompleted(BLINK_GPIO)); } Serial.println("Blinking OFF for 1 seconds"); delay(1000); From 85113f97fa34e1a84455d9ea1469271f8a98110b Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:56:19 -0300 Subject: [PATCH 32/39] fix(rmt): fixes bad code formating --- libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index b079e4a2b4b..0930bd2906c 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -342,8 +342,7 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 0.5s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)) - ; + while (!rmtTransmitCompleted(BLINK_GPIO)); } Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { From d6d715ab6a18790a6ca68806828303827508db7a Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:56:35 -0300 Subject: [PATCH 33/39] fix(rmt): fixes bad code formating --- libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index 0930bd2906c..df2005213e1 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -333,8 +333,7 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 1s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)) - ; + while (!rmtTransmitCompleted(BLINK_GPIO)); } Serial.println("Blinking at 500ms on + 500ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { From 8775dd1637b8849b63f8781dac6284841169caea Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:56:52 -0300 Subject: [PATCH 34/39] fix(rmt): fixes bad code formating --- libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index df2005213e1..002a92e13c4 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -244,8 +244,7 @@ void RMT_Mixed_Write_Blink() { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)) - ; + while (!rmtTransmitCompleted(BLINK_GPIO)); } Serial.println("Blinking OFF for 1 seconds"); delay(1000); From 4d836d030f15da064474c6b07c2852e9e203fee7 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 00:59:21 -0300 Subject: [PATCH 35/39] fix(rmt): commentary complement --- cores/esp32/esp32-hal-rmt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index 4e657b28390..d87a4d6897b 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -125,7 +125,7 @@ bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); /** Writing data up to the reserved memsize, looping continuously (rmtWriteLooping()) or fixed - number of times (rmtWriteRepeated()) + number of times (rmtWriteRepeated()) is a 32 bits structure as defined by rmt_data_t type. It is possible to use the macro RMT_SYMBOLS_OF(data), if data is an array of rmt_data_t From 7fffb38642c2f5741ffecb53c8981ea5e9be477c Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 01:07:22 -0300 Subject: [PATCH 36/39] fix(rmt): adds missing return value Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 6809ba4442a..c75cda3fb08 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -443,6 +443,7 @@ bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_ return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/); #else log_e("RMT TX GPIO %d : Loop Count is not supported. Writing failed.", pin); + return false; #endif } } From d1434bd486e893163d35658fd8a9e32651c6c73d Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 6 Sep 2025 01:10:10 -0300 Subject: [PATCH 37/39] feat(rmt): improve commentaries Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index c75cda3fb08..436e34cfd97 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -428,7 +428,7 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { } // Same as rmtWriteLooping(...) but it transmits the data a fixed number of times ("loop_count"). -// loop_count == 0 is invalid (no transmission); loop_count >= 1 means transmit that many times. +// loop_count == 0 is invalid (no transmission); loop_count == 1 transmits once (no looping); loop_count > 1 transmits the data repeatedly (looping). bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) { if (loop_count == 0) { log_e("RMT TX GPIO %d : Invalid loop_count (%u). Must be at least 1.", pin, loop_count); From 87cce35eb4f97237f91e3953a94e01c5442dd206 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 10 Sep 2025 12:14:33 +0000 Subject: [PATCH 38/39] ci(pre-commit): Apply automatic fixes --- cores/esp32/esp32-hal-rmt.c | 14 ++++++-------- cores/esp32/esp32-hal-rmt.h | 6 +++--- .../examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 14 +++++++------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 436e34cfd97..146f40f174b 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -303,7 +303,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl } } - #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE +#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE log_v("GPIO: %d - Request: %d RMT Symbols - %s - Timeout: %d", pin, num_rmt_symbols, blocking ? "Blocking" : "Non-Blocking", timeout_ms); // loop parameter semantics: // loop == 0: no looping (single transmission) @@ -313,14 +313,12 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl char buf[17]; // placeholder for up to maximum uint32_t value (4294967295) = 10 digits + " times" (6 chars) + null terminator (17 bytes) snprintf(buf, sizeof(buf), "%lu times", loop); log_v( - "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, - bus->rmt_ch_is_looping ? "YES" : "NO", - loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : buf), - loopCancel ? "YES" : "NO" + "GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, bus->rmt_ch_is_looping ? "YES" : "NO", + loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : buf), loopCancel ? "YES" : "NO" ); } - #endif - +#endif + if ((xEventGroupGetBits(bus->rmt_events) & RMT_FLAG_TX_DONE) == 0) { log_v("GPIO %d - RMT Write still pending to be completed.", pin); return false; @@ -363,7 +361,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl if (loop > 0) { // rmt_ch_is_looping is used as a flag to indicate that RMT is in looping execution in order to // be cancelled whenever a new _rmtWrite() is executed while it is looping - bus->rmt_ch_is_looping = true; + bus->rmt_ch_is_looping = true; } else { if (blocking) { // wait for transmission confirmation | timeout diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index d87a4d6897b..2698f9dd898 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -124,9 +124,9 @@ bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeou bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); /** - Writing data up to the reserved memsize, looping continuously (rmtWriteLooping()) or fixed - number of times (rmtWriteRepeated()) - + Writing data up to the reserved memsize, looping continuously (rmtWriteLooping()) or fixed + number of times (rmtWriteRepeated()) + is a 32 bits structure as defined by rmt_data_t type. It is possible to use the macro RMT_SYMBOLS_OF(data), if data is an array of rmt_data_t diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index 002a92e13c4..df906588479 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -128,7 +128,7 @@ rmt_data_t blink_1s_rmt_data[] = { 0, }, // Looping mode needs a Zero ending data to mark the EOF - { 0, 0, 0, 0 } + {0, 0, 0, 0} }; // RMT is at 400KHz with a 2.5us tick @@ -185,7 +185,7 @@ rmt_data_t blink_500ms_rmt_data[] = { 0, }, // Looping mode needs a Zero ending data to mark the EOF - { 0, 0, 0, 0 } + {0, 0, 0, 0} }; // RMT is at 400KHz with a 2.5us tick @@ -218,7 +218,7 @@ rmt_data_t blink_250ms_rmt_data[] = { 0, }, // Looping mode needs a Zero ending data to mark the EOF - { 0, 0, 0, 0 } + {0, 0, 0, 0} }; void RMT_Mixed_Write_Blink() { @@ -269,7 +269,7 @@ void RMT_Loop_Write_Blink() { delay(5000); Serial.println("Blinking OFF for 2 seconds"); - rmt_data_t blink_STOP_rmt_data[] = { { 0, 0, 0, 0 } }; + rmt_data_t blink_STOP_rmt_data[] = {{0, 0, 0, 0}}; if (!rmtWrite(BLINK_GPIO, blink_STOP_rmt_data, RMT_SYMBOLS_OF(blink_STOP_rmt_data), RMT_WAIT_FOR_EVER)) { Serial.println("===> rmtWrite Blink STOP Error!"); } @@ -283,19 +283,19 @@ void RMT_Repeated_Write_Blink() { if (!rmtWriteRepeated(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data), 2)) { Serial.println("===> rmtWrite Blink 1s Error!"); } - delay(4000 + 1000); // it should blink 2 times and stop automatically + delay(4000 + 1000); // it should blink 2 times and stop automatically Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks"); // repeating blink_500ms_rmt_data (500ms on + 500ms off) 4 times for 4 blinks if (!rmtWriteRepeated(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data), 4)) { Serial.println("===> rmtWrite Blink 0.5s Error!"); } - delay(4000 + 1000); // it should blink 4 times and stop automatically + delay(4000 + 1000); // it should blink 4 times and stop automatically Serial.println("Blinking at 250ms on + 250ms off :: 8 blinks"); // repeating blink_250ms_rmt_data (250ms on + 250ms off) 8 times for 8 blinks if (!rmtWriteRepeated(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data), 8)) { Serial.println("===> rmtWrite Blink 0.25s Error!"); } - delay(4000 + 1000); // it should blink 8 times and stop automatically + delay(4000 + 1000); // it should blink 8 times and stop automatically Serial.println("Blinking is OFF for 2 seconds"); delay(2000); } From ba60ffa590c8d10d6a704d90cd7d8c4980296854 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Wed, 10 Sep 2025 12:20:08 -0300 Subject: [PATCH 39/39] fix(rmt): typo in commentary --- cores/esp32/esp32-hal-rmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 146f40f174b..6d8a6c7dfae 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -360,7 +360,7 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl } else { // transmit OK if (loop > 0) { // rmt_ch_is_looping is used as a flag to indicate that RMT is in looping execution in order to - // be cancelled whenever a new _rmtWrite() is executed while it is looping + // be canceled whenever a new _rmtWrite() is executed while it is looping bus->rmt_ch_is_looping = true; } else { if (blocking) {