From 1daeac210b419cd283fb296cb3011103293b3d70 Mon Sep 17 00:00:00 2001 From: morris Date: Mon, 18 Dec 2023 15:50:47 +0800 Subject: [PATCH] feat(rmt): support update bytes encoder configurations at runtime Closes https://github.com/espressif/esp-idf/issues/12775 --- .../driver/rmt/include/driver/rmt_encoder.h | 17 ++++++++++++++++- components/driver/rmt/rmt_encoder.c | 12 +++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/components/driver/rmt/include/driver/rmt_encoder.h b/components/driver/rmt/include/driver/rmt_encoder.h index 91ee775068..57270abeff 100644 --- a/components/driver/rmt/include/driver/rmt_encoder.h +++ b/components/driver/rmt/include/driver/rmt_encoder.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -98,6 +98,21 @@ typedef struct { */ esp_err_t rmt_new_bytes_encoder(const rmt_bytes_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder); +/** + * @brief Update the configuration of the bytes encoder + * + * @note The configurations of the bytes encoder is also set up by `rmt_new_bytes_encoder()`. + * This function is used to update the configuration of the bytes encoder at runtime. + * + * @param[in] bytes_encoder Bytes encoder handle, created by e.g `rmt_new_bytes_encoder()` + * @param[in] config Bytes encoder configuration + * @return + * - ESP_OK: Update RMT bytes encoder successfully + * - ESP_ERR_INVALID_ARG: Update RMT bytes encoder failed because of invalid argument + * - ESP_FAIL: Update RMT bytes encoder failed because of other error + */ +esp_err_t rmt_bytes_encoder_update_config(rmt_encoder_handle_t bytes_encoder, const rmt_bytes_encoder_config_t *config); + /** * @brief Create RMT copy encoder, which copies the given RMT symbols into RMT memory * diff --git a/components/driver/rmt/rmt_encoder.c b/components/driver/rmt/rmt_encoder.c index f6c5939b74..c555a1debf 100644 --- a/components/driver/rmt/rmt_encoder.c +++ b/components/driver/rmt/rmt_encoder.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -273,6 +273,16 @@ err: return ret; } +esp_err_t rmt_bytes_encoder_update_config(rmt_encoder_handle_t bytes_encoder, const rmt_bytes_encoder_config_t *config) +{ + ESP_RETURN_ON_FALSE(bytes_encoder && config, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); + rmt_bytes_encoder_t *encoder = __containerof(bytes_encoder, rmt_bytes_encoder_t, base); + encoder->bit0 = config->bit0; + encoder->bit1 = config->bit1; + encoder->flags.msb_first = config->flags.msb_first; + return ESP_OK; +} + esp_err_t rmt_new_copy_encoder(const rmt_copy_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder) { esp_err_t ret = ESP_OK;