From cf0dc7a202b1d1e7964573169377cd5b3c8c03a7 Mon Sep 17 00:00:00 2001 From: morris Date: Mon, 23 Dec 2024 15:08:50 +0800 Subject: [PATCH] feat(rmt): add API to return the real clock resolution of a channel Closes https://github.com/espressif/esp-idf/pull/15074 --- components/driver/include/esp_private/rmt.h | 14 +++++++++++++- components/driver/rmt/rmt_common.c | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/driver/include/esp_private/rmt.h b/components/driver/include/esp_private/rmt.h index fa88b06f2a..1c86c2a487 100644 --- a/components/driver/include/esp_private/rmt.h +++ b/components/driver/include/esp_private/rmt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -28,6 +28,18 @@ extern "C" { */ esp_err_t rmt_get_channel_id(rmt_channel_handle_t channel, int *ret_id); +/** + * @brief Get the RMT channel's real clock resolution + * + * @param[in] channel RMT generic channel that created by `rmt_new_tx_channel()` or `rmt_new_rx_channel()` + * @param[out] ret_resolution_hz The real clock resolution in Hz + * @return + * - ESP_OK: Get RMT channel resolution successfully + * - ESP_ERR_INVALID_ARG: Get RMT channel resolution failed because of invalid argument + * - ESP_FAIL: Get RMT channel resolution failed because of other reasons + */ +esp_err_t rmt_get_channel_resolution(rmt_channel_handle_t channel, uint32_t *ret_resolution_hz); + #ifdef __cplusplus } #endif diff --git a/components/driver/rmt/rmt_common.c b/components/driver/rmt/rmt_common.c index bbc4592e98..8057884d9b 100644 --- a/components/driver/rmt/rmt_common.c +++ b/components/driver/rmt/rmt_common.c @@ -194,6 +194,13 @@ esp_err_t rmt_get_channel_id(rmt_channel_handle_t channel, int *ret_id) return ESP_OK; } +esp_err_t rmt_get_channel_resolution(rmt_channel_handle_t channel, uint32_t *ret_resolution_hz) +{ + ESP_RETURN_ON_FALSE(channel && ret_resolution_hz, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); + *ret_resolution_hz = channel->resolution_hz; + return ESP_OK; +} + esp_err_t rmt_apply_carrier(rmt_channel_handle_t channel, const rmt_carrier_config_t *config) { // specially, we allow config to be NULL, means to disable the carrier submodule