From b2327260cc28060488626262c053c25af333d1bb Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 12 Feb 2024 19:03:32 -0300 Subject: [PATCH 01/10] RMT (featt): adds a new function to set EOT level after RMT writing --- cores/esp32/esp32-hal-rmt.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index fedc75dba40..20b51c9ac64 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -76,6 +76,18 @@ typedef union { */ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t memsize, uint32_t frequency_Hz); +/** + Sets the End of Transmission level to be set the when the RMT transmission ends. + This function affects how rmtWrite(), rmtWriteAsync() or rmtWriteLooping() will set the pin after writing the data. + The default EOT level is LOW, in case this function isn't used before RMT Writing. + This level can be set for each RMT pin and can change between writings to the same pin. + + shall be Zero (LOW) or non-zero (HIGH) value. + It only affects the transmission process, therefore, it doesn't affect any IDLE LEVEL before starting the RMT transmission. + The pre-transmission idle level can be set manually calling, for instance, digitalWrite(pin, Level). +*/ +void rmtSetEOT(int pin, uint8_t EOT_Level); + /** Sending data in Blocking Mode. is a 32 bits structure as defined by rmt_data_t type. From 534d5492ff912d8b6105923e886895e238bd7897 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 12 Feb 2024 19:26:12 -0300 Subject: [PATCH 02/10] RMT (feat): adds new feature to set the EOT level after writing RMT channel --- cores/esp32/esp32-hal-rmt.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 4d19d52638d..ea742d69614 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -61,6 +61,7 @@ struct rmt_obj_s { bool rmt_ch_is_looping; // Is this RMT TX Channel in LOOPING MODE? size_t *num_symbols_read; // Pointer to the number of RMT symbol read by IDF RMT RX Done uint32_t frequency_Hz; // RMT Frequency + uint8_t rmt_EOT_Level; // RMT End of Transmission Level - default it LOW #if !CONFIG_DISABLE_HAL_LOCKS SemaphoreHandle_t g_rmt_objlocks; // Channel Semaphore Lock @@ -185,6 +186,19 @@ static bool _rmtDetachBus(void *busptr) Public method definitions */ +void rmtSetEOT(int pin, uint8_t EOT_Level) +{ + rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); + if (bus == NULL) { + return false; + } + if (!_rmtCheckDirection(pin, RMT_TX_MODE, __FUNCTION__)) { + return false; + } + + bus->rmt_EOT_Level = EOT_Level > 0 ? 1 : 0; +} + bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t frequency_Hz, float duty_percent) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); @@ -316,6 +330,10 @@ static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool bl rmt_enable(bus->rmt_channel_h); bus->rmt_ch_is_looping = false; // not looping anymore } + // sets the End of trnasmission level to HIGH if the user has requested so + if (bus->rmt_EOT_Level) { + transmit_cfg.eot_level = 1; // EOT is HIGH + } if (loopCancel) { // just resets and releases the channel, maybe, already done above, then exits bus->rmt_ch_is_looping = false; @@ -487,7 +505,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ // store the RMT Freq to check Filter and Idle valid values in the RMT API bus->frequency_Hz = frequency_Hz; // pulses with width smaller than min_ns will be ignored (as a glitch) - bus->signal_range_min_ns = 0; // disabled + //bus->signal_range_min_ns = 0; // disabled --> not necessary CALLOC set all to ZERO. // RMT stops reading if the input stays idle for longer than max_ns bus->signal_range_max_ns = (1000000000 / frequency_Hz) * RMT_LL_MAX_IDLE_VALUE; // maximum possible // creates the event group to control read_done and write_done From cd388eeb28d745c2b4f89d8f1de27ff5a43b2309 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 12 Feb 2024 19:45:26 -0300 Subject: [PATCH 03/10] adds return value to rmtSetEOT() --- cores/esp32/esp32-hal-rmt.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index 20b51c9ac64..dd7f51aa0db 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -85,6 +85,8 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mems shall be Zero (LOW) or non-zero (HIGH) value. It only affects the transmission process, therefore, it doesn't affect any IDLE LEVEL before starting the RMT transmission. The pre-transmission idle level can be set manually calling, for instance, digitalWrite(pin, Level). + + Returns when EOT has been correctly set for , otherwise. */ void rmtSetEOT(int pin, uint8_t EOT_Level); From 52d1fa4be4d633162db3745717e0c366f6a465ca Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 12 Feb 2024 19:46:12 -0300 Subject: [PATCH 04/10] adds bool return to rmtSetEOT() --- 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 dd7f51aa0db..68c742bced4 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -88,7 +88,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mems Returns when EOT has been correctly set for , otherwise. */ -void rmtSetEOT(int pin, uint8_t EOT_Level); +bool rmtSetEOT(int pin, uint8_t EOT_Level); /** Sending data in Blocking Mode. From 745cdfbf9e6a994b28acc5751582dbf85761d55f Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 12 Feb 2024 19:47:41 -0300 Subject: [PATCH 05/10] adds return value to the rmtSetEOT() function --- 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 ea742d69614..8abc8e5e971 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -186,7 +186,7 @@ static bool _rmtDetachBus(void *busptr) Public method definitions */ -void rmtSetEOT(int pin, uint8_t EOT_Level) +bool rmtSetEOT(int pin, uint8_t EOT_Level) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { @@ -197,6 +197,7 @@ void rmtSetEOT(int pin, uint8_t EOT_Level) } bus->rmt_EOT_Level = EOT_Level > 0 ? 1 : 0; + return true; } bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t frequency_Hz, float duty_percent) From a8133e7eb4eedc76b69b121c9ec38815a5ac505f Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 12 Feb 2024 20:03:48 -0300 Subject: [PATCH 06/10] FIX (rmt): fixes eot_level setting using flags in the TX structure --- 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 8abc8e5e971..1f7a2e18fe1 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -333,7 +333,7 @@ static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool bl } // sets the End of trnasmission level to HIGH if the user has requested so if (bus->rmt_EOT_Level) { - transmit_cfg.eot_level = 1; // EOT is HIGH + transmit_cfg.flags.eot_level = 1; // EOT is HIGH } if (loopCancel) { // just resets and releases the channel, maybe, already done above, then exits From 52bda1c738a0330d0e6d089bf4c9bfbd4b0e4a58 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 12 Feb 2024 20:57:11 -0300 Subject: [PATCH 07/10] RMT(feat): Create RMT_EndOfTransmissionState.ino example --- .../RMT_EndOfTransmissionState.ino | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino diff --git a/libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino b/libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino new file mode 100644 index 00000000000..90c4e4f7d08 --- /dev/null +++ b/libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino @@ -0,0 +1,59 @@ +#define BLINK_GPIO 2 +#define EOT_INITIAL_STATE_TIME_MS 1000 + +// BLINK_GPIO shall start at RMT_EOT (HIGH or LOW) as initial state for EOT_INITIAL_STATE_TIME_MS, +// BLINK: 1 second ON, 1 second OFF and then return/stay to RMT_EOT level at the end. +#define RMT_EOT HIGH + +// RMT is at 400KHz with a 2.5us tick +// This RMT data sends a 0.5Hz pulse with 1s High and 1s Low signal +rmt_data_t blink_1s_rmt_data[] = { + // 400,000 x 2.5us = 1 second ON + {25000, 1, 25000, 1,}, + {25000, 1, 25000, 1,}, + {25000, 1, 25000, 1,}, + {25000, 1, 25000, 1,}, + {25000, 1, 25000, 1,}, + {25000, 1, 25000, 1,}, + {25000, 1, 25000, 1,}, + {25000, 1, 25000, 1,}, + // 400,000 x 2.5us = 1 second OFF + {25000, 0, 25000, 0,}, + {25000, 0, 25000, 0,}, + {25000, 0, 25000, 0,}, + {25000, 0, 25000, 0,}, + {25000, 0, 25000, 0,}, + {25000, 0, 25000, 0,}, + {25000, 0, 25000, 0,}, + {25000, 0, 25000, 0,}, + // Looping mode needs a Zero ending data to mark the EOF + {0, 0, 0, 0} +}; + +void setup() { + Serial.begin(115200); + Serial.println("Starting Blink testing..."); + Serial.flush(); + + // 1 RMT Block has 64 RMT_SYMBOLS (ESP32|ESP32S2) or 48 RMT_SYMBOLS (ESP32C3|ESP32S3) + if (!rmtInit(BLINK_GPIO, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 400000)) { //2.5us tick + Serial.println("===> rmtInit Error!"); + } + + // sets the End of Transmission Level to HIGH, after writing to the pin. DEFAULT is LOW. + rmtSetEOT(BLINK_GPIO, RMT_EOT); + // set initial RMT state by writing a single RMT data + rmt_data_t initStateSetup_rmt_data[] = { {1, RMT_EOT, 0, 0} }; + rmtWrite(BLINK_GPIO, initStateSetup_rmt_data, RMT_SYMBOLS_OF(initStateSetup_rmt_data), RMT_WAIT_FOR_EVER); + Serial.printf("\nLED GPIO%d start in the inital level %s\n", BLINK_GPIO, RMT_EOT == LOW ? "LOW" : "HIGH"); + delay(EOT_INITIAL_STATE_TIME_MS); // set initial state of the LED is set by RMT_EOT. + + // Send the data and wait until it is done - set EOT level to HIGH + Serial.printf("\nLED GPIO%d Blinks 1 second HIGH - 1 second LOW.\n", BLINK_GPIO); + if (!rmtWrite(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 2, RMT_WAIT_FOR_EVER)) { + Serial.println("===> rmtWrite Blink 1s Error!"); + } + Serial.printf("\nLED GPIO%d goes to the EOT level %s\n", BLINK_GPIO, RMT_EOT == LOW ? "LOW" : "HIGH"); +} + +void loop(){} From 6c2c5e7230e1f60586dd8378b5559d3e7b804890 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 13 Feb 2024 12:13:34 -0300 Subject: [PATCH 08/10] Update cores/esp32/esp32-hal-rmt.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com> --- cores/esp32/esp32-hal-rmt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index 68c742bced4..1b08fdae00d 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -77,10 +77,10 @@ typedef union { bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t memsize, uint32_t frequency_Hz); /** - Sets the End of Transmission level to be set the when the RMT transmission ends. + Sets the End of Transmission level to be set for the when the RMT transmission ends. This function affects how rmtWrite(), rmtWriteAsync() or rmtWriteLooping() will set the pin after writing the data. The default EOT level is LOW, in case this function isn't used before RMT Writing. - This level can be set for each RMT pin and can change between writings to the same pin. + This level can be set for each RMT pin and can be changed between writings to the same pin. shall be Zero (LOW) or non-zero (HIGH) value. It only affects the transmission process, therefore, it doesn't affect any IDLE LEVEL before starting the RMT transmission. From 04852dad037d4cccc6f36bee58ebbed9ed772cc6 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 13 Feb 2024 12:13:45 -0300 Subject: [PATCH 09/10] Update cores/esp32/esp32-hal-rmt.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@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 1f7a2e18fe1..00a37ea0e66 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -331,7 +331,7 @@ static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool bl rmt_enable(bus->rmt_channel_h); bus->rmt_ch_is_looping = false; // not looping anymore } - // sets the End of trnasmission level to HIGH if the user has requested so + // sets the End of Transmission level to HIGH if the user has requested so if (bus->rmt_EOT_Level) { transmit_cfg.flags.eot_level = 1; // EOT is HIGH } From 5181fea67bcd242ffb25d48473a35c948979505c Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 13 Feb 2024 12:14:06 -0300 Subject: [PATCH 10/10] Update cores/esp32/esp32-hal-rmt.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@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 00a37ea0e66..0755dc43ecd 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -61,7 +61,7 @@ struct rmt_obj_s { bool rmt_ch_is_looping; // Is this RMT TX Channel in LOOPING MODE? size_t *num_symbols_read; // Pointer to the number of RMT symbol read by IDF RMT RX Done uint32_t frequency_Hz; // RMT Frequency - uint8_t rmt_EOT_Level; // RMT End of Transmission Level - default it LOW + uint8_t rmt_EOT_Level; // RMT End of Transmission Level - default is LOW #if !CONFIG_DISABLE_HAL_LOCKS SemaphoreHandle_t g_rmt_objlocks; // Channel Semaphore Lock