diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml
index 29ba2663d5..633a8a3242 100644
--- a/.github/ISSUE_TEMPLATE/bug-report.yml
+++ b/.github/ISSUE_TEMPLATE/bug-report.yml
@@ -52,6 +52,7 @@ body:
- quirc
- sh2lib
- spi_nand_flash
+ - uart_emu
- supertinycron
- thorvg
- zlib
diff --git a/.github/workflows/upload_component.yml b/.github/workflows/upload_component.yml
index e9822d6604..693fe6a513 100644
--- a/.github/workflows/upload_component.yml
+++ b/.github/workflows/upload_component.yml
@@ -63,6 +63,7 @@ jobs:
quirc;
sh2lib;
spi_nand_flash;
+ uart_emu;
supertinycron;
thorvg;
zlib;
diff --git a/.idf_build_apps.toml b/.idf_build_apps.toml
index 9441ec33ec..e5e551c728 100644
--- a/.idf_build_apps.toml
+++ b/.idf_build_apps.toml
@@ -21,6 +21,7 @@ manifest_file = [
"pid_ctrl/.build-test-rules.yml",
"qrcode/.build-test-rules.yml",
"quirc/.build-test-rules.yml",
+ "uart_emu/.build-test-rules.yml",
"zlib/.build-test-rules.yml",
"libjpeg-turbo/.build-test-rules.yml",
".build-test-rules.yml",
diff --git a/uart_emu/.build-test-rules.yml b/uart_emu/.build-test-rules.yml
new file mode 100644
index 0000000000..bc18ff8909
--- /dev/null
+++ b/uart_emu/.build-test-rules.yml
@@ -0,0 +1,4 @@
+uart_emu/example:
+ disable:
+ - if: CONFIG_SOC_RMT_SUPPORTED != 1
+ reason: Relevant only for RMT enabled targets
diff --git a/uart_emu/CHANGELOG.md b/uart_emu/CHANGELOG.md
new file mode 100644
index 0000000000..4e0918381b
--- /dev/null
+++ b/uart_emu/CHANGELOG.md
@@ -0,0 +1,3 @@
+## 1.0.0
+
+- Initial driver version, support using the RMT to emulate the UART communication
diff --git a/uart_emu/CMakeLists.txt b/uart_emu/CMakeLists.txt
new file mode 100644
index 0000000000..0b1a4996c7
--- /dev/null
+++ b/uart_emu/CMakeLists.txt
@@ -0,0 +1,17 @@
+set(srcs)
+set(public_requires)
+
+if(CONFIG_SOC_RMT_SUPPORTED)
+ list(APPEND srcs "src/uart_emu_rmt.c" "src/uart_emu_rmt_encoder.c")
+endif()
+
+# Starting from esp-idf v5.3, the drivers are moved to separate components
+if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.3")
+ list(APPEND public_requires "esp_driver_rmt")
+else()
+ list(APPEND public_requires "driver")
+endif()
+
+idf_component_register(SRCS ${srcs}
+ INCLUDE_DIRS "include"
+ REQUIRES ${public_requires})
\ No newline at end of file
diff --git a/uart_emu/LICENSE b/uart_emu/LICENSE
new file mode 100644
index 0000000000..d645695673
--- /dev/null
+++ b/uart_emu/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/uart_emu/README.md b/uart_emu/README.md
new file mode 100644
index 0000000000..db625b94d2
--- /dev/null
+++ b/uart_emu/README.md
@@ -0,0 +1,11 @@
+# UART Emulator
+
+[](https://components.espressif.com/components/espressif/uart_emu)
+
+This directory contains an implementation for software UART. Currently only RMT is supported as the software UART backend.
+
+## Documentation
+
+For detailed information about the UART EMU component, including API reference and user guides, please visit:
+
+- **Programming Guide & API Reference**: [UART EMU Documentation](https://espressif.github.io/idf-extra-components/latest/uart_emu/index.html)
diff --git a/uart_emu/docs/Doxyfile b/uart_emu/docs/Doxyfile
new file mode 100644
index 0000000000..92be4ce98e
--- /dev/null
+++ b/uart_emu/docs/Doxyfile
@@ -0,0 +1,28 @@
+# Set this to the header file you want
+INPUT = ../include/
+
+# The output directory for the generated XML documentation
+OUTPUT_DIRECTORY = doxygen_output
+
+# Warning-related settings, it's recommended to keep them enabled
+WARN_IF_UNDOC_ENUM_VAL = YES
+WARN_AS_ERROR = YES
+
+# Other common settings
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH = ../
+STRIP_FROM_INC_PATH = ../
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = YES
+OPTIMIZE_OUTPUT_FOR_C = YES
+EXPAND_ONLY_PREDEF = YES
+EXTRACT_ALL = YES
+PREDEFINED = $(ENV_DOXYGEN_DEFINES)
+HAVE_DOT = NO
+GENERATE_XML = YES
+XML_OUTPUT = xml
+GENERATE_HTML = NO
+HAVE_DOT = NO
+GENERATE_LATEX = NO
+QUIET = YES
+MARKDOWN_SUPPORT = YES
diff --git a/uart_emu/docs/book.toml b/uart_emu/docs/book.toml
new file mode 100644
index 0000000000..ccc5b5cf07
--- /dev/null
+++ b/uart_emu/docs/book.toml
@@ -0,0 +1,8 @@
+[book]
+title = "UART EMU"
+language = "en"
+
+[output.html]
+default-theme = "light"
+git-repository-url = "https://github.com/espressif/idf-extra-components/tree/master/uart_emu"
+edit-url-template = "https://github.com/espressif/idf-extra-components/edit/master/uart_emu/docs/{path}"
\ No newline at end of file
diff --git a/uart_emu/docs/src/SUMMARY.md b/uart_emu/docs/src/SUMMARY.md
new file mode 100644
index 0000000000..c4d2b090f1
--- /dev/null
+++ b/uart_emu/docs/src/SUMMARY.md
@@ -0,0 +1,13 @@
+# Summary
+
+---
+
+# Programming Guide
+
+- [UART EMU](index.md)
+
+---
+
+# API Reference
+
+- [API Reference](api.md)
diff --git a/uart_emu/docs/src/api.md b/uart_emu/docs/src/api.md
new file mode 100644
index 0000000000..6cedc20c1e
--- /dev/null
+++ b/uart_emu/docs/src/api.md
@@ -0,0 +1,9 @@
+# API Reference
+
+
+
+This file is automatically generated by esp-doxybook.
+
+DO NOT edit it manually.
+
+
diff --git a/uart_emu/docs/src/index.md b/uart_emu/docs/src/index.md
new file mode 100644
index 0000000000..0f99d961b2
--- /dev/null
+++ b/uart_emu/docs/src/index.md
@@ -0,0 +1,71 @@
+# UART EMU
+
+## Allocate UART EMULATOR Object with RMT Backend
+
+## Features
+
+- **RMT-based Implementation**: Utilizes ESP32's RMT peripheral for precise timing control
+- **Configurable Baud Rate**: Supports various baud rates
+- **Asynchronous Operation**: Non-blocking transmit and receive operations
+- **Callback Support**: Event-driven programming with TX/RX completion callbacks
+- **DMA Support(need RMT Supports DMA)**: Optional DMA acceleration for improved performance
+- **Ping-Pong Buffer**: Efficient handling of continuous data streams
+
+## Current Limitations
+
+- **Data Bits**: Only 8-bit data format supported
+- **Parity**: Only no-parity mode supported
+- **Stop Bits**: 1 or 2 stop bits supported
+- **Flow Control**: No hardware flow control support
+- **Error Detection**: Limited error detection capabilities compared to hardware UART
+
+## API Documentation
+
+For detailed API documentation, please refer to the header files:
+- [uart_emu.h](./include/uart_emu.h) - Main public API
+- [uart_emu_rmt.h](./include/uart_emu_rmt.h) - RMT-specific API
+
+## Usage Example
+
+```c
+#include "uart_emu_rmt.h"
+
+// Configuration
+uart_emu_config_t uart_config = {
+ .tx_io_num = UART_EMU_TX_PIN,
+ .rx_io_num = UART_EMU_RX_PIN,
+ .baud_rate = UART_EMU_BAUD_RATE,
+ .data_bits = UART_EMU_DATA_8_BITS,
+ .stop_bits = UART_EMU_STOP_BITS_1,
+ .parity = UART_EMU_PARITY_DISABLE,
+ .rx_buffer_size = UART_EMU_RX_BUFFER_SIZE,
+};
+uart_emu_rmt_config_t rmt_config = {
+ .tx_trans_queue_depth = UART_EMU_RMT_TX_TRANS_QUEUE_DEPTH,
+ .tx_mem_block_symbols = UART_EMU_RMT_MEM_BLOCK_SYMBOLS,
+ .rx_mem_block_symbols = UART_EMU_RMT_MEM_BLOCK_SYMBOLS,
+ .intr_priority = UART_EMU_RMT_INTR_PRIORITY,
+ .flags = {
+ .with_dma = false, // DMA feature is available on chips like ESP32-S3/P4
+ }
+};
+
+// Initialize
+uart_emu_device_handle_t uart_device;
+ESP_ERROR_CHECK(uart_emu_new_from_rmt(&uart_config, &rmt_config, &uart_device));
+
+// Transmit data
+const char *data = "Hello, World!";
+ESP_ERROR_CHECK(uart_emu_transmit(uart_device, (uint8_t *)data, strlen(data)));
+```
+
+## Performance Considerations
+
+- Use DMA when available for better performance
+- Increase interrupt priority for time-critical applications
+- Consider buffer sizes based on your application's data throughput
+- The component uses 8 RMT clock cycles per UART bit for better resolution
+
+---
+
+You can create multiple UART EMU objects with different GPIOs. The backend driver will automatically allocate sufficient RMT channels for you wherever possible. If the RMT channels are not enough, the [uart_emu_new_from_rmt](api.md#function-uart_emu_new_from_rmt) will return an error.
diff --git a/uart_emu/example/rmt_uart/CMakeLists.txt b/uart_emu/example/rmt_uart/CMakeLists.txt
new file mode 100644
index 0000000000..6e304a4f56
--- /dev/null
+++ b/uart_emu/example/rmt_uart/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 3.16)
+
+set(COMPONENTS main)
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(uart_emu_by_rmt)
diff --git a/uart_emu/example/rmt_uart/README.md b/uart_emu/example/rmt_uart/README.md
new file mode 100644
index 0000000000..6d3e96e0d8
--- /dev/null
+++ b/uart_emu/example/rmt_uart/README.md
@@ -0,0 +1,50 @@
+# UART Emulator Example (RMT backend)
+
+This example demonstrates how to emulate UART using the [uart_emu](https://components.espressif.com/component/espressif/uart_emu) component.
+
+## How to Use Example
+
+### Hardware Required
+
+* A development board with Espressif SoC
+* A USB cable for Power supply and programming
+* A UART bridge (optional, set the TX and RX pins to be the same as the loopback test if don't have)
+
+### Configure the Example
+
+Before project configuration and build, be sure to set the correct chip target using `idf.py set-target `. Then assign the proper GPIO in the [source file](main/uart_emu_main.c).
+
+### Build and Flash
+
+Run `idf.py -p PORT build flash monitor` to build, flash and monitor the project.
+
+(To exit the serial monitor, type ``Ctrl-]``.)
+
+See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects.
+
+## Example Output (loopback test)
+
+```text
+I (248) main_task: Started on CPU0
+I (248) main_task: Calling app_main()
+I (258) uart_emu_rmt: new uart emu at 0x4087cd38, baud=115200 rmt_resolution=921600
+I (268) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (278) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (288) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (298) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (308) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (318) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (328) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (338) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (348) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (358) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (368) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (378) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (388) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (398) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (408) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (418) uart_emu_rmt_example: Read len: 23, data: RMT UART, transmission
+I (478) uart_emu_rmt_example: UART transmit 16 times!
+I (478) main_task: Returned from app_main()
+
+```
diff --git a/uart_emu/example/rmt_uart/main/CMakeLists.txt b/uart_emu/example/rmt_uart/main/CMakeLists.txt
new file mode 100644
index 0000000000..17f6bcfd37
--- /dev/null
+++ b/uart_emu/example/rmt_uart/main/CMakeLists.txt
@@ -0,0 +1,4 @@
+set(srcs "uart_emu_main.c")
+
+idf_component_register(SRCS "${srcs}"
+ INCLUDE_DIRS ".")
\ No newline at end of file
diff --git a/uart_emu/example/rmt_uart/main/idf_component.yml b/uart_emu/example/rmt_uart/main/idf_component.yml
new file mode 100644
index 0000000000..d5065e1fff
--- /dev/null
+++ b/uart_emu/example/rmt_uart/main/idf_component.yml
@@ -0,0 +1,4 @@
+dependencies:
+ espressif/uart_emu:
+ version: "*"
+ override_path: "../../../"
diff --git a/uart_emu/example/rmt_uart/main/uart_emu_main.c b/uart_emu/example/rmt_uart/main/uart_emu_main.c
new file mode 100644
index 0000000000..f8c873cf8b
--- /dev/null
+++ b/uart_emu/example/rmt_uart/main/uart_emu_main.c
@@ -0,0 +1,126 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: CC0-1.0
+ */
+#include
+#include
+#include "sdkconfig.h"
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+#include "esp_log.h"
+#include "esp_check.h"
+#include "uart_emu_rmt.h"
+
+// the memory size of each RMT channel, in words (4 bytes)
+#if SOC_RMT_SUPPORT_DMA
+#define UART_EMU_RMT_MEM_BLOCK_SYMBOLS 1024
+#else
+#define UART_EMU_RMT_MEM_BLOCK_SYMBOLS SOC_RMT_MEM_WORDS_PER_CHANNEL
+#endif
+
+#define UART_EMU_RMT_INTR_PRIORITY 3 // use higher priority to avoid timing issues
+#define UART_EMU_RMT_TX_TRANS_QUEUE_DEPTH 10 // the max number of the pending tx transaction
+#define UART_EMU_RX_BUFFER_SIZE 128 // the max size of the received data, in bytes
+#define UART_EMU_RMT_RX_PINGPONG_BUFFER_SIZE 256 // in rmt symbol words, the size of the ping-pong buffer
+#define UART_EMU_TX_PIN GPIO_NUM_1
+#define UART_EMU_RX_PIN GPIO_NUM_0
+#define UART_EMU_BAUD_RATE 115200
+
+const char *TAG = "uart_emu_rmt_example";
+
+IRAM_ATTR static bool uart_emu_rmt_tx_event_cbs(uart_emu_device_handle_t tx_unit, const uart_emu_tx_done_event_data_t *edata, void *user_ctx)
+{
+ BaseType_t high_task_wakeup = pdFALSE;
+ TaskHandle_t task = (TaskHandle_t)user_ctx;
+ vTaskNotifyGiveFromISR(task, &high_task_wakeup);
+ return high_task_wakeup == pdTRUE;
+}
+
+IRAM_ATTR static bool uart_emu_rmt_rx_event_cbs(uart_emu_device_handle_t rx_unit, const uart_emu_rx_done_event_data_t *edata, void *user_ctx)
+{
+ BaseType_t high_task_wakeup = pdFALSE;
+ QueueHandle_t receive_queue = (QueueHandle_t)user_ctx;
+ xQueueSendFromISR(receive_queue, edata, &high_task_wakeup);
+ return high_task_wakeup == pdTRUE;
+}
+
+void uart_read_task(void *pvParameters)
+{
+ uart_emu_device_handle_t uart_device = (uart_emu_device_handle_t)pvParameters;
+ QueueHandle_t receive_queue = xQueueCreate(10, sizeof(uart_emu_rx_done_event_data_t)); // queue for receive rmt rx done event
+ assert(receive_queue != NULL);
+ uart_emu_event_rx_callbacks_t uart_rx_cbs = {
+ .on_rx_trans_done = uart_emu_rmt_rx_event_cbs,
+ };
+ ESP_ERROR_CHECK(uart_emu_register_rx_event_callbacks(uart_device, &uart_rx_cbs, receive_queue));
+ uart_emu_rx_done_event_data_t rx_done_event_data;
+ rmt_symbol_word_t *receive_symbols = heap_caps_calloc(UART_EMU_RMT_RX_PINGPONG_BUFFER_SIZE, sizeof(rmt_symbol_word_t),
+ MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);
+ assert(receive_symbols != NULL);
+
+ char read_buffer[UART_EMU_RX_BUFFER_SIZE] = {0};
+ while (1) {
+ /* Read from the UART */
+ ESP_ERROR_CHECK(uart_emu_receive(uart_device, (uint8_t *)receive_symbols, UART_EMU_RMT_RX_PINGPONG_BUFFER_SIZE * sizeof(rmt_symbol_word_t)));
+ if (xQueueReceive(receive_queue, &rx_done_event_data, portMAX_DELAY)) {
+ // decode the received symbols to data
+ int read_len = uart_emu_rmt_decode_data(uart_device, &rx_done_event_data, (uint8_t *)read_buffer, sizeof(read_buffer), true);
+ if (read_len > 0) {
+ ESP_LOGI(TAG, "Read len: %d, data: %s", read_len, read_buffer);
+ memset(read_buffer, 0, sizeof(read_buffer));
+ }
+ }
+ }
+}
+
+void app_main(void)
+{
+ uart_emu_config_t uart_config = {
+ .tx_io_num = UART_EMU_TX_PIN,
+ .rx_io_num = UART_EMU_RX_PIN,
+ .baud_rate = UART_EMU_BAUD_RATE,
+ .data_bits = UART_EMU_DATA_8_BITS,
+ .stop_bits = UART_EMU_STOP_BITS_1,
+ .parity = UART_EMU_PARITY_DISABLE,
+ .rx_buffer_size = UART_EMU_RX_BUFFER_SIZE,
+ };
+ uart_emu_rmt_config_t rmt_config = {
+ .tx_trans_queue_depth = UART_EMU_RMT_TX_TRANS_QUEUE_DEPTH,
+ .tx_mem_block_symbols = UART_EMU_RMT_MEM_BLOCK_SYMBOLS,
+ .rx_mem_block_symbols = UART_EMU_RMT_MEM_BLOCK_SYMBOLS,
+ .intr_priority = UART_EMU_RMT_INTR_PRIORITY,
+#if SOC_RMT_SUPPORT_DMA
+ .flags.with_dma = true,
+#endif
+ };
+ uart_emu_device_handle_t uart_device = NULL;
+ /* Initialize and configure the software UART port */
+ ESP_ERROR_CHECK(uart_emu_new_from_rmt(&uart_config, &rmt_config, &uart_device));
+ uart_emu_event_tx_callbacks_t uart_tx_cbs = {
+ .on_tx_trans_done = uart_emu_rmt_tx_event_cbs,
+ };
+ ESP_ERROR_CHECK(uart_emu_register_tx_event_callbacks(uart_device, &uart_tx_cbs, xTaskGetCurrentTaskHandle()));
+
+ // create a task to read data from the UART
+ xTaskCreate(uart_read_task, "uTask", 4096, uart_device, 4, NULL);
+
+ char sendbuf[] = "RMT UART, transmission! RMT UART, transmission! RMT UART, transmission! RMT UART, transmission! RMT UART, transmission! RMT UART, transmission! RMT UART, transmission!";
+ for (int i = 0; i < 16; i++) {
+ /* Write few bytes to the UART */
+ ESP_ERROR_CHECK(uart_emu_transmit(uart_device, (uint8_t *)sendbuf, strlen(sendbuf) + 1));
+ vTaskDelay(pdMS_TO_TICKS(100));
+ }
+
+ int count = 0;
+ while (1) {
+ if (!ulTaskNotifyTake(pdFALSE, pdMS_TO_TICKS(50))) {
+ break;
+ }
+ count++;
+ }
+ ESP_LOGI(TAG, "UART transmit %d times!", count);
+
+}
diff --git a/uart_emu/idf_component.yml b/uart_emu/idf_component.yml
new file mode 100644
index 0000000000..c4593d8c46
--- /dev/null
+++ b/uart_emu/idf_component.yml
@@ -0,0 +1,6 @@
+version: "1.0.0"
+description: Driver for UART emulator
+url: https://github.com/espressif/idf-extra-components/tree/master/uart_emu
+issues: "https://github.com/espressif/idf-extra-components/issues"
+dependencies:
+ idf: ">=5.1"
diff --git a/uart_emu/include/uart_emu.h b/uart_emu/include/uart_emu.h
new file mode 100644
index 0000000000..327b66a2a7
--- /dev/null
+++ b/uart_emu/include/uart_emu.h
@@ -0,0 +1,125 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#pragma once
+
+#include
+#include
+#include "esp_err.h"
+#include "uart_emu_type.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ uint32_t baud_rate; /*!< UART baud rate*/
+ uart_emu_word_length_t data_bits; /*!< UART byte size*/
+ uart_emu_parity_t parity; /*!< UART parity mode*/
+ uart_emu_stop_bits_t stop_bits; /*!< UART stop bits*/
+ gpio_num_t tx_io_num; /*!< UART tx io number*/
+ gpio_num_t rx_io_num; /*!< UART rx io number*/
+ size_t rx_buffer_size; /*!< UART rx buffer size*/
+} uart_emu_config_t;
+
+/**
+ * @brief Transmit data over a UART emulator. This is a non-blocking function.
+ *
+ * @note You can use the `uart_emu_register_tx_event_callbacks()` function to register a callback function to handle the transmission done event.
+ * @param[in] uart_device Handle to the UART EMU controller.
+ * @param[in] data Pointer to the data to be transmitted.
+ * @param[in] size Size of the data to be transmitted.
+ *
+ * @return
+ * - `ESP_OK`: Start transmitting successfully.
+ * - `ESP_ERR_INVALID_ARG`: Invalid arguments (e.g., null `uart_device` handle or `data` pointer).
+ */
+esp_err_t uart_emu_transmit(uart_emu_device_handle_t uart_device, const uint8_t *data, size_t size);
+
+/**
+ * @brief Receive data over a UART emulator. This is a non-blocking function.
+ *
+ * @note You can use the `uart_emu_register_rx_event_callbacks()` function to register a callback function to handle the received data.
+ *
+ * @param[in] uart_device Handle to the UART EMU controller, which was previously created using
+ * `uart_emu_new_from_rmt()`.
+ * @param[in] buf Pointer to the buffer to store the received data.
+ * @param[in] size Size of the buffer to store the received data.
+ *
+ * @return
+ * - `ESP_OK`: Start receiving successfully.
+ * - `ESP_ERR_INVALID_ARG`: Invalid arguments (e.g., null `uart_device` handle or `buf` pointer).
+ */
+esp_err_t uart_emu_receive(uart_emu_device_handle_t uart_device, uint8_t *buf, size_t size);
+
+/**
+ * @brief Delete a UART EMU controller.
+ *
+ * @param[in] uart_device Handle to the UART EMU controller.
+ *
+ * @return
+ * - `ESP_OK`: UART EMU controller was successfully deleted.
+ * - `ESP_ERR_INVALID_ARG`: Invalid arguments (e.g., null `uart_device` handle).
+ */
+esp_err_t uart_emu_delete(uart_emu_device_handle_t uart_device);
+
+/**
+ * @brief Structure for defining callback functions for RMT UART transmission events.
+ */
+typedef struct {
+ uart_emu_tx_done_callback_t on_tx_trans_done; /*!< Callback function for handling the completion of a transmission */
+} uart_emu_event_tx_callbacks_t;
+
+/**
+ * @brief Structure for defining callback functions for RMT UART receive events.
+ */
+typedef struct {
+ uart_emu_rx_done_callback_t on_rx_trans_done; /*!< Callback function for handling the completion of a reception */
+} uart_emu_event_rx_callbacks_t;
+
+/**
+ * @brief Register rx event callback functions for a UART EMU controller.
+ *
+ * @note This function allows the user to register callback functions to handle specific UART EMU reception completion event.
+ * The callbacks provide a mechanism to handle asynchronous events generated by the UART EMU controller.
+ *
+ * @param[in] uart_device Handle to the UART EMU controller, which was previously created by `uart_emu_new_from_rmt()`.
+ * @param[in] cbs Pointer to a `uart_emu_rmt_event_rx_callbacks_t` structure that defines the callback
+ * functions to be registered. This structure includes pointers to the callback
+ * functions for handling UART EMU events.
+ * @param[in] user_data Pointer to user-defined data that will be passed to the callback functions
+ * when they are invoked. This can be used to provide context or state information
+ * specific to the application.
+ *
+ * @return
+ * - `ESP_OK`: Register event callbacks successfully.
+ * - `ESP_ERR_INVALID_ARG`: Invalid arguments (e.g., null `uart_device` handle or `cbs` pointer).
+ */
+esp_err_t uart_emu_register_rx_event_callbacks(uart_emu_device_handle_t uart_device, const uart_emu_event_rx_callbacks_t *cbs, void *user_data);
+
+/**
+ * @brief Register tx event callback functions for a UART EMU controller.
+ *
+ * @note This function allows the user to register callback functions to handle specific UART EMU transmission completion event.
+ * The callbacks provide a mechanism to handle asynchronous events generated by the UART EMU controller.
+ *
+ * @param[in] uart_device Handle to the UART EMU controller, which was previously created by `uart_emu_new_from_rmt()`.
+ * @param[in] cbs Pointer to a `uart_emu_rmt_event_tx_callbacks_t` structure that defines the callback
+ * functions to be registered. This structure includes pointers to the callback
+ * functions for handling UART EMU events.
+ * @param[in] user_data Pointer to user-defined data that will be passed to the callback functions
+ * when they are invoked. This can be used to provide context or state information
+ * specific to the application.
+ *
+ * @return
+ * - `ESP_OK`: Register event callbacks successfully.
+ * - `ESP_ERR_INVALID_ARG`: Invalid arguments (e.g., null `uart_device` handle or `cbs` pointer).
+ */
+esp_err_t uart_emu_register_tx_event_callbacks(uart_emu_device_handle_t uart_device, const uart_emu_event_tx_callbacks_t *cbs, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/uart_emu/include/uart_emu_rmt.h b/uart_emu/include/uart_emu_rmt.h
new file mode 100644
index 0000000000..0012245d76
--- /dev/null
+++ b/uart_emu/include/uart_emu_rmt.h
@@ -0,0 +1,63 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#pragma once
+
+#include
+#include
+#include "esp_err.h"
+#include "freertos/FreeRTOS.h"
+#include "soc/soc_caps.h"
+#include "hal/gpio_types.h"
+#include "uart_emu_type.h"
+#include "uart_emu.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ size_t tx_trans_queue_depth; /*!< RMT tx internal transfer queue depth, increase this value can support more transfers pending in the background */
+ size_t tx_mem_block_symbols; /*!< RMT tx mem block symbols*/
+ size_t rx_mem_block_symbols; /*!< RMT rx mem block symbols*/
+ uint32_t intr_priority; /*!< RMT interrupt priority*/
+ struct {
+ uint32_t with_dma: 1; /*!< If set, the driver will allocate an RMT channel with DMA capability */
+ } flags; /*!< RMT config flags */
+} uart_emu_rmt_config_t;
+
+/**
+ * @brief Create a new UART EMU controller from RMT.
+ *
+ * @param[in] uart_config Configuration for the UART EMU controller.
+ * @param[in] rmt_config Configuration for the RMT UART controller.
+ * @param[out] ret_device Handle to the UART EMU controller.
+ *
+ * @return
+ * - `ESP_OK`: UART EMU controller was successfully created.
+ * - `ESP_ERR_INVALID_ARG`: Invalid arguments (e.g., null `uart_config` pointer or `ret_device` pointer).
+ * - `ESP_ERR_NO_MEM`: No enough memory to create the UART EMU controller.
+ */
+esp_err_t uart_emu_new_from_rmt(const uart_emu_config_t *uart_config, const uart_emu_rmt_config_t *rmt_config, uart_emu_device_handle_t *ret_device);
+
+/**
+ * @brief Decode UART EMU RMT data.
+ *
+ * @note After receiving the UART EMU RMT symbols, you can use this function to decode the data.
+ *
+ * @param[in] uart_device Handle to the UART EMU controller, which was previously created by `uart_emu_new_from_rmt()`.
+ * @param[in] rmt_rx_evt_data Pointer to the UART EMU RMT receive event data.
+ * @param[in] rx_buf Pointer to the buffer to store the decoded data.
+ * @param[in] rx_buf_size Size of the buffer to store the decoded data.
+ * @param[in] continue_on_error Whether to continue decoding on error.
+ * @return
+ * - (0) Error
+ * - OTHERS (>0) The number of bytes decoded from UART EMU RMT received symbols
+ */
+int uart_emu_rmt_decode_data(uart_emu_device_handle_t uart_device, uart_emu_rx_done_event_data_t *rmt_rx_evt_data, uint8_t *rx_buf, size_t rx_buf_size, bool continue_on_error);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/uart_emu/include/uart_emu_type.h b/uart_emu/include/uart_emu_type.h
new file mode 100644
index 0000000000..73b644880c
--- /dev/null
+++ b/uart_emu/include/uart_emu_type.h
@@ -0,0 +1,79 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include "soc/soc_caps.h"
+#include "driver/rmt_types.h"
+#include "sdkconfig.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Type of UART EMU device handle
+ */
+typedef struct uart_emu_device_t *uart_emu_device_handle_t;
+
+typedef enum {
+ UART_EMU_DATA_8_BITS = 0x8, /*!< word length: 8bits*/
+} uart_emu_word_length_t;
+
+typedef enum {
+ UART_EMU_STOP_BITS_1 = 0x0, /*!< stop bit: 1bit*/
+ UART_EMU_STOP_BITS_2 = 0x1, /*!< stop bit: 2bits*/
+} uart_emu_stop_bits_t;
+
+typedef enum {
+ UART_EMU_PARITY_DISABLE = 0x0, /*!< Disable UART parity*/
+} uart_emu_parity_t;
+
+/**
+ * @brief UART EMU TX Done Event Data
+ */
+typedef struct {
+
+} uart_emu_tx_done_event_data_t;
+
+/**
+ * @brief UART EMU TX Done Callback Function Type
+ * @param uart_device Handle to the UART EMU device that initiated the transmission.
+ * @param edata Pointer to a structure containing event data related to the completed transmission.
+ * @param user_ctx User-defined context passed during the callback registration.
+ * It can be used to maintain application-specific state or data.
+ *
+ * @return Whether a high priority task has been waken up by this callback function
+ */
+typedef bool (*uart_emu_tx_done_callback_t)(uart_emu_device_handle_t uart_device, const uart_emu_tx_done_event_data_t *edata, void *user_ctx);
+
+/**
+ * @brief UART EMU RX Done Event Data
+ */
+typedef struct {
+ void *rx_done_event_data;
+} uart_emu_rx_done_event_data_t;
+
+/**
+ * @brief UART EMU RX Done Callback Function Type
+ * @param uart_device Handle to the UART EMU device that initiated the transmission.
+ * @param edata Pointer to a structure containing event data related to the completed transmission.
+ * This structure provides details such as the number of bytes transmitted and any
+ * status information relevant to the operation.
+ * @param user_ctx User-defined context passed during the callback registration.
+ * It can be used to maintain application-specific state or data.
+ *
+ * @return Whether a high priority task has been waken up by this callback function
+ */
+typedef bool (*uart_emu_rx_done_callback_t)(uart_emu_device_handle_t uart_device, const uart_emu_rx_done_event_data_t *edata, void *user_ctx);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/uart_emu/src/uart_emu_rmt.c b/uart_emu/src/uart_emu_rmt.c
new file mode 100644
index 0000000000..3a169c677c
--- /dev/null
+++ b/uart_emu/src/uart_emu_rmt.c
@@ -0,0 +1,414 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#include
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/queue.h"
+#include "freertos/semphr.h"
+#include "sdkconfig.h"
+#include "esp_log.h"
+#include "esp_check.h"
+#include "esp_heap_caps.h"
+#include "driver/rmt_tx.h"
+#include "driver/rmt_rx.h"
+#include "uart_emu_rmt.h"
+#include "uart_emu_rmt_encoder.h"
+#include "esp_memory_utils.h"
+
+static const char *TAG = "uart_emu_rmt";
+
+// in order to prevent data loss and achieve a higher baudrate, we use 8 RMT clock cycles to represent a UART bit
+#define RMT_BIT_RESOLUTION 8
+
+#define ROUND_CLOSEST(dividend, divisor) (((dividend) + ((divisor) / 2)) / (divisor))
+
+typedef struct uart_emu_rmt_tx_context_t uart_emu_rmt_tx_context_t;
+typedef struct uart_emu_rmt_rx_context_t uart_emu_rmt_rx_context_t;
+typedef struct uart_emu_rmt_decode_context_t uart_emu_rmt_decode_context_t;
+typedef struct uart_emu_device_t uart_emu_device_t;
+
+struct uart_emu_rmt_tx_context_t {
+ rmt_channel_handle_t tx_channel; // rmt tx channel handler
+ rmt_encoder_handle_t tx_encoder; // rmt tx encoder handle
+ rmt_transmit_config_t tx_config; // rmt tx config
+ uart_emu_tx_done_callback_t on_tx_trans_done; // callback function for tx done event
+ void *user_ctx; // user context for tx done callback
+};
+
+struct uart_emu_rmt_rx_context_t {
+ rmt_channel_handle_t rx_channel; // rmt rx channel handler
+ rmt_symbol_word_t *rx_symbols_buf; // hold rmt raw symbols
+ size_t max_bytes_len; // buffer size in byte for single transaction
+ uart_emu_rx_done_callback_t on_rx_trans_done; // callback function for rx done event
+ void *user_ctx; // user context for rx done callback
+ uint32_t read_symbol_index; // the index of the read buffer
+};
+
+struct uart_emu_rmt_decode_context_t {
+ size_t bit_pos; // the current bit position
+ uint16_t raw_data; // the raw data being assembled
+ size_t byte_pos; // the decoded byte position
+ bool continue_on_error; // whether to continue decoding on error
+};
+
+struct uart_emu_device_t {
+ uart_emu_rmt_tx_context_t rmt_uart_context_tx; // rmt tx context
+ uart_emu_rmt_rx_context_t rmt_uart_context_rx; // rmt rx context
+ uart_emu_word_length_t data_bits; // UART byte size
+ uart_emu_parity_t parity; // UART parity mode
+ uart_emu_stop_bits_t stop_bits; // UART stop bits
+ size_t frame_len; // frame length
+ uint32_t baud_rate; // baud rate
+};
+
+static bool uart_emu_rmt_process_level(uint8_t level, uint32_t duration, int bit_ticks,
+ const uart_emu_device_t *uart_device,
+ uart_emu_rmt_decode_context_t *decode_context,
+ uint8_t *rx_buf, size_t rx_buf_size)
+{
+ int bit_count = ROUND_CLOSEST(duration, bit_ticks);
+ uint8_t data_bits = uart_device->data_bits;
+ uint8_t stop_bits = (uart_device->stop_bits == UART_EMU_STOP_BITS_1) ? 1 : 2;
+ uint8_t total_bits = 1 + data_bits + stop_bits;
+
+ for (int i = 0; i < bit_count; i++) {
+ // if the current bit is not a start bit, stop the decoding
+ if (decode_context->bit_pos == 0 && level != 0) {
+ if (decode_context->continue_on_error) {
+ continue;
+ } else {
+ ESP_LOGE(TAG, "Invalid start bit @ byte %d", decode_context->byte_pos);
+ return false;
+ }
+ }
+
+ decode_context->raw_data |= (level << decode_context->bit_pos);
+ decode_context->bit_pos++;
+
+ if (decode_context->bit_pos == total_bits) {
+ // Total bits layout:
+ // [0] Start bit (always 0)
+ // [1 ~ N] N bits data
+ // [N + 1] Parity bit (optional)
+ // [N + 1 + (1 or 2)] Stop bit (always 1)
+
+ // extract the data byte
+ uint8_t data_byte = (decode_context->raw_data >> 1) & ((1 << data_bits) - 1);
+
+ // if the stop bit is wrong, stop the decoding
+ if ((decode_context->raw_data >> (total_bits - 1)) != 1) {
+ if (decode_context->continue_on_error == false) {
+ ESP_LOGE(TAG, "Invalid stop bit @ byte %d", decode_context->byte_pos);
+ }
+ decode_context->bit_pos = 0;
+ decode_context->raw_data = 0;
+ return decode_context->continue_on_error;
+ }
+
+ // if the byte position is less than the buffer size, store the data byte
+ if (decode_context->byte_pos < rx_buf_size) {
+ rx_buf[decode_context->byte_pos++] = data_byte;
+ ESP_LOGD(TAG, "Decoded byte[%d] = 0x%02X", decode_context->byte_pos - 1, data_byte);
+ }
+
+ decode_context->bit_pos = 0;
+ decode_context->raw_data = 0;
+
+ // if the byte position is greater than the buffer size, truncate the data, stop the decoding
+ if (decode_context->byte_pos >= rx_buf_size) {
+ return false;
+ }
+ }
+ }
+
+ return true; // continue decoding
+}
+
+int uart_emu_rmt_decode_data(uart_emu_device_handle_t uart_device, uart_emu_rx_done_event_data_t *evt_data,
+ uint8_t *rx_buf, size_t rx_buf_size, bool continue_on_error)
+{
+ if (!uart_device || !evt_data || !rx_buf || rx_buf_size == 0) {
+ ESP_LOGE(TAG, "Invalid arguments");
+ return 0;
+ }
+
+ if (rx_buf_size > uart_device->rmt_uart_context_rx.max_bytes_len) {
+ ESP_LOGE(TAG, "rx_buf_size %d should not be greater than %d, which is configured in uart_emu_new_from_rmt", rx_buf_size, uart_device->rmt_uart_context_rx.max_bytes_len);
+ return 0;
+ }
+ rmt_rx_done_event_data_t *rmt_rx_evt_data = (rmt_rx_done_event_data_t *)evt_data->rx_done_event_data;
+ uart_emu_rmt_decode_context_t decode_context = {
+ .bit_pos = 0,
+ .raw_data = 0,
+ .byte_pos = 0,
+ .continue_on_error = continue_on_error,
+ };
+
+ rmt_symbol_word_t *symbols = rmt_rx_evt_data->received_symbols;
+ size_t num_symbols = rmt_rx_evt_data->num_symbols;
+
+ for (size_t i = 0; i < num_symbols; i++) {
+ rmt_symbol_word_t *sym = &symbols[i];
+
+ ESP_LOGV(TAG, "Symbol[%02d]: duration0: %d level0: %d duration1: %d level1: %d",
+ i, sym->duration0, sym->level0, sym->duration1, sym->level1);
+
+ // if the symbol is the last one, the duration of the stop bit will be 0 because the rmt_rx_done_event_data is triggered
+ // so we need to set the duration of the stop bit manually
+ if (i == num_symbols - 1) {
+ if (sym->level0 == 1) {
+ sym->duration0 = (uart_device->stop_bits + 1) * RMT_BIT_RESOLUTION;
+ } else if (sym->level1 == 1) {
+ sym->duration1 = (uart_device->stop_bits + 1) * RMT_BIT_RESOLUTION;
+ }
+ }
+
+ if (!uart_emu_rmt_process_level(sym->level0, sym->duration0, RMT_BIT_RESOLUTION, uart_device, &decode_context, rx_buf, rx_buf_size)) {
+ break;
+ }
+ if (!uart_emu_rmt_process_level(sym->level1, sym->duration1, RMT_BIT_RESOLUTION, uart_device, &decode_context, rx_buf, rx_buf_size)) {
+ break;
+ }
+ }
+
+ return decode_context.byte_pos;
+}
+
+IRAM_ATTR bool uart_emu_rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *edata, void *user_data)
+{
+ BaseType_t high_task_woken = pdFALSE;
+ uart_emu_device_t *uart_device = (uart_emu_device_t *)user_data;
+ uart_emu_rmt_rx_context_t *rx_context = &uart_device->rmt_uart_context_rx;
+ uint32_t *read_symbol_index = &rx_context->read_symbol_index;
+
+ // avoid memory trampling
+ if (*read_symbol_index + edata->num_symbols > rx_context->max_bytes_len * uart_device->frame_len) {
+ ESP_EARLY_LOGW(TAG, "Received symbols number is over the buffer size, truncate the data");
+ *read_symbol_index = 0;
+ }
+
+ // do memory copy, the pingpong buffer should not be very large, so the memory copy should be fast
+ if (edata->flags.is_last) {
+ memcpy(rx_context->rx_symbols_buf + *read_symbol_index, edata->received_symbols, edata->num_symbols * sizeof(rmt_symbol_word_t));
+ *read_symbol_index += edata->num_symbols;
+ rmt_rx_done_event_data_t last_edata = {
+ .received_symbols = rx_context->rx_symbols_buf,
+ .num_symbols = *read_symbol_index,
+ .flags.is_last = true,
+ };
+ uart_emu_rx_done_event_data_t evt_data = {
+ .rx_done_event_data = (void *) &last_edata,
+ };
+ if (rx_context->on_rx_trans_done(uart_device, &evt_data, rx_context->user_ctx)) {
+ high_task_woken |= pdTRUE;
+ }
+ *read_symbol_index = 0;
+ } else {
+ memcpy(rx_context->rx_symbols_buf + *read_symbol_index, edata->received_symbols, edata->num_symbols * sizeof(rmt_symbol_word_t));
+ *read_symbol_index += edata->num_symbols;
+ }
+
+ return high_task_woken;
+}
+
+IRAM_ATTR bool uart_emu_rmt_tx_done_callback(rmt_channel_handle_t channel, const rmt_tx_done_event_data_t *edata, void *user_data)
+{
+ BaseType_t high_task_woken = pdFALSE;
+ uart_emu_device_t *uart_device = (uart_emu_device_t *)user_data;
+ uart_emu_rmt_tx_context_t *tx_context = &uart_device->rmt_uart_context_tx;
+
+ if (tx_context->on_tx_trans_done(uart_device, NULL, tx_context->user_ctx)) {
+ high_task_woken |= pdTRUE;
+ }
+ return high_task_woken;
+}
+
+esp_err_t uart_emu_new_from_rmt(const uart_emu_config_t *uart_config, const uart_emu_rmt_config_t *rmt_config, uart_emu_device_handle_t *ret_device)
+{
+ esp_err_t ret = ESP_OK;
+ ESP_RETURN_ON_FALSE(uart_config && rmt_config, ESP_ERR_INVALID_ARG, TAG, "Invalid argument");
+
+ // malloc channel memory
+ uart_emu_device_t *uart_device = heap_caps_calloc(1, sizeof(uart_emu_device_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
+ ESP_RETURN_ON_FALSE(uart_device, ESP_ERR_NO_MEM, TAG, "no mem for uart_emu_device");
+ ESP_RETURN_ON_FALSE(uart_config->data_bits == UART_EMU_DATA_8_BITS, ESP_ERR_INVALID_ARG, TAG, "Invalid data bits");
+
+ uart_device->baud_rate = uart_config->baud_rate;
+ uart_device->data_bits = uart_config->data_bits;
+ uart_device->stop_bits = uart_config->stop_bits;
+ uart_device->parity = uart_config->parity;
+ const int resolution = uart_config->baud_rate * RMT_BIT_RESOLUTION;
+
+ // 1 RMT symbol represents 1 bit. 1 bit start and 1 bit stop, n bits data, 1 bit parity (optional), total n + 2 (+ 1) bits, equivalent to n + 2 (+ 1) symbols
+ uart_device->frame_len = uart_config->parity ? uart_config->data_bits + 3 : uart_config->data_bits + 2;
+
+ if (uart_config->rx_io_num != GPIO_NUM_NC) {
+ uart_emu_rmt_rx_context_t *rx_context = &uart_device->rmt_uart_context_rx;
+ rmt_rx_channel_config_t uart_rx_channel_cfg = {
+ .clk_src = RMT_CLK_SRC_DEFAULT,
+ .resolution_hz = resolution,
+ .gpio_num = uart_config->rx_io_num,
+ .mem_block_symbols = rmt_config->rx_mem_block_symbols,
+ .intr_priority = rmt_config->intr_priority,
+ .flags.invert_in = false,
+ .flags.with_dma = rmt_config->flags.with_dma,
+ };
+ ESP_GOTO_ON_ERROR(rmt_new_rx_channel(&uart_rx_channel_cfg, &rx_context->rx_channel), err, TAG, "new rx channel failed");
+
+ rx_context->max_bytes_len = uart_config->rx_buffer_size;
+
+ // allocate rmt rx symbol buffer
+ rx_context->rx_symbols_buf = heap_caps_calloc(1, rx_context->max_bytes_len * sizeof(rmt_symbol_word_t) * uart_device->frame_len, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
+ ESP_GOTO_ON_FALSE(rx_context->rx_symbols_buf, ESP_ERR_NO_MEM, err, TAG, "no mem to store received RMT symbols");
+
+ // register rmt rx done callback
+ rmt_rx_event_callbacks_t rx_cbs = {
+ .on_recv_done = uart_emu_rmt_rx_done_callback
+ };
+ rmt_rx_register_event_callbacks(rx_context->rx_channel, &rx_cbs, uart_device);
+
+ // enable rmt channels
+ rmt_enable(rx_context->rx_channel);
+ }
+
+ if (uart_config->tx_io_num != GPIO_NUM_NC) {
+ uart_emu_rmt_tx_context_t *tx_context = &uart_device->rmt_uart_context_tx;
+ rmt_tx_channel_config_t uart_tx_channel_cfg = {
+ .clk_src = RMT_CLK_SRC_DEFAULT,
+ .gpio_num = uart_config->tx_io_num,
+ .mem_block_symbols = rmt_config->tx_mem_block_symbols,
+ .resolution_hz = resolution,
+ .trans_queue_depth = rmt_config->tx_trans_queue_depth,
+ .intr_priority = rmt_config->intr_priority,
+ .flags.invert_out = false,
+ .flags.with_dma = rmt_config->flags.with_dma,
+ };
+ ESP_GOTO_ON_ERROR(rmt_new_tx_channel(&uart_tx_channel_cfg, &tx_context->tx_channel), err, TAG, "new tx channel failed");
+
+ // IDLE should be high level
+ tx_context->tx_config.flags.eot_level = 1;
+
+ ESP_RETURN_ON_ERROR(uart_emu_rmt_new_encoder(uart_config, &tx_context->tx_encoder), TAG, "new encoder failed");
+
+ // register rmt tx done callback
+ rmt_tx_event_callbacks_t tx_cbs = {
+ .on_trans_done = uart_emu_rmt_tx_done_callback
+ };
+ rmt_tx_register_event_callbacks(tx_context->tx_channel, &tx_cbs, uart_device);
+
+ // enable rmt channels
+ rmt_enable(tx_context->tx_channel);
+ }
+ *ret_device = uart_device;
+ ESP_LOGI(TAG, "new uart emu at %p, baud=%d rmt_resolution=%d", uart_device, uart_config->baud_rate, resolution);
+ return ESP_OK;
+
+err:
+ if (uart_device->rmt_uart_context_rx.rx_symbols_buf) {
+ free(uart_device->rmt_uart_context_rx.rx_symbols_buf);
+ }
+ if (uart_device) {
+ free(uart_device);
+ }
+ return ret;
+}
+
+esp_err_t uart_emu_transmit(uart_emu_device_handle_t uart_device, const uint8_t *data, size_t size)
+{
+ uart_emu_rmt_tx_context_t *tx_context = &uart_device->rmt_uart_context_tx;
+ ESP_RETURN_ON_FALSE(uart_device, ESP_ERR_INVALID_ARG, TAG, "Invalid argument");
+
+ // transmit data with the encoder
+ ESP_RETURN_ON_ERROR(rmt_transmit(tx_context->tx_channel, tx_context->tx_encoder, data, size, &tx_context->tx_config), TAG, "uart emu transmit failed");
+
+ return ESP_OK;
+}
+
+esp_err_t uart_emu_receive(uart_emu_device_handle_t uart_device, uint8_t *buf, size_t rx_buf_size)
+{
+ uart_emu_rmt_rx_context_t *rx_context = &uart_device->rmt_uart_context_rx;
+ ESP_RETURN_ON_FALSE(uart_device, ESP_ERR_INVALID_ARG, TAG, "Invalid argument");
+
+ // calculate the bit time in nanoseconds
+ uint32_t bit_time_ns = 1000000000 / uart_device->baud_rate;
+ rmt_receive_config_t receive_config = {
+ .signal_range_min_ns = bit_time_ns / 100,
+ .signal_range_max_ns = bit_time_ns * 10,
+ .flags.en_partial_rx = 1, // the uart data may be large, so we need to enable partial receive to do the pingpong
+ };
+
+ rmt_receive(rx_context->rx_channel, buf, rx_buf_size, &receive_config);
+ return ESP_OK;
+}
+
+esp_err_t uart_emu_delete(uart_emu_device_handle_t uart_device)
+{
+ ESP_RETURN_ON_FALSE(uart_device, ESP_ERR_INVALID_ARG, TAG, "Invalid argument");
+
+ // delete RMT TX
+ uart_emu_rmt_tx_context_t *tx_context = &uart_device->rmt_uart_context_tx;
+
+ if (tx_context->tx_channel) {
+ rmt_disable(tx_context->tx_channel);
+ rmt_del_channel(tx_context->tx_channel);
+ }
+
+ if (tx_context->tx_encoder) {
+ rmt_del_encoder(tx_context->tx_encoder);
+ }
+
+ // delete RMT RX
+ uart_emu_rmt_rx_context_t *rx_context = &uart_device->rmt_uart_context_rx;
+
+ if (rx_context->rx_channel) {
+ rmt_disable(rx_context->rx_channel);
+ rmt_del_channel(rx_context->rx_channel);
+ }
+
+ // delete uart device
+ if (rx_context->rx_symbols_buf) {
+ free(rx_context->rx_symbols_buf);
+ }
+
+ free(uart_device);
+
+ return ESP_OK;
+}
+
+esp_err_t uart_emu_register_tx_event_callbacks(uart_emu_device_handle_t uart_device, const uart_emu_event_tx_callbacks_t *cbs, void *user_data)
+{
+ ESP_RETURN_ON_FALSE(uart_device && cbs, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
+
+#if CONFIG_RMT_TX_ISR_CACHE_SAFE
+ if (cbs->on_tx_trans_done) {
+ ESP_RETURN_ON_FALSE(esp_ptr_in_iram(cbs->on_tx_trans_done), ESP_ERR_INVALID_ARG, TAG, "on_tx_trans_done callback not in IRAM");
+ }
+ if (user_data) {
+ ESP_RETURN_ON_FALSE(esp_ptr_internal(user_data), ESP_ERR_INVALID_ARG, TAG, "user context not in internal RAM");
+ }
+#endif
+
+ uart_device->rmt_uart_context_tx.on_tx_trans_done = cbs->on_tx_trans_done;
+ uart_device->rmt_uart_context_tx.user_ctx = user_data;
+ return ESP_OK;
+}
+
+esp_err_t uart_emu_register_rx_event_callbacks(uart_emu_device_handle_t uart_device, const uart_emu_event_rx_callbacks_t *cbs, void *user_data)
+{
+ ESP_RETURN_ON_FALSE(uart_device && cbs, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
+
+#if CONFIG_RMT_RX_ISR_CACHE_SAFE
+ if (cbs->on_rx_trans_done) {
+ ESP_RETURN_ON_FALSE(esp_ptr_in_iram(cbs->on_rx_trans_done), ESP_ERR_INVALID_ARG, TAG, "on_rx_trans_done callback not in IRAM");
+ }
+ if (user_data) {
+ ESP_RETURN_ON_FALSE(esp_ptr_internal(user_data), ESP_ERR_INVALID_ARG, TAG, "user context not in internal RAM");
+ }
+#endif
+ uart_device->rmt_uart_context_rx.on_rx_trans_done = cbs->on_rx_trans_done;
+ uart_device->rmt_uart_context_rx.user_ctx = user_data;
+ return ESP_OK;
+}
\ No newline at end of file
diff --git a/uart_emu/src/uart_emu_rmt_encoder.c b/uart_emu/src/uart_emu_rmt_encoder.c
new file mode 100644
index 0000000000..a348d2e48f
--- /dev/null
+++ b/uart_emu/src/uart_emu_rmt_encoder.c
@@ -0,0 +1,166 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "esp_check.h"
+#include "uart_emu_rmt_encoder.h"
+
+static const char *TAG = "uart_encoder";
+
+#define RMT_BIT_RESOLUTION 8
+
+typedef struct {
+ rmt_encoder_t base; // the base "class", declares the standard encoder interface
+ rmt_encoder_t *copy_encoder; // use the copy_encoder to encode the start and stop bit
+ rmt_encoder_t *bytes_encoder; // use the bytes_encoder to encode the data bits
+ rmt_symbol_word_t uart_start_symbol; // uart start bit with RMT representation
+ rmt_symbol_word_t uart_stop_symbol; // uart stop bit with RMT representation
+ int state;
+ int byte_index; // index of the encoding byte in the primary stream
+} uart_emu_rmt_encoder_t;
+
+static size_t rmt_encode_uart(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state)
+{
+ uart_emu_rmt_encoder_t *uart_encoder = __containerof(encoder, uart_emu_rmt_encoder_t, base);
+ rmt_encode_state_t session_state = RMT_ENCODING_RESET;
+ rmt_encode_state_t state = RMT_ENCODING_RESET;
+ size_t encoded_symbols = 0;
+ uint8_t *data = (uint8_t *)primary_data;
+ int *byte_index = &uart_encoder->byte_index;
+ rmt_encoder_handle_t copy_encoder = uart_encoder->copy_encoder;
+ rmt_encoder_handle_t bytes_encoder = uart_encoder->bytes_encoder;
+
+ while (*byte_index < data_size) {
+ switch (uart_encoder->state) {
+ case 0: // send start bit
+ encoded_symbols += copy_encoder->encode(copy_encoder, channel, &uart_encoder->uart_start_symbol,
+ sizeof(rmt_symbol_word_t), &session_state);
+ if (session_state & RMT_ENCODING_COMPLETE) {
+ uart_encoder->state = 1; // we can only switch to next state when current encoder finished
+ }
+ if (session_state & RMT_ENCODING_MEM_FULL) {
+ state |= RMT_ENCODING_MEM_FULL;
+ goto out; // yield if there's no free space to put other encoding artifacts
+ }
+ // fall-through
+ case 1: // send data bits
+ encoded_symbols += bytes_encoder->encode(bytes_encoder, channel, data + *byte_index, sizeof(uint8_t), &session_state);
+ if (session_state & RMT_ENCODING_COMPLETE) {
+ uart_encoder->state = 2; // we can only switch to next state when current encoder finished
+ (*byte_index)++;
+ }
+ if (session_state & RMT_ENCODING_MEM_FULL) {
+ state |= RMT_ENCODING_MEM_FULL;
+ goto out; // yield if there's no free space to put other encoding artifacts
+ }
+ // fall-through
+ case 2: // send ending code
+ encoded_symbols += copy_encoder->encode(copy_encoder, channel, &uart_encoder->uart_stop_symbol,
+ sizeof(rmt_symbol_word_t), &session_state);
+ if (session_state & RMT_ENCODING_COMPLETE) {
+ uart_encoder->state = RMT_ENCODING_RESET; // back to the initial encoding session
+
+ }
+ if (session_state & RMT_ENCODING_MEM_FULL) {
+ state |= RMT_ENCODING_MEM_FULL;
+ goto out; // yield if there's no free space to put other encoding artifacts
+ }
+ }
+ }
+
+ // all bytes are encoded, set the state to complete
+ *byte_index = 0;
+ state |= RMT_ENCODING_COMPLETE;
+
+out:
+ *ret_state = state;
+ return encoded_symbols;
+}
+
+static esp_err_t rmt_del_uart_encoder(rmt_encoder_t *encoder)
+{
+ uart_emu_rmt_encoder_t *uart_encoder = __containerof(encoder, uart_emu_rmt_encoder_t, base);
+ rmt_del_encoder(uart_encoder->copy_encoder);
+ rmt_del_encoder(uart_encoder->bytes_encoder);
+ free(uart_encoder);
+ return ESP_OK;
+}
+
+static esp_err_t rmt_uart_encoder_reset(rmt_encoder_t *encoder)
+{
+ uart_emu_rmt_encoder_t *uart_encoder = __containerof(encoder, uart_emu_rmt_encoder_t, base);
+ rmt_encoder_reset(uart_encoder->copy_encoder);
+ rmt_encoder_reset(uart_encoder->bytes_encoder);
+ uart_encoder->state = RMT_ENCODING_RESET;
+ return ESP_OK;
+}
+
+esp_err_t uart_emu_rmt_new_encoder(const uart_emu_config_t *config, rmt_encoder_handle_t *ret_encoder)
+{
+ esp_err_t ret = ESP_OK;
+ uart_emu_rmt_encoder_t *uart_encoder = NULL;
+ ESP_GOTO_ON_FALSE(config && ret_encoder, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
+ uart_encoder = rmt_alloc_encoder_mem(sizeof(uart_emu_rmt_encoder_t));
+ ESP_GOTO_ON_FALSE(uart_encoder, ESP_ERR_NO_MEM, err, TAG, "no mem for uart encoder");
+ uart_encoder->base.encode = rmt_encode_uart;
+ uart_encoder->base.del = rmt_del_uart_encoder;
+ uart_encoder->base.reset = rmt_uart_encoder_reset;
+
+ rmt_copy_encoder_config_t copy_encoder_config = {};
+ ESP_GOTO_ON_ERROR(rmt_new_copy_encoder(©_encoder_config, &uart_encoder->copy_encoder), err, TAG, "create copy encoder failed");
+
+ // construct the leading code and ending code with RMT symbol format
+ uart_encoder->uart_start_symbol = (rmt_symbol_word_t) {
+ .level0 = 0,
+ .duration0 = RMT_BIT_RESOLUTION / 2,
+ .level1 = 0,
+ .duration1 = RMT_BIT_RESOLUTION / 2,
+ };
+ rmt_symbol_word_t stop_bit_symbol = {
+ .level0 = 1,
+ .level1 = 1,
+ };
+ switch (config->stop_bits) {
+ case UART_EMU_STOP_BITS_1:
+ stop_bit_symbol.duration0 = RMT_BIT_RESOLUTION / 2;
+ stop_bit_symbol.duration1 = RMT_BIT_RESOLUTION / 2;
+ break;
+ case UART_EMU_STOP_BITS_2:
+ stop_bit_symbol.duration0 = RMT_BIT_RESOLUTION;
+ stop_bit_symbol.duration1 = RMT_BIT_RESOLUTION;
+ break;
+ }
+ uart_encoder->uart_stop_symbol = stop_bit_symbol;
+
+ rmt_bytes_encoder_config_t bytes_encoder_config = {
+ .bit0 = {
+ .level0 = 0,
+ .duration0 = RMT_BIT_RESOLUTION / 2,
+ .level1 = 0,
+ .duration1 = RMT_BIT_RESOLUTION / 2,
+ },
+ .bit1 = {
+ .level0 = 1,
+ .duration0 = RMT_BIT_RESOLUTION / 2,
+ .level1 = 1,
+ .duration1 = RMT_BIT_RESOLUTION / 2,
+ },
+ };
+ ESP_GOTO_ON_ERROR(rmt_new_bytes_encoder(&bytes_encoder_config, &uart_encoder->bytes_encoder), err, TAG, "create bytes encoder failed");
+
+ *ret_encoder = &uart_encoder->base;
+ return ESP_OK;
+err:
+ if (uart_encoder) {
+ if (uart_encoder->bytes_encoder) {
+ rmt_del_encoder(uart_encoder->bytes_encoder);
+ }
+ if (uart_encoder->copy_encoder) {
+ rmt_del_encoder(uart_encoder->copy_encoder);
+ }
+ free(uart_encoder);
+ }
+ return ret;
+}
\ No newline at end of file
diff --git a/uart_emu/src/uart_emu_rmt_encoder.h b/uart_emu/src/uart_emu_rmt_encoder.h
new file mode 100644
index 0000000000..95bc6efc60
--- /dev/null
+++ b/uart_emu/src/uart_emu_rmt_encoder.h
@@ -0,0 +1,30 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#pragma once
+
+#include
+#include "driver/rmt_encoder.h"
+#include "uart_emu_rmt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Create RMT encoder for encoding uart frame into RMT symbols
+ *
+ * @param[in] uart_config Encoder configuration
+ * @param[out] ret_encoder Returned encoder handle
+ * @return
+ * - `ESP_OK`: Create uart encoder successfully
+ * - `ESP_ERR_INVALID_ARG`: Invalid arguments
+ * - `ESP_ERR_NO_MEM`: No enough memory to create uart encoder
+ */
+esp_err_t uart_emu_rmt_new_encoder(const uart_emu_config_t *uart_config, rmt_encoder_handle_t *ret_encoder);
+
+#ifdef __cplusplus
+}
+#endif
\ No newline at end of file