From 2cd4640666ad65062a660fa98112d78fdbc8ef11 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Thu, 12 Jun 2025 10:49:05 +0800 Subject: [PATCH] fix(touch): fixed incorrect interval clock source --- .../esp_driver_touch_sens/common/touch_sens_private.h | 1 + .../hw_ver3/touch_version_specific.c | 11 +++++++++-- .../touch_sens/main/test_touch_sens_common.c | 4 ++-- tools/ci/check_copyright_ignore.txt | 3 --- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/components/esp_driver_touch_sens/common/touch_sens_private.h b/components/esp_driver_touch_sens/common/touch_sens_private.h index 325acb775e..48b671bb3a 100644 --- a/components/esp_driver_touch_sens/common/touch_sens_private.h +++ b/components/esp_driver_touch_sens/common/touch_sens_private.h @@ -67,6 +67,7 @@ struct touch_sensor_s { touch_channel_handle_t ch[SOC_TOUCH_SENSOR_NUM]; /*!< Touch sensor channel handles, will be NULL if the channel is not registered */ uint32_t chan_mask; /*!< Enabled channel mask, corresponding bit will be set if the channel is registered */ uint32_t src_freq_hz; /*!< Source clock frequency */ + uint32_t interval_freq_hz; /*!< Frequency of the interval clock */ intr_handle_t intr_handle; /*!< Interrupt handle */ touch_event_callbacks_t cbs; /*!< Event callbacks */ touch_channel_handle_t deep_slp_chan; /*!< The configured channel for depp sleep, will be NULL if not enable the deep sleep */ diff --git a/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c b/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c index f9d44a75f4..7acd374482 100644 --- a/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c +++ b/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -147,11 +147,18 @@ static esp_err_t s_touch_convert_to_hal_config(touch_sensor_handle_t sens_handle TAG, "get clock frequency failed"); ESP_LOGD(TAG, "touch rtc clock source: RTC_FAST, frequency: %"PRIu32" Hz", sens_handle->src_freq_hz); } + if (!sens_handle->interval_freq_hz) { + ESP_RETURN_ON_ERROR(esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_RTC_SLOW, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &sens_handle->interval_freq_hz), + TAG, "get interval clock frequency failed"); + } uint32_t src_freq_hz = sens_handle->src_freq_hz; uint32_t src_freq_mhz = src_freq_hz / 1000000; + uint32_t interval_freq_mhz = sens_handle->interval_freq_hz / 1000000; hal_cfg->power_on_wait_ticks = (uint32_t)sens_cfg->power_on_wait_us * src_freq_mhz; - hal_cfg->meas_interval_ticks = (uint32_t)(sens_cfg->meas_interval_us * src_freq_mhz); + hal_cfg->power_on_wait_ticks = hal_cfg->power_on_wait_ticks > TOUCH_LL_PAD_MEASURE_WAIT_MAX ? + TOUCH_LL_PAD_MEASURE_WAIT_MAX : hal_cfg->power_on_wait_ticks; + hal_cfg->meas_interval_ticks = (uint32_t)(sens_cfg->meas_interval_us * interval_freq_mhz); hal_cfg->timeout_ticks = (uint32_t)sens_cfg->max_meas_time_us * src_freq_mhz; ESP_RETURN_ON_FALSE(hal_cfg->timeout_ticks <= TOUCH_LL_TIMEOUT_MAX, ESP_ERR_INVALID_ARG, TAG, "max_meas_time_ms should within %"PRIu32, TOUCH_LL_TIMEOUT_MAX / src_freq_mhz); diff --git a/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c b/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c index b93c277b0e..c5c0adc3ce 100644 --- a/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c +++ b/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c @@ -52,8 +52,8 @@ TEST_CASE("touch_sens_install_uninstall_test", "[touch]") TEST_ESP_OK(touch_sensor_new_channel(touch, i + TOUCH_MIN_CHAN_ID, &s_chan_cfg, &touch_chan[i])); } touch_channel_handle_t fault_chan = NULL; - TEST_ASSERT(touch_sensor_new_channel(touch, TOUCH_TOTAL_CHAN_NUM, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_ARG); - TEST_ASSERT(touch_sensor_new_channel(touch, 0, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_STATE); + TEST_ASSERT(touch_sensor_new_channel(touch, TOUCH_TOTAL_CHAN_NUM + TOUCH_MIN_CHAN_ID, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_ARG); + TEST_ASSERT(touch_sensor_new_channel(touch, TOUCH_MIN_CHAN_ID, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_STATE); TEST_ESP_OK(touch_sensor_enable(touch)); TEST_ASSERT(touch_sensor_del_channel(touch_chan[0]) == ESP_ERR_INVALID_STATE); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 465fd7d9b1..bcbb6761c4 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -577,7 +577,6 @@ components/soc/esp32/include/soc/soc_ulp.h components/soc/esp32/include/soc/spi_pins.h components/soc/esp32/include/soc/syscon_reg.h components/soc/esp32/include/soc/syscon_struct.h -components/soc/esp32/include/soc/touch_sensor_channel.h components/soc/esp32/include/soc/uart_pins.h components/soc/esp32/include/soc/uart_reg.h components/soc/esp32/include/soc/uart_struct.h @@ -643,7 +642,6 @@ components/soc/esp32s2/include/soc/soc_ulp.h components/soc/esp32s2/include/soc/spi_pins.h components/soc/esp32s2/include/soc/systimer_reg.h components/soc/esp32s2/include/soc/systimer_struct.h -components/soc/esp32s2/include/soc/touch_sensor_channel.h components/soc/esp32s2/include/soc/touch_sensor_pins.h components/soc/esp32s2/include/soc/uart_pins.h components/soc/esp32s2/include/soc/uart_reg.h @@ -700,7 +698,6 @@ components/soc/esp32s3/include/soc/system_reg.h components/soc/esp32s3/include/soc/system_struct.h components/soc/esp32s3/include/soc/systimer_reg.h components/soc/esp32s3/include/soc/systimer_struct.h -components/soc/esp32s3/include/soc/touch_channel.h components/soc/esp32s3/include/soc/uart_pins.h components/soc/esp32s3/include/soc/uart_reg.h components/soc/esp32s3/include/soc/uart_struct.h