Skip to content

Commit 00989d4

Browse files
authored
feat(rmt): rmtWriteLoopingCount improvement
Updated rmtWriteLoopingCount to handle loop_count validation and added logic for single transmission.
1 parent 7d8bf25 commit 00989d4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cores/esp32/esp32-hal-rmt.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,20 @@ bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) {
421421
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 1 /*looping*/, 0 /*N/A*/);
422422
}
423423

424-
// Same as rmtWriteLooping(...) but limits number of loops to "loop_count"
425-
// loop_count shall be higher than 1 because 0 means no looping (single transmission)
426-
// 1 means infinite looping (it shall use rmtWriteLooping() instead)
424+
// Same as rmtWriteLooping(...) but it transmits the data a fixed number of times ("loop_count").
425+
// loop_count == 0 is invalid (no transmission); loop_count >= 1 means transmit that many times.
427426
bool rmtWriteLoopingCount(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) {
428-
if (loop_count <= 1) {
429-
log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be greater than 1.", loop_count);
427+
if (loop_count == 0) {
428+
log_w("rmtWriteLoopingCount: Invalid loop_count (%u). Must be at least 1.", loop_count);
430429
return false;
431430
}
432-
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/);
431+
if (loop_count == 1) {
432+
// send the RMT symbols once using non blocking write, like "looping" it a single time
433+
return rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols);
434+
} else {
435+
// write the RMT symbols for loop_count times
436+
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/);
437+
}
433438
}
434439

435440
bool rmtTransmitCompleted(int pin) {

0 commit comments

Comments
 (0)