feat(rmt): support update bytes encoder configurations at runtime

Closes https://github.com/espressif/esp-idf/issues/12775
This commit is contained in:
morris 2023-12-18 15:50:47 +08:00
parent 42a8eddaaf
commit 5eed8e0fda
2 changed files with 27 additions and 2 deletions

View File

@ -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
*

View File

@ -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
*/
@ -275,6 +275,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;