diff --git a/components/esp_driver_gpio/src/rtc_io.c b/components/esp_driver_gpio/src/rtc_io.c index 6e955feb7b..ef6ae489e2 100644 --- a/components/esp_driver_gpio/src/rtc_io.c +++ b/components/esp_driver_gpio/src/rtc_io.c @@ -67,7 +67,8 @@ esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num) // Select Gpio as Digital Gpio rtcio_hal_function_select(rtc_io_number_get(gpio_num), RTCIO_LL_FUNC_DIGITAL); -#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + // TODO: IDF-14951 Turning off the lp io clock might affect other lp peripherals. Temporary disabled. +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT && !CONFIG_IDF_TARGET_ESP32H4 io_mux_force_disable_lp_io_clock(gpio_num); #endif RTCIO_EXIT_CRITICAL(); diff --git a/components/esp_driver_touch_sens/common/touch_sens_common.c b/components/esp_driver_touch_sens/common/touch_sens_common.c index 801a038570..91d5c353d8 100644 --- a/components/esp_driver_touch_sens/common/touch_sens_common.c +++ b/components/esp_driver_touch_sens/common/touch_sens_common.c @@ -93,7 +93,7 @@ esp_err_t touch_sensor_new_controller(const touch_sensor_config_t *sens_cfg, tou #if SOC_TOUCH_SENSOR_VERSION <= 2 ESP_GOTO_ON_ERROR(rtc_isr_register(touch_priv_default_intr_handler, NULL, TOUCH_LL_INTR_MASK_ALL, 0), err, TAG, "Failed to register interrupt handler"); #else - ESP_GOTO_ON_ERROR(esp_intr_alloc(ETS_LP_TOUCH_INTR_SOURCE, TOUCH_INTR_ALLOC_FLAGS, touch_priv_default_intr_handler, NULL, &(g_touch->intr_handle)), + ESP_GOTO_ON_ERROR(esp_intr_alloc(TOUCH_LL_INTR_SOURCE, TOUCH_INTR_ALLOC_FLAGS, touch_priv_default_intr_handler, NULL, &(g_touch->intr_handle)), err, TAG, "Failed to register interrupt handler"); #endif *ret_sens_handle = g_touch; 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 bb5f4c1034..da372347ba 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 @@ -147,7 +147,7 @@ static esp_err_t s_touch_convert_to_hal_config(touch_sensor_handle_t sens_handle ESP_RETURN_ON_FALSE(sens_cfg->trigger_rise_cnt < 2, ESP_ERR_INVALID_ARG, TAG, "this target do not support trigger_rise_cnt > 1"); #endif - + esp_err_t ret = ESP_OK; /* Get the source clock frequency for the first time */ if (!sens_handle->src_freq_hz) { /* Touch sensor actually uses dynamic fast clock LP_DYN_FAST_CLK, but it will only switch to the slow clock during sleep, @@ -157,8 +157,12 @@ static esp_err_t s_touch_convert_to_hal_config(touch_sensor_handle_t sens_handle 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"); + ret = esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_RTC_SLOW, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &sens_handle->interval_freq_hz); + if (ret != ESP_OK) { + ESP_LOGW(TAG, "get cached interval clock frequency failed, try to get approximate frequency"); + ret = esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_RTC_SLOW, ESP_CLK_TREE_SRC_FREQ_PRECISION_APPROX, &sens_handle->interval_freq_hz); + } + ESP_RETURN_ON_ERROR(ret, TAG, "get interval clock frequency failed"); } uint32_t src_freq_hz = sens_handle->src_freq_hz; @@ -424,8 +428,8 @@ esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, co #if SOC_PM_SUPPORT_RTC_PERIPH_PD esp_sleep_pd_domain_t pd_domain = ESP_PD_DOMAIN_RTC_PERIPH; #else -#warning "RTC_PERIPH power domain is not supported" esp_sleep_pd_domain_t pd_domain = ESP_PD_DOMAIN_MAX; + ESP_LOGW(TAG, "RTC_PERIPH power domain is not supported"); #endif // SOC_PM_SUPPORT_RTC_PERIPH_PD ESP_GOTO_ON_ERROR(esp_sleep_pd_config(pd_domain, slp_opt), err, TAG, "Failed to set RTC_PERIPH power domain"); diff --git a/components/esp_driver_touch_sens/test_apps/touch_sens/README.md b/components/esp_driver_touch_sens/test_apps/touch_sens/README.md index 66d419d46b..7824d26684 100644 --- a/components/esp_driver_touch_sens/test_apps/touch_sens/README.md +++ b/components/esp_driver_touch_sens/test_apps/touch_sens/README.md @@ -1,3 +1,3 @@ -| Supported Targets | ESP32 | ESP32-P4 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/soc/esp32/include/soc/touch_sensor_channel.h b/components/esp_hal_touch_sens/esp32/include/hal/touch_sensor_channel.h similarity index 95% rename from components/soc/esp32/include/soc/touch_sensor_channel.h rename to components/esp_hal_touch_sens/esp32/include/hal/touch_sensor_channel.h index ce2a1993dc..fb53842370 100644 --- a/components/soc/esp32/include/soc/touch_sensor_channel.h +++ b/components/esp_hal_touch_sens/esp32/include/hal/touch_sensor_channel.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #ifndef _SOC_TOUCH_CHANNEL_H diff --git a/components/esp_hal_touch_sens/esp32/touch_sensor_periph.c b/components/esp_hal_touch_sens/esp32/touch_sensor_periph.c index 26fbd01c76..e10178021c 100644 --- a/components/esp_hal_touch_sens/esp32/touch_sensor_periph.c +++ b/components/esp_hal_touch_sens/esp32/touch_sensor_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/touch_sensor_channel.h" +#include "hal/touch_sensor_channel.h" /* Store IO number corresponding to the Touch Sensor channel number. */ const int touch_sensor_channel_io_map[] = { diff --git a/components/esp_hal_touch_sens/esp32h4/include/hal/touch_sensor_channel.h b/components/esp_hal_touch_sens/esp32h4/include/hal/touch_sensor_channel.h new file mode 100644 index 0000000000..4db058da2e --- /dev/null +++ b/components/esp_hal_touch_sens/esp32h4/include/hal/touch_sensor_channel.h @@ -0,0 +1,54 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +//Touch channels + +#define TOUCH_PAD_GPIO0_CHANNEL 0 +#define TOUCH_PAD_NUM0_GPIO_NUM 0 + +#define TOUCH_PAD_GPIO1_CHANNEL 1 +#define TOUCH_PAD_NUM1_GPIO_NUM 1 + +#define TOUCH_PAD_GPIO2_CHANNEL 2 +#define TOUCH_PAD_NUM2_GPIO_NUM 2 + +#define TOUCH_PAD_GPIO3_CHANNEL 3 +#define TOUCH_PAD_NUM3_GPIO_NUM 3 + +#define TOUCH_PAD_GPIO29_CHANNEL 4 +#define TOUCH_PAD_NUM4_GPIO_NUM 29 + +#define TOUCH_PAD_GPIO30_CHANNEL 5 +#define TOUCH_PAD_NUM5_GPIO_NUM 30 + +#define TOUCH_PAD_GPIO31_CHANNEL 6 +#define TOUCH_PAD_NUM6_GPIO_NUM 31 + +#define TOUCH_PAD_GPIO32_CHANNEL 7 +#define TOUCH_PAD_NUM7_GPIO_NUM 32 + +#define TOUCH_PAD_GPIO33_CHANNEL 8 +#define TOUCH_PAD_NUM8_GPIO_NUM 33 + +#define TOUCH_PAD_GPIO34_CHANNEL 9 +#define TOUCH_PAD_NUM9_GPIO_NUM 34 + +#define TOUCH_PAD_GPIO35_CHANNEL 10 +#define TOUCH_PAD_NUM10_GPIO_NUM 35 + +#define TOUCH_PAD_GPIO36_CHANNEL 11 +#define TOUCH_PAD_NUM11_GPIO_NUM 36 + +#define TOUCH_PAD_GPIO37_CHANNEL 12 +#define TOUCH_PAD_NUM12_GPIO_NUM 37 + +#define TOUCH_PAD_GPIO38_CHANNEL 13 +#define TOUCH_PAD_NUM13_GPIO_NUM 38 + +#define TOUCH_PAD_GPIO39_CHANNEL 14 +#define TOUCH_PAD_NUM14_GPIO_NUM 39 diff --git a/components/esp_hal_touch_sens/esp32h4/include/hal/touch_sensor_ll.h b/components/esp_hal_touch_sens/esp32h4/include/hal/touch_sensor_ll.h new file mode 100644 index 0000000000..b17726fa37 --- /dev/null +++ b/components/esp_hal_touch_sens/esp32h4/include/hal/touch_sensor_ll.h @@ -0,0 +1,1063 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/******************************************************************************* + * NOTICE + * The ll is not public api, don't use in application code. + * See readme.md in hal/include/hal/readme.md + ******************************************************************************/ + +#pragma once + +#include +#include +#include "hal/misc.h" +#include "hal/assert.h" +#include "hal/touch_sensor_periph.h" +#include "hal/touch_sens_types.h" +#include "hal/config.h" +#include "soc/lp_analog_peri_struct.h" +#include "soc/lp_clkrst_struct.h" +#include "soc/lpperi_struct.h" +#include "soc/touch_aon_struct.h" +#include "soc/touch_struct.h" +#include "soc/pmu_struct.h" +#include "soc/soc_caps.h" +#include "esp_rom_sys.h" + +#define TOUCH_LL_GET(_attr) TOUCH_LL_ ## _attr +#define TOUCH_LL_CHAN_NUM 15 + +#ifdef __cplusplus +extern "C" { +#endif + +#define TOUCH_LL_READ_BENCHMARK 0x2 +#define TOUCH_LL_READ_SMOOTH 0x3 + +#define TOUCH_LL_TIMER_FORCE_DONE_BY_SW 0x1 +#define TOUCH_LL_TIMER_DONE_BY_FSM 0x0 + +// Interrupt mask +#define TOUCH_LL_INTR_MASK_SCAN_DONE BIT(0) +#define TOUCH_LL_INTR_MASK_DONE BIT(1) +#define TOUCH_LL_INTR_MASK_ACTIVE BIT(2) +#define TOUCH_LL_INTR_MASK_INACTIVE BIT(3) +#define TOUCH_LL_INTR_MASK_TIMEOUT BIT(4) +#define TOUCH_LL_INTR_MASK_PROX_DONE BIT(5) +// #define TOUCH_LL_INTR_MASK_BENCHMARK_UPDATE BIT(6) +#define TOUCH_LL_INTR_MASK_ALL (0x3F) + +#define TOUCH_LL_FULL_CHANNEL_MASK ((uint16_t)((1U << (TOUCH_LL_GET(CHAN_NUM))) - 1) << SOC_TOUCH_MIN_CHAN_ID) +#define TOUCH_LL_NULL_CHANNEL (15) // Null Channel id. Used for disabling some functions like sleep/proximity/waterproof + +#define TOUCH_LL_PAD_MEASURE_WAIT_MAX (0x7FFF) // The timer frequency is 8Mhz, the max value is 0xff +#define TOUCH_LL_ACTIVE_THRESH_MAX (0xFFFF) // Max channel active threshold +#define TOUCH_LL_CLK_DIV_MAX (0x08) // Max clock divider value +#define TOUCH_LL_TIMEOUT_MAX (0xFFFF) // Max timeout value +#define TOUCH_LL_SLP_MEASURE_WAIT_MAX (0x1FF) // Max wait ticks to wait PMU entering HP SLEEP status during the sleep. + +#define TOUCH_LL_SUPPORT_PROX_DONE (1) + +#define TOUCH_LL_INTR_SOURCE ETS_TOUCH_INTR_SOURCE // Touch sensor interrupt source, defined in ll for the driver compatibility + +/** + * Enable/disable clock gate of touch sensor. + * + * @param enable true/false. + */ +static inline void touch_ll_enable_module_clock(bool enable) +{ + LPPERI.clk_en.lp_touch_ck_en = enable; + // This clock decides whether the value can be written to the TOUCH_AON registers. + LP_CLKRST.lp_clk_en.aon_touch_gate = enable; +} + +/** + * Enable/disable clock gate of touch sensor. + * + * @param enable true/false. + */ +static inline void touch_ll_reset_module(void) +{ + LPPERI.reset_en.lp_touch_reset_en = 1; + LPPERI.reset_en.lp_touch_reset_en = 0; +} + +/** + * Set the power on wait cycle + * + * @param wait_cycles + */ +static inline void touch_ll_set_power_on_wait_cycle(uint32_t wait_cycles) +{ + TOUCH_AON.aon_scan_ctrl1.aon_touch_xpd_wait = wait_cycles; +} + +/** + * Set touch sensor touch sensor charge and discharge times of every measurement on a pad. + * + * @param sample_cfg_id The sample configuration index + * @param charge_times The times of charge and discharge in each measure process of touch channels. + * The timer frequency is RTC_FAST (about 16M). Range: 0 ~ 0xffff. + */ +static inline void touch_ll_set_charge_times(uint8_t sample_cfg_id, uint16_t charge_times) +{ + //The times of charge and discharge in each measure process of touch channels. + switch (sample_cfg_id) { + case 0: + TOUCH_AON.aon_work_meas_num.aon_touch_meas_num0 = charge_times; + break; + case 1: + TOUCH_AON.aon_work_meas_num.aon_touch_meas_num1 = charge_times; + break; + case 2: + TOUCH_AON.aon_work_meas_num.aon_touch_meas_num2 = charge_times; + break; + default: + abort(); + } +} + +/** + * Get touch sensor times of charge and discharge. + * + * @param meas_times Pointer to accept times count of charge and discharge. + */ +static inline void touch_ll_get_charge_times(uint8_t sample_cfg_id, uint16_t *charge_times) +{ + switch (sample_cfg_id) { + case 0: + *charge_times = TOUCH_AON.aon_work_meas_num.aon_touch_meas_num0; + break; + case 1: + *charge_times = TOUCH_AON.aon_work_meas_num.aon_touch_meas_num1; + break; + case 2: + *charge_times = TOUCH_AON.aon_work_meas_num.aon_touch_meas_num2; + break; + default: + abort(); + } +} + +/** + * Set touch sensor sleep time. + * + * @param interval_ticks The touch sensor will sleep for some cycles after each measurement. + * interval_ticks decide the interval between each measurement. + * t_sleep = interval_ticks / (RTC_SLOW_CLK frequency). + * The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function. + */ +static inline void touch_ll_set_measure_interval_ticks(uint16_t interval_ticks) +{ + // touch sensor sleep cycle Time = interval_ticks / RTC_SLOW_CLK + HAL_FORCE_MODIFY_U32_REG_FIELD(PMU.touch_pwr_ctrl, touch_sleep_cycles, interval_ticks); +} + +/** + * Get touch sensor sleep time. + * + * @param interval_ticks Pointer to accept measurement interval (sleep) cycle number. + */ +static inline void touch_ll_get_measure_interval_ticks(uint16_t *interval_ticks) +{ + *interval_ticks = HAL_FORCE_READ_U32_REG_FIELD(PMU.touch_pwr_ctrl, touch_sleep_cycles); +} + +/** + * Enable touch sensor FSM timer trigger (continuous) mode or software trigger (oneshot) mode. + * + * @param enable Enable FSM timer mode. + * True: the FSM will trigger scanning repeatedly under the control of the hardware timer (continuous mode) + * False: the FSM will trigger scanning once under the control of the software (continuous mode) + */ +__attribute__((always_inline)) +static inline void touch_ll_enable_fsm_timer(bool enable) +{ + // FSM controlled by timer or software + TOUCH_AON.aon_mux0.aon_touch_fsm_en = enable; + // Set 0 to stop by timer, otherwise by software + TOUCH_AON.aon_mux0.aon_touch_done_force = !enable; + // Set 0 to start by timer, otherwise by software + TOUCH_AON.aon_mux0.aon_touch_start_force = !enable; +} + +/** + * Is touch sensor FSM using hardware timer to trigger scanning. + * The measurement action can be triggered by the hardware timer, as well as by the software instruction. + * + * @return Whether FSM timer enabled. + */ +static inline bool touch_ll_is_fsm_using_timer(void) +{ + return !TOUCH_AON.aon_mux0.aon_touch_start_force; +} + +/** + * Touch timer trigger measurement and always wait measurement done. + * Force done for touch timer ensures that the timer always can get the measurement done signal. + * @note The `force done` signal should last as least one slow clock tick + */ +__attribute__((always_inline)) +static inline void touch_ll_force_done_curr_measurement(void) +{ + // Set `force done` signal + PMU.touch_pwr_ctrl.touch_force_done = 1; + // Force done signal should last at least one slow clock tick + esp_rom_delay_us(3); + // Clear `force done` signal + PMU.touch_pwr_ctrl.touch_force_done = 0; +} + +/** + * Start touch sensor FSM timer to run FSM repeatedly + * The measurement action can be triggered by the hardware timer, as well as by the software instruction. + * @note + * The timer should be triggered + */ +__attribute__((always_inline)) +static inline void touch_ll_start_fsm_repeated_timer(void) +{ + /** + * Touch timer trigger measurement and always wait measurement done. + * Force done for touch timer ensures that the timer always can get the measurement done signal. + */ + touch_ll_force_done_curr_measurement(); + PMU.touch_pwr_ctrl.touch_sleep_timer_en = 1; +} + +/** + * Stop touch sensor FSM timer. + * The measurement action can be triggered by the hardware timer, as well as by the software instruction. + */ +__attribute__((always_inline)) +static inline void touch_ll_stop_fsm_repeated_timer(void) +{ + PMU.touch_pwr_ctrl.touch_sleep_timer_en = 0; + touch_ll_force_done_curr_measurement(); +} + +/** + * Is the FSM repeated timer enabled. + * @note when the timer is enabled, RTC clock should not be power down + * + * @return + * - true: enabled + * - true: disabled + */ +__attribute__((always_inline)) +static inline bool touch_ll_is_fsm_repeated_timer_enabled(void) +{ + return (bool)(PMU.touch_pwr_ctrl.touch_sleep_timer_en); +} + +/** + * Enable the touch sensor FSM start signal from software + */ +__attribute__((always_inline)) +static inline void touch_ll_trigger_oneshot_measurement(void) +{ + /* Trigger once measurement */ + TOUCH_AON.aon_mux0.aon_touch_start_en = 1; + TOUCH_AON.aon_mux0.aon_touch_start_en = 0; +} + +static inline void touch_ll_measure_channel_once(uint16_t chan_mask) +{ + TOUCH_AON.aon_mux1.aon_touch_start = chan_mask; +} + +/** + * Set touch sensor threshold of charge cycles that triggers pad active state. + * The threshold determines the sensitivity of the touch sensor. + * The threshold is the original value of the trigger state minus the benchmark value. + * + * @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered. + * @param touch_num The touch pad id + * @param sample_cfg_id The sample configuration index + * @param thresh The threshold of charge cycles + */ +static inline void touch_ll_set_chan_active_threshold(uint32_t touch_num, uint8_t sample_cfg_id, uint32_t thresh) +{ + HAL_ASSERT(sample_cfg_id < SOC_TOUCH_SAMPLE_CFG_NUM); + HAL_FORCE_MODIFY_U32_REG_FIELD(TOUCH_AON.aon_padx_thn[touch_num].thresh[sample_cfg_id], threshold, thresh); // codespell:ignore +} + +/** + * Get touch sensor threshold of charge cycles that triggers pad active state. + * The threshold determines the sensitivity of the touch sensor. + * The threshold is the original value of the trigger state minus the benchmark value. + * + * @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered. + * @param touch_num The touch pad id + * @param sample_cfg_id The sample configuration index + * @return + * - The threshold of charge cycles + */ +static inline uint32_t touch_ll_get_chan_active_threshold(uint32_t touch_num, uint8_t sample_cfg_id) +{ + HAL_ASSERT(sample_cfg_id < SOC_TOUCH_SAMPLE_CFG_NUM); + return HAL_FORCE_READ_U32_REG_FIELD(TOUCH_AON.aon_padx_thn[touch_num].thresh[sample_cfg_id], threshold); // codespell:ignore +} + +/** + * @brief Enable or disable the channel that will be scanned. + * @note The shield channel should not be enabled to scan here + * + * @param chan_mask The channel mask to be enabled or disabled + * @param enable Enable or disable the channel mask + */ +__attribute__((always_inline)) +static inline void touch_ll_enable_scan_mask(uint16_t chan_mask, bool enable) +{ + // the lowest bit takes no effect + uint16_t mask = chan_mask & TOUCH_LL_FULL_CHANNEL_MASK; + uint16_t prev_mask = TOUCH_AON.aon_scan_ctrl1.aon_touch_scan_pad_map; + if (enable) { + TOUCH_AON.aon_scan_ctrl1.aon_touch_scan_pad_map = prev_mask | mask; + } else { + TOUCH_AON.aon_scan_ctrl1.aon_touch_scan_pad_map = prev_mask & (~mask); + } +} + +/** + * Enable touch sensor channel. Register touch channel into touch sensor measurement group. + * The working mode of the touch sensor is simultaneous measurement. + * This function will set the measure bits according to the given bitmask. + * + * @note If set this mask, the FSM timer should be stop firstly. + * @note The touch sensor that in scan map, should be deinit GPIO function firstly. + * @param enable_mask bitmask of touch sensor scan group. + * e.g. TOUCH_PAD_NUM1 -> BIT(1) + * @return + * - ESP_OK on success + */ +static inline void touch_ll_enable_channel_mask(uint16_t enable_mask) +{ + // the lowest bit takes no effect + uint16_t mask = enable_mask & TOUCH_LL_FULL_CHANNEL_MASK; + TOUCH_AON.aon_scan_ctrl1.aon_touch_scan_pad_map = mask; + TOUCH_AON.aon_filter2.aon_touch_outen = mask; +} + +/** + * @brief Power on the channel by mask + * + * @param chan_mask The channel mask that needs to power on + */ +__attribute__((always_inline)) +static inline void touch_ll_channel_sw_measure_mask(uint16_t chan_mask) +{ + TOUCH_AON.aon_mux1.aon_touch_xpd = chan_mask; + TOUCH_AON.aon_mux1.aon_touch_start = chan_mask; +} + +/** + * @brief Power off the channel by mask + * + * @param chan_mask The channel mask that needs to power off + */ +static inline void touch_ll_channel_power_off(uint16_t chan_mask) +{ + uint32_t curr_mask = TOUCH_AON.aon_mux1.aon_touch_xpd; + TOUCH_AON.aon_mux1.aon_touch_xpd = (~chan_mask) & curr_mask; +} + +/** + * Get the touch sensor active channel mask, usually used in ISR to decide which channels are 'touched'. + * + * @param active_mask The touch channel status. e.g. Touch1 trigger status is `status_mask & (BIT1)`. + */ +__attribute__((always_inline)) +static inline void touch_ll_get_active_channel_mask(uint32_t *active_mask) +{ + *active_mask = TOUCH_SENS.chn_status.pad_active; +} + +/** + * Clear all touch sensor channels active status. + * + * @note Generally no manual removal is required. + */ +static inline void touch_ll_clear_active_channel_status(void) +{ + TOUCH_AON.aon_clr.aon_touch_status_clr = 1; +} + +/** + * Get the data of the touch channel according to the types + * + * @param touch_num touch pad index + * @param sample_cfg_id The sample configuration index + * @param type data type + * 0/1: not work + * 2: TOUCH_LL_READ_BENCHMARK, benchmark value of touch channel, + * the benchmark value is the maximum during the first measurement period + * 3: TOUCH_LL_READ_SMOOTH, the smoothed data that obtained by filtering the raw data. + * @param data pointer to the data + */ +__attribute__((always_inline)) +static inline void touch_ll_read_chan_data(uint32_t touch_num, uint8_t sample_cfg_id, uint8_t type, uint32_t *data) +{ + HAL_ASSERT(sample_cfg_id < SOC_TOUCH_SAMPLE_CFG_NUM); + HAL_ASSERT(type == TOUCH_LL_READ_BENCHMARK || type == TOUCH_LL_READ_SMOOTH); + TOUCH_AON.aon_mux0.aon_touch_freq_sel = sample_cfg_id; + TOUCH_AON.aon_mux0.aon_touch_data_sel = type; + *data = HAL_FORCE_READ_U32_REG_FIELD(TOUCH_SENS.chn_data[touch_num], pad_data); +} + +/** + * Get touch sensor measure status. No block. + * + * @return + * - If touch sensors measure done. + */ +__attribute__((always_inline)) +static inline bool touch_ll_is_measure_done(void) +{ + return (bool)TOUCH_SENS.chn_status.meas_done; +} + +/** + * Select the counting mode of the binarized touch out wave + * + * @param mode 0: as data, the value will be smaller than actual value but more sensitive when the frequency of touch_out is close to the source clock + * 1: as clock, the value is accurate but less sensitive when the frequency of touch_out is close to the source clock + * No big difference when the frequency of touch_out is far more lower than the source clock + */ +static inline void touch_ll_set_out_mode(touch_out_mode_t mode) +{ + TOUCH_AON.aon_work.aon_touch_out_sel = mode; +} + +/** + * @brief Enable/disable the touch sensor output gate + * + * @param enable set true to enable the output gate, false to disable it + */ +static inline void touch_ll_enable_out_gate(bool enable) +{ + TOUCH_AON.aon_work.aon_touch_out_gate = enable; +} + +/** + * @brief Set the clock division of the sampling frequency + * + * @param sample_cfg_id The sample configuration index + * @param div_num Division number + */ +static inline void touch_ll_set_clock_div(uint8_t sample_cfg_id, uint32_t div_num) +{ + switch (sample_cfg_id) { + case 0: + TOUCH_AON.aon_work.aon_div_num0 = div_num - 1; + break; + case 1: + TOUCH_AON.aon_work.aon_div_num1 = div_num - 1; + break; + case 2: + TOUCH_AON.aon_work.aon_div_num2 = div_num - 1; + break; + default: + // invalid sample_cfg_id + abort(); + } +} + +/** + * Set connection type of touch channel in idle status. + * When a channel is in measurement mode, other initialized channels are in idle mode. + * The touch channel is generally adjacent to the trace, so the connection state of the idle channel + * affects the stability and sensitivity of the test channel. + * The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels. + * The `CONN_GND`(grounding) setting increases the stability of touch channels. + * @note This option does not take effect, it is default to HIGH Z + * Only remained here to be compatible to other version + * + * @param type Select idle channel connect to high resistance state or ground. (No effect) + */ +static inline void touch_ll_set_idle_channel_connect(touch_idle_conn_t type) +{ + (void)type; +} + +/** + * Get the current channel that under measuring. + * + * @return + * - touch channel number + */ +__attribute__((always_inline)) +static inline uint32_t touch_ll_get_current_meas_channel(void) +{ + return TOUCH_SENS.chn_status.scan_curr; +} + +/** + * Enable touch sensor interrupt by bitmask. + * + * @param int_mask interrupt mask + */ +static inline void touch_ll_interrupt_enable(uint32_t int_mask) +{ + uint32_t mask = TOUCH_SENS.int_ena.val; + mask |= (int_mask & TOUCH_LL_INTR_MASK_ALL); + TOUCH_SENS.int_ena.val = mask; +} + +/** + * Disable touch sensor interrupt by bitmask. + * + * @param int_mask interrupt mask + */ +static inline void touch_ll_interrupt_disable(uint32_t int_mask) +{ + uint32_t mask = TOUCH_SENS.int_ena.val; + mask &= ~(int_mask & TOUCH_LL_INTR_MASK_ALL); + TOUCH_SENS.int_ena.val = mask; +} + +/** + * Clear touch sensor interrupt by bitmask. + * + * @param int_mask Pad mask to clear interrupts + */ +__attribute__((always_inline)) +static inline void touch_ll_interrupt_clear(uint32_t int_mask) +{ + TOUCH_SENS.int_clr.val = int_mask; +} + +/** + * Get the bitmask of touch sensor interrupt status. + * + * @return type interrupt type + */ +__attribute__((always_inline)) +static inline uint32_t touch_ll_get_intr_status_mask(void) +{ + uint32_t intr_st = TOUCH_SENS.int_st.val; + return (intr_st & TOUCH_LL_INTR_MASK_ALL); +} + +/** + * Set the timeout to enable or disable the check for all touch sensor channels measurements. + * When the touch reading of a touch channel exceeds the measurement threshold, + * If enable: a timeout interrupt will be generated and it will go to the next channel measurement. + * If disable: the FSM is always on the channel, until the measurement of this channel is over. + * + * @param timeout_cycles The maximum time cycles of the measurement on one channel. + * Set to 0 to disable the timeout. + * Set to non-zero to enable the timeout and set the timeout cycles. + */ +static inline void touch_ll_set_timeout(uint32_t timeout_cycles) +{ + if (timeout_cycles) { + HAL_FORCE_MODIFY_U32_REG_FIELD(TOUCH_AON.aon_scan_ctrl2, aon_touch_timeout_num, timeout_cycles); + TOUCH_AON.aon_scan_ctrl2.aon_touch_timeout_en = 1; + } else { + TOUCH_AON.aon_scan_ctrl2.aon_touch_timeout_en = 0; + } +} + +/** + * Set the engaged sample configuration number + * + * @param sample_cfg_num The enabled sample configuration number, range 0~3. + * 0/1 means only one sample configuration enabled, which can not support frequency hopping + */ +static inline void touch_ll_sample_cfg_set_engaged_num(uint8_t sample_cfg_num) +{ + HAL_ASSERT(sample_cfg_num <= SOC_TOUCH_SAMPLE_CFG_NUM); + TOUCH_AON.aon_scan_ctrl2.aon_freq_scan_en = !!sample_cfg_num; + TOUCH_AON.aon_scan_ctrl2.aon_freq_scan_cnt_limit = sample_cfg_num ? sample_cfg_num : 1; +} + +/** + * Get the engaged sample configuration number + * + * @return The engaged sample configuration number, range 0~3. + */ +static inline uint32_t touch_ll_sample_cfg_get_engaged_num(void) +{ + uint32_t sample_cfg_num = TOUCH_AON.aon_scan_ctrl2.aon_freq_scan_cnt_limit; + return sample_cfg_num ? sample_cfg_num : 1; +} + +/** + * Set the number of trigger rise count + * + * @param rise_cnt Configure the number of hit frequency points that need to be determined for touch + * in frequency hopping mode. + */ +static inline void touch_ll_sample_cfg_set_trigger_rise_cnt(uint8_t rise_cnt) +{ +#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300 + TOUCH_AON.aon_ctrl.aon_freq_scan_cnt_rise = rise_cnt; +#endif +} + +/** + * Set capacitance and resistance of the RC filter of the sampling frequency. + * + * @param sample_cfg_id The sample configuration index + * @param cap Capacitance of the RC filter. + * @param res Resistance of the RC filter. + */ +static inline void touch_ll_sample_cfg_set_rc_filter(uint8_t sample_cfg_id, uint32_t cap, uint32_t res) +{ + HAL_ASSERT(sample_cfg_id < SOC_TOUCH_SAMPLE_CFG_NUM); + TOUCH_AON.aon_freq_scan_para[sample_cfg_id].aon_touch_freq_dcap_lpf = cap; + TOUCH_AON.aon_freq_scan_para[sample_cfg_id].aon_touch_freq_dres_lpf = res; +} + +/** + * @brief Set the driver of the sampling frequency + * + * @param sample_cfg_id The sample configuration index + * @param ls_drv Low speed touch driver + * @param hs_drv High speed touch driver + */ +static inline void touch_ll_sample_cfg_set_driver(uint8_t sample_cfg_id, uint32_t ls_drv, uint32_t hs_drv) +{ + HAL_ASSERT(sample_cfg_id < SOC_TOUCH_SAMPLE_CFG_NUM); + TOUCH_AON.aon_freq_scan_para[sample_cfg_id].aon_touch_freq_drv_ls = ls_drv; + TOUCH_AON.aon_freq_scan_para[sample_cfg_id].aon_touch_freq_drv_hs = hs_drv; +} + +/** + * Set the touch internal LDO bias voltage of the sampling frequency + * + * @param sample_cfg_id The sample configuration index + * @param bias_volt LDO bias voltage + */ +static inline void touch_ll_sample_cfg_set_bias_voltage(uint8_t sample_cfg_id, uint32_t bias_volt) +{ + HAL_ASSERT(sample_cfg_id < SOC_TOUCH_SAMPLE_CFG_NUM); + TOUCH_AON.aon_freq_scan_para[sample_cfg_id].aon_touch_freq_dbias = bias_volt; +} + +/** + * @brief Set the internal loop capacitance + * Can simulate the touch signal via the internal capacitance + * Need to turn off touch pad + * @param cap The internal capacitance + */ +static inline void touch_ll_set_internal_loop_capacitance(int cap) +{ + bool enable = cap > 0; + TOUCH_AON.aon_ana_para.aon_touch_touch_en_cal = enable; + TOUCH_AON.aon_ana_para.aon_touch_touch_dcap_cal = enable ? cap : 0; +} + +/************************ Filter register setting ************************/ + +/** + * Force reset benchmark to raw data of touch sensor. + * + * @note If call this API, make sure enable clock gate(`touch_ll_clkgate`) first. + * @param chan_mask touch channel mask + */ +__attribute__((always_inline)) +static inline void touch_ll_reset_chan_benchmark(uint32_t chan_mask) +{ + TOUCH_AON.aon_clr.aon_touch_channel_clr = chan_mask; +} + +/** + * Set filter mode. The input of the filter is the raw value of touch reading, + * and the output of the filter is involved in the judgment of the touch state. + * + * @param mode Filter mode type. Refer to ``touch_benchmark_filter_mode_t``. + */ +static inline void touch_ll_filter_set_filter_mode(touch_benchmark_filter_mode_t mode) +{ + TOUCH_AON.aon_filter1.aon_touch_filter_mode = mode; +} + +/** + * Set filter mode. The input to the filter is raw data and the output is the smooth data. + * The smooth data is used to determine the touch status. + * + * @param mode Filter mode type. Refer to ``touch_smooth_filter_mode_t``. + */ +static inline void touch_ll_filter_set_smooth_mode(touch_smooth_filter_mode_t mode) +{ + TOUCH_AON.aon_filter1.aon_touch_smooth_lvl = mode; +} + +/** + * Set debounce count, such as `n`. If the measured values continue to exceed + * the threshold for `n+1` times, it is determined that the touch sensor state changes. + * + * @param dbc_cnt Debounce count value. + */ +static inline void touch_ll_filter_set_debounce(uint32_t dbc_cnt) +{ + TOUCH_AON.aon_filter1.aon_touch_debounce_limit = dbc_cnt; +} + +/** + * Set the denoise coefficient regarding the denoise level. + * + * @param denoise_lvl Range [0 ~ 4]. 0 = no noise resistance, otherwise higher denoise_lvl means more noise resistance. + */ +static inline void touch_ll_filter_set_denoise_level(int denoise_lvl) +{ + HAL_ASSERT(denoise_lvl >= 0 && denoise_lvl <= 4); + bool always_update = denoise_lvl == 0; + // Map denoise level to actual noise threshold coefficients + uint32_t noise_thresh = denoise_lvl == 4 ? 3 : 3 - denoise_lvl; + + TOUCH_AON.aon_filter2.aon_touch_bypass_noise_thres = always_update; + TOUCH_AON.aon_filter1.aon_touch_noise_thres = always_update ? 0 : noise_thresh; + + TOUCH_AON.aon_filter2.aon_touch_bypass_nn_thres = always_update; + TOUCH_AON.aon_filter1.aon_touch_nn_thres = always_update ? 0 : noise_thresh; + TOUCH_AON.aon_filter1.aon_touch_nn_limit = 5; // 5 is the default value +} + +/** + * Set the hysteresis value of the active threshold + * While the touch data is greater than active_threshold + hysteresis and last for several ticks, the channel is activated, + * and while the touch data is smaller than active_threshold - hysteresis and last for several ticks, the channel is inactivated + * + * @param hysteresis The hysteresis value of active threshold + */ +static inline void touch_ll_filter_set_active_hysteresis(uint32_t hysteresis) +{ + TOUCH_AON.aon_filter1.aon_touch_hysteresis = hysteresis; +} + +/** + * Set jitter filter step size. + * If filter mode is jitter, should set filter step for jitter. + * Range: 0 ~ 15 + * + * @param step The step size of the data change. + */ +static inline void touch_ll_filter_set_jitter_step(uint32_t step) +{ + TOUCH_AON.aon_filter1.aon_touch_jitter_step = step; +} + +/** + * Enable or disable touch sensor filter and detection algorithm. + * For more details on the detection algorithm, please refer to the application documentation. + */ +static inline void touch_ll_filter_enable(bool enable) +{ + TOUCH_AON.aon_filter1.aon_touch_filter_en = enable; +} + +/** + * Force the update the benchmark by software + * @note This benchmark will be applied to all enabled channel and all sampling frequency + * + * @param pad_num The pad number, range [1-14] + * @param sample_cfg_id The sample configuration index, range [0-2] + * @param benchmark The benchmark specified by software + */ +static inline void touch_ll_force_update_benchmark(uint32_t pad_num, uint8_t sample_cfg_id, uint32_t benchmark) +{ + TOUCH_AON.aon_filter3.aon_touch_update_benchmark_pad_sel = pad_num; + TOUCH_AON.aon_filter3.aon_touch_update_benchmark_freq_sel = sample_cfg_id; + HAL_FORCE_MODIFY_U32_REG_FIELD(TOUCH_AON.aon_filter3, aon_touch_benchmark_sw, benchmark); + TOUCH_AON.aon_filter3.aon_touch_update_benchmark_sw = 1; + // waiting for update + while (TOUCH_AON.aon_filter3.aon_touch_update_benchmark_sw); +} + +/************************ Waterproof register setting ************************/ + +/** + * Set touch channel use for guard pad. + * + * @param pad_num Touch sensor channel number. + */ +static inline void touch_ll_waterproof_set_guard_chan(uint32_t pad_num) +{ + TOUCH_AON.aon_scan_ctrl2.aon_touch_out_ring = pad_num; +} + +/** + * Enable or disable parameter of waterproof function. + * + * The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel. + * Guard pad is used to detect the large area of water covering the touch panel. + * Shield pad is used to shield the influence of water droplets covering the touch panel. + * It is generally designed as a grid and is placed around the touch buttons. + */ +static inline void touch_ll_waterproof_enable(bool enable) +{ + TOUCH_AON.aon_scan_ctrl1.aon_touch_shield_pad_en = enable; +} + +/** + * Set the shield channel mask + * + * @param mask The channels that set in the mask will be used as shield channel + */ +static inline void touch_ll_waterproof_set_shield_chan_mask(uint32_t mask) +{ + TOUCH_AON.aon_mux0.aon_touch_bufsel = mask; +} + +/** + * Set the touch buff driver for the shield channel. + * + * @param driver_level The driver level of the touch buff + */ +static inline void touch_ll_waterproof_set_shield_driver(touch_chan_shield_cap_t driver_level) +{ + TOUCH_AON.aon_ana_para.aon_touch_touch_buf_drv = driver_level; +} + +/************************ Approach register setting ************************/ + +/** + * Set the proximity sensing channel to the specific touch channel + * To disable the proximity channel, point this pad to `TOUCH_LL_NULL_CHANNEL` + * + * @param prox_chan proximity sensing channel. + * @param touch_num The touch channel that supposed to be used as proximity sensing channel + */ +static inline void touch_ll_set_proximity_sensing_channel(uint8_t prox_chan, uint32_t touch_num) +{ + switch (prox_chan) { + case 0: + TOUCH_AON.aon_approach.aon_touch_approach_pad0 = touch_num; + break; + case 1: + TOUCH_AON.aon_approach.aon_touch_approach_pad1 = touch_num; + break; + case 2: + TOUCH_AON.aon_approach.aon_touch_approach_pad2 = touch_num; + break; + default: + // invalid proximity channel + abort(); + } +} + +/** + * Set the total scan times of the proximity sensing channel. + * + * @param scan_times The total scan times of the proximity sensing channel + */ +static inline void touch_ll_proximity_set_total_scan_times(uint32_t scan_times) +{ + HAL_FORCE_MODIFY_U32_REG_FIELD(TOUCH_AON.aon_filter1, aon_touch_approach_limit, scan_times); +} + +/** + * Set charge times for each sample configuration in proximity sensing mode. + * + * @param sample_cfg_id The sample configuration index + * @param charge_times The charge and discharge times. + */ +static inline void touch_ll_proximity_set_charge_times(uint8_t sample_cfg_id, uint32_t charge_times) +{ + switch (sample_cfg_id) { + case 0: + TOUCH_AON.aon_approach_work_meas_num.aon_touch_approach_meas_num0 = charge_times; + break; + case 1: + TOUCH_AON.aon_approach_work_meas_num.aon_touch_approach_meas_num1 = charge_times; + break; + case 2: + TOUCH_AON.aon_approach_work_meas_num.aon_touch_approach_meas_num2 = charge_times; + break; + default: + // invalid sample_cfg_id + abort(); + } +} + +/** + * Read current cumulative measurement times for proximity sensing channel. + * + * @param prox_chan proximity sensing channel. + * @param cnt The cumulative number of measurement cycles. + */ +static inline void touch_ll_proximity_read_measure_cnt(uint8_t prox_chan, uint32_t *cnt) +{ + switch (prox_chan) { + case 0: + *cnt = HAL_FORCE_READ_U32_REG_FIELD(TOUCH_SENS.aprch_ch_data, approach_pad0_cnt); + break; + case 1: + *cnt = HAL_FORCE_READ_U32_REG_FIELD(TOUCH_SENS.aprch_ch_data, approach_pad1_cnt); + break; + case 2: + *cnt = HAL_FORCE_READ_U32_REG_FIELD(TOUCH_SENS.aprch_ch_data, approach_pad2_cnt); + break; + default: // sleep channel + *cnt = HAL_FORCE_READ_U32_REG_FIELD(TOUCH_SENS.aprch_ch_data, slp_approach_cnt); + break; + } +} + +/** + * Check if the touch sensor channel is the proximity sensing channel. + * + * @param touch_num The touch sensor channel number. + */ +static inline bool touch_ll_is_proximity_sensing_channel(uint32_t touch_num) +{ + if ((TOUCH_AON.aon_approach.aon_touch_approach_pad0 != touch_num) + && (TOUCH_AON.aon_approach.aon_touch_approach_pad1 != touch_num) + && (TOUCH_AON.aon_approach.aon_touch_approach_pad2 != touch_num)) { + return false; + } + return true; +} + +/************** sleep channel setting ***********************/ + +/** + * Set touch channel number for sleep channel. + * + * @note Only one touch sensor channel is supported in deep sleep mode. + * @param touch_num Touch sensor channel number. + */ +static inline void touch_ll_sleep_set_channel_num(uint32_t touch_num) +{ + TOUCH_AON.aon_slp0.aon_touch_slp_pad = touch_num; +} + +/** + * Get touch channel number for sleep pad. + * + * @note Only one touch sensor channel is supported in deep sleep mode. + * @param touch_num Touch sensor channel number. + */ +static inline void touch_ll_sleep_get_channel_num(uint32_t *touch_num) +{ + *touch_num = (uint32_t)(TOUCH_AON.aon_slp0.aon_touch_slp_pad); +} + +/** + * Set the trigger threshold of touch sensor in deep sleep. + * The threshold determines the sensitivity of the touch sensor. + * The threshold is the original value of the trigger state minus the benchmark value. + * + * @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep. + */ +static inline void touch_ll_sleep_set_threshold(uint8_t sample_cfg_id, uint32_t touch_thresh) +{ + switch (sample_cfg_id) { + case 0: + HAL_FORCE_MODIFY_U32_REG_FIELD(TOUCH_AON.aon_slp0, aon_touch_slp_th0, touch_thresh); + break; + case 1: + HAL_FORCE_MODIFY_U32_REG_FIELD(TOUCH_AON.aon_slp1, aon_touch_slp_th1, touch_thresh); + break; + case 2: + HAL_FORCE_MODIFY_U32_REG_FIELD(TOUCH_AON.aon_slp1, aon_touch_slp_th2, touch_thresh); + break; + default: + // invalid sample_cfg_id + abort(); + } +} + +/** + * Set the touch sensor wait ticks after PMU is woken up by touch timer during the sleep. + * @note The PMU will be woken up after the measure interval timer time-up, + * PMU needs some time to prepare the clock and power for the touch sensor, + * If the wait ticks is too short, the touch sensor can't work properly and fail to wakeup the chip from sleep. + * + * @param wait_ticks The wait ticks after PMU is woken up by touch FSM during the sleep. + * Typically recommended to set it to the max value, + * the PMU will start the touch sensor FSM immediately after the PMU enters HP SLEEP state. + */ +static inline void touch_ll_sleep_set_measure_wait_ticks(uint32_t wait_ticks) +{ + PMU.touch_pwr_ctrl.touch_wait_cycles = wait_ticks; +} + +/** + * Enable proximity sensing function for sleep channel. + */ +static inline void touch_ll_sleep_enable_proximity_sensing(bool enable) +{ + TOUCH_AON.aon_approach.aon_touch_slp_approach_en = enable; +} + +/** + * Get the data of the touch channel according to the types + * + * @param sample_cfg_id The sample configuration index + * @param type data type + * 0/1: TOUCH_LL_READ_RAW, the raw data of the touch channel + * 2: TOUCH_LL_READ_BENCHMARK, benchmark value of touch channel, + * the benchmark value is the maximum during the first measurement period + * 3: TOUCH_LL_READ_SMOOTH, the smoothed data that obtained by filtering the raw data. + * @param smooth_data pointer to smoothed data + */ +__attribute__((always_inline)) +static inline void touch_ll_sleep_read_chan_data(uint8_t type, uint8_t sample_cfg_id, uint32_t *data) +{ + HAL_ASSERT(type <= TOUCH_LL_READ_SMOOTH); + TOUCH_AON.aon_mux0.aon_touch_freq_sel = sample_cfg_id + 1; + TOUCH_AON.aon_mux0.aon_touch_data_sel = type; + *data = HAL_FORCE_READ_U32_REG_FIELD(TOUCH_SENS.slp_ch_data, slp_data); +} + +/** + * @brief Reset the benchmark of the sleep channel + * + */ +static inline void touch_ll_sleep_reset_benchmark(void) +{ + TOUCH_AON.aon_slp0.aon_touch_slp_channel_clr = 1; +} + +/** + * Read debounce of touch sensor for sleep channel. + * + * @param debounce Pointer to accept touch sensor debounce value. + */ +static inline void touch_ll_sleep_read_debounce(uint32_t *debounce) +{ + *debounce = TOUCH_SENS.slp_ch_data.slp_debounce_cnt; +} + +/** + * Read proximity count of touch sensor for sleep channel. + * @param prox_cnt Pointer to accept touch sensor proximity count value. + */ +static inline void touch_ll_sleep_read_proximity_cnt(uint32_t *prox_cnt) +{ + *prox_cnt = HAL_FORCE_READ_U32_REG_FIELD(TOUCH_SENS.aprch_ch_data, slp_approach_cnt); +} + +/** + * @brief Enable or disable the internal capacitor, mainly for debug + * + * @param enable enable or disable the internal capacitor + */ +static inline void touch_ll_enable_internal_capacitor(bool enable) +{ + TOUCH_AON.aon_ana_para.aon_touch_touch_en_cal = enable; +} + +/** + * @brief Set the internal capacitor, mainly for debug + * @note Only take effect when the internal capacitor is enabled + * + * @param cap the capacitor value + */ +static inline void touch_ll_set_internal_capacitor(uint32_t cap) +{ + TOUCH_AON.aon_ana_para.aon_touch_touch_dcap_cal = cap; +} + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_hal_touch_sens/esp32h4/touch_sensor_periph.c b/components/esp_hal_touch_sens/esp32h4/touch_sensor_periph.c new file mode 100644 index 0000000000..1641bc5e35 --- /dev/null +++ b/components/esp_hal_touch_sens/esp32h4/touch_sensor_periph.c @@ -0,0 +1,26 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "hal/touch_sensor_channel.h" + +/* Store IO number corresponding to the Touch Sensor channel number. */ +const int touch_sensor_channel_io_map[] = { + TOUCH_PAD_NUM0_GPIO_NUM, + TOUCH_PAD_NUM1_GPIO_NUM, + TOUCH_PAD_NUM2_GPIO_NUM, + TOUCH_PAD_NUM3_GPIO_NUM, + TOUCH_PAD_NUM4_GPIO_NUM, + TOUCH_PAD_NUM5_GPIO_NUM, + TOUCH_PAD_NUM6_GPIO_NUM, + TOUCH_PAD_NUM7_GPIO_NUM, + TOUCH_PAD_NUM8_GPIO_NUM, + TOUCH_PAD_NUM9_GPIO_NUM, + TOUCH_PAD_NUM10_GPIO_NUM, + TOUCH_PAD_NUM11_GPIO_NUM, + TOUCH_PAD_NUM12_GPIO_NUM, + TOUCH_PAD_NUM13_GPIO_NUM, + TOUCH_PAD_NUM14_GPIO_NUM, +}; diff --git a/components/soc/esp32p4/include/soc/touch_sensor_channel.h b/components/esp_hal_touch_sens/esp32p4/include/hal/touch_sensor_channel.h similarity index 96% rename from components/soc/esp32p4/include/soc/touch_sensor_channel.h rename to components/esp_hal_touch_sens/esp32p4/include/hal/touch_sensor_channel.h index cb31d25acf..ff009b31ed 100644 --- a/components/soc/esp32p4/include/soc/touch_sensor_channel.h +++ b/components/esp_hal_touch_sens/esp32p4/include/hal/touch_sensor_channel.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #pragma once diff --git a/components/esp_hal_touch_sens/esp32p4/include/hal/touch_sensor_ll.h b/components/esp_hal_touch_sens/esp32p4/include/hal/touch_sensor_ll.h index 2f462cb6ec..5f8038fda5 100644 --- a/components/esp_hal_touch_sens/esp32p4/include/hal/touch_sensor_ll.h +++ b/components/esp_hal_touch_sens/esp32p4/include/hal/touch_sensor_ll.h @@ -60,6 +60,8 @@ extern "C" { #define TOUCH_LL_SUPPORT_PROX_DONE (1) +#define TOUCH_LL_INTR_SOURCE ETS_LP_TOUCH_INTR_SOURCE // Touch sensor interrupt source, defined in ll for the driver compatibility + /** * Enable/disable clock gate of touch sensor. * diff --git a/components/esp_hal_touch_sens/esp32p4/touch_sensor_periph.c b/components/esp_hal_touch_sens/esp32p4/touch_sensor_periph.c index 0bf598389a..214421fdf3 100644 --- a/components/esp_hal_touch_sens/esp32p4/touch_sensor_periph.c +++ b/components/esp_hal_touch_sens/esp32p4/touch_sensor_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/touch_sensor_channel.h" +#include "hal/touch_sensor_channel.h" /* Store IO number corresponding to the Touch Sensor channel number. */ /* Note: T0 is an internal channel that does not have a corresponding external GPIO. */ diff --git a/components/soc/esp32s2/include/soc/touch_sensor_channel.h b/components/esp_hal_touch_sens/esp32s2/include/hal/touch_sensor_channel.h similarity index 96% rename from components/soc/esp32s2/include/soc/touch_sensor_channel.h rename to components/esp_hal_touch_sens/esp32s2/include/hal/touch_sensor_channel.h index 4a1b1d2c7b..61197c92c4 100644 --- a/components/soc/esp32s2/include/soc/touch_sensor_channel.h +++ b/components/esp_hal_touch_sens/esp32s2/include/hal/touch_sensor_channel.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #ifndef _SOC_TOUCH_CHANNEL_H diff --git a/components/esp_hal_touch_sens/esp32s2/touch_sensor_periph.c b/components/esp_hal_touch_sens/esp32s2/touch_sensor_periph.c index dc02e62ba6..23c2f5067a 100644 --- a/components/esp_hal_touch_sens/esp32s2/touch_sensor_periph.c +++ b/components/esp_hal_touch_sens/esp32s2/touch_sensor_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/touch_sensor_channel.h" +#include "hal/touch_sensor_channel.h" /* Store IO number corresponding to the Touch Sensor channel number. */ /* Note: T0 is an internal channel that does not have a corresponding external GPIO. */ diff --git a/components/soc/esp32s3/include/soc/touch_sensor_channel.h b/components/esp_hal_touch_sens/esp32s3/include/hal/touch_sensor_channel.h similarity index 96% rename from components/soc/esp32s3/include/soc/touch_sensor_channel.h rename to components/esp_hal_touch_sens/esp32s3/include/hal/touch_sensor_channel.h index 3879a72100..88d58d66b9 100644 --- a/components/soc/esp32s3/include/soc/touch_sensor_channel.h +++ b/components/esp_hal_touch_sens/esp32s3/include/hal/touch_sensor_channel.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #pragma once diff --git a/components/esp_hal_touch_sens/esp32s3/touch_sensor_periph.c b/components/esp_hal_touch_sens/esp32s3/touch_sensor_periph.c index dc02e62ba6..23c2f5067a 100644 --- a/components/esp_hal_touch_sens/esp32s3/touch_sensor_periph.c +++ b/components/esp_hal_touch_sens/esp32s3/touch_sensor_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/touch_sensor_channel.h" +#include "hal/touch_sensor_channel.h" /* Store IO number corresponding to the Touch Sensor channel number. */ /* Note: T0 is an internal channel that does not have a corresponding external GPIO. */ diff --git a/components/esp_hal_touch_sens/touch_sens_hal.c b/components/esp_hal_touch_sens/touch_sens_hal.c index 54b7572919..1cf228c729 100644 --- a/components/esp_hal_touch_sens/touch_sens_hal.c +++ b/components/esp_hal_touch_sens/touch_sens_hal.c @@ -107,7 +107,7 @@ static void s_touch_hal_apply_sleep_config(void) } else { /* If not allow power down but sleep channel is set, then only enable this channel during the deep sleep */ touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL); - touch_ll_enable_channel_mask(BIT(s_touch_slp_obj.deep_slp_chan)); + touch_ll_enable_channel_mask(1UL << (s_touch_slp_obj.deep_slp_chan)); } } else { touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL); diff --git a/components/esp_hw_support/port/esp32h4/private_include/pmu_bit_defs.h b/components/esp_hw_support/port/esp32h4/private_include/pmu_bit_defs.h index c456a178c6..613190e412 100644 --- a/components/esp_hw_support/port/esp32h4/private_include/pmu_bit_defs.h +++ b/components/esp_hw_support/port/esp32h4/private_include/pmu_bit_defs.h @@ -16,6 +16,7 @@ extern "C" { #define PMU_LP_TIMER_WAKEUP_EN BIT(4) #define PMU_UART0_WAKEUP_EN BIT(6) #define PMU_UART1_WAKEUP_EN BIT(7) +#define PMU_TOUCH_WAKEUP_EN BIT(9) #define PMU_BLE_SOC_WAKEUP_EN BIT(10) #define PMU_USB_WAKEUP_EN BIT(14) diff --git a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in index 72fa57bb3f..1b59a214ca 100644 --- a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in @@ -139,6 +139,10 @@ config SOC_LP_AON_SUPPORTED bool default y +config SOC_TOUCH_SENSOR_SUPPORTED + bool + default y + config SOC_REG_I2C_SUPPORTED bool default y @@ -1039,6 +1043,42 @@ config SOC_RCC_IS_INDEPENDENT bool default y +config SOC_TOUCH_SENSOR_VERSION + int + default 3 + +config SOC_TOUCH_MIN_CHAN_ID + int + default 0 + +config SOC_TOUCH_MAX_CHAN_ID + int + default 14 + +config SOC_TOUCH_SUPPORT_SLEEP_WAKEUP + bool + default y + +config SOC_TOUCH_SUPPORT_BENCHMARK + bool + default y + +config SOC_TOUCH_SUPPORT_WATERPROOF + bool + default y + +config SOC_TOUCH_SUPPORT_PROX_SENSING + bool + default y + +config SOC_TOUCH_PROXIMITY_CHANNEL_NUM + int + default 3 + +config SOC_TOUCH_SAMPLE_CFG_NUM + int + default 3 + config SOC_USB_OTG_PERIPH_NUM int default 1 diff --git a/components/soc/esp32h4/include/soc/soc_caps.h b/components/soc/esp32h4/include/soc/soc_caps.h index 61e2b3baaa..7ef8aa428c 100644 --- a/components/soc/esp32h4/include/soc/soc_caps.h +++ b/components/soc/esp32h4/include/soc/soc_caps.h @@ -81,6 +81,7 @@ #define SOC_PAU_SUPPORTED 1 #define SOC_LP_TIMER_SUPPORTED 1 #define SOC_LP_AON_SUPPORTED 1 +#define SOC_TOUCH_SENSOR_SUPPORTED 1 // #define SOC_LP_PERIPHERALS_SUPPORTED 1 // #define SOC_LP_I2C_SUPPORTED 1 // TODO: [ESP32H4] IDF-12449 // #define SOC_ULP_LP_UART_SUPPORTED 1 // TODO: [ESP32H4] IDF-12445 IDF-12451 @@ -536,6 +537,19 @@ // #define SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL (1) // #define SOC_TEMPERATURE_SENSOR_INTR_SUPPORT (1) +/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/ +#define SOC_TOUCH_SENSOR_VERSION (3) /*!< Hardware version of touch sensor */ +#define SOC_TOUCH_MIN_CHAN_ID (0U) /*!< Touch minimum channel number */ +#define SOC_TOUCH_MAX_CHAN_ID (14) /*!< Touch maximum channel number */ + +/* Touch Sensor Features */ +#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */ +#define SOC_TOUCH_SUPPORT_BENCHMARK (1) /*!< Touch sensor supports benchmark configuration */ +#define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */ +#define SOC_TOUCH_SUPPORT_PROX_SENSING (1) /*!< Touch sensor supports proximity sensing */ +#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /*!< Support touch proximity channel number. */ +#define SOC_TOUCH_SAMPLE_CFG_NUM (3) /*!< The sample configurations number in total, each sampler can be used to sample on one frequency */ + /*---------------------------------- Bluetooth CAPS ----------------------------------*/ // #define SOC_BLE_SUPPORTED (1) /*!< Support Bluetooth Low Energy hardware */ // #define SOC_BLE_MESH_SUPPORTED (1) /*!< Support BLE MESH */ diff --git a/components/soc/esp32h4/register/soc/touch_aon_struct.h b/components/soc/esp32h4/register/soc/touch_aon_struct.h index 56fd2e7c3d..b34b47a90a 100644 --- a/components/soc/esp32h4/register/soc/touch_aon_struct.h +++ b/components/soc/esp32h4/register/soc/touch_aon_struct.h @@ -339,102 +339,34 @@ typedef union { */ typedef union { struct { - /** aon_touch_freq0_dcap_lpf : R/W; bitpos: [6:0]; default: 0; + /** aon_touch_freq_dcap_lpf : R/W; bitpos: [6:0]; default: 0; * need_des */ - uint32_t aon_touch_freq0_dcap_lpf:7; - /** aon_touch_freq0_dres_lpf : R/W; bitpos: [8:7]; default: 0; + uint32_t aon_touch_freq_dcap_lpf:7; + /** aon_touch_freq_dres_lpf : R/W; bitpos: [8:7]; default: 0; * need_des */ - uint32_t aon_touch_freq0_dres_lpf:2; - /** aon_touch_freq0_drv_ls : R/W; bitpos: [12:9]; default: 0; + uint32_t aon_touch_freq_dres_lpf:2; + /** aon_touch_freq_drv_ls : R/W; bitpos: [12:9]; default: 0; * need_des */ - uint32_t aon_touch_freq0_drv_ls:4; - /** aon_touch_freq0_drv_hs : R/W; bitpos: [17:13]; default: 0; + uint32_t aon_touch_freq_drv_ls:4; + /** aon_touch_freq_drv_hs : R/W; bitpos: [17:13]; default: 0; * need_des */ - uint32_t aon_touch_freq0_drv_hs:5; - /** aon_touch_freq0_dbias : R/W; bitpos: [22:18]; default: 0; + uint32_t aon_touch_freq_drv_hs:5; + /** aon_touch_freq_dbias : R/W; bitpos: [22:18]; default: 0; * need_des */ - uint32_t aon_touch_freq0_dbias:5; - /** aon_touch_freq0_buf_sel_en : R/W; bitpos: [23]; default: 1; + uint32_t aon_touch_freq_dbias:5; + /** aon_touch_freq_buf_sel_en : R/W; bitpos: [23]; default: 1; * need_des */ - uint32_t aon_touch_freq0_buf_sel_en:1; + uint32_t aon_touch_freq_buf_sel_en:1; uint32_t reserved_24:8; }; uint32_t val; -} touch_aon_freq0_scan_para_reg_t; - -/** Type of aon_freq1_scan_para register - * need_des - */ -typedef union { - struct { - /** aon_touch_freq1_dcap_lpf : R/W; bitpos: [6:0]; default: 0; - * need_des - */ - uint32_t aon_touch_freq1_dcap_lpf:7; - /** aon_touch_freq1_dres_lpf : R/W; bitpos: [8:7]; default: 0; - * need_des - */ - uint32_t aon_touch_freq1_dres_lpf:2; - /** aon_touch_freq1_drv_ls : R/W; bitpos: [12:9]; default: 0; - * need_des - */ - uint32_t aon_touch_freq1_drv_ls:4; - /** aon_touch_freq1_drv_hs : R/W; bitpos: [17:13]; default: 0; - * need_des - */ - uint32_t aon_touch_freq1_drv_hs:5; - /** aon_touch_freq1_dbias : R/W; bitpos: [22:18]; default: 0; - * need_des - */ - uint32_t aon_touch_freq1_dbias:5; - /** aon_touch_freq1_buf_sel_en : R/W; bitpos: [23]; default: 1; - * need_des - */ - uint32_t aon_touch_freq1_buf_sel_en:1; - uint32_t reserved_24:8; - }; - uint32_t val; -} touch_aon_freq1_scan_para_reg_t; - -/** Type of aon_freq2_scan_para register - * need_des - */ -typedef union { - struct { - /** aon_touch_freq2_dcap_lpf : R/W; bitpos: [6:0]; default: 0; - * need_des - */ - uint32_t aon_touch_freq2_dcap_lpf:7; - /** aon_touch_freq2_dres_lpf : R/W; bitpos: [8:7]; default: 0; - * need_des - */ - uint32_t aon_touch_freq2_dres_lpf:2; - /** aon_touch_freq2_drv_ls : R/W; bitpos: [12:9]; default: 0; - * need_des - */ - uint32_t aon_touch_freq2_drv_ls:4; - /** aon_touch_freq2_drv_hs : R/W; bitpos: [17:13]; default: 0; - * need_des - */ - uint32_t aon_touch_freq2_drv_hs:5; - /** aon_touch_freq2_dbias : R/W; bitpos: [22:18]; default: 0; - * need_des - */ - uint32_t aon_touch_freq2_dbias:5; - /** aon_touch_freq2_buf_sel_en : R/W; bitpos: [23]; default: 1; - * need_des - */ - uint32_t aon_touch_freq2_buf_sel_en:1; - uint32_t reserved_24:8; - }; - uint32_t val; -} touch_aon_freq2_scan_para_reg_t; +} touch_aon_freq_scan_para_reg_t; /** Type of aon_ana_para register * need_des @@ -518,635 +450,19 @@ typedef union { uint32_t val; } touch_aon_mux1_reg_t; -/** Type of aon_pad0_th0 register +/** Type of threshold register * need_des */ typedef union { struct { uint32_t reserved_0:16; - /** aon_touch_pad0_th0 : R/W; bitpos: [31:16]; default: 0; + /** threshold : R/W; bitpos: [31:16]; default: 0; * Reserved */ - uint32_t aon_touch_pad0_th0:16; + uint32_t threshold:16; }; uint32_t val; -} touch_aon_pad0_th0_reg_t; - -/** Type of aon_pad0_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad0_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad0_th1:16; - }; - uint32_t val; -} touch_aon_pad0_th1_reg_t; - -/** Type of aon_pad0_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad0_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad0_th2:16; - }; - uint32_t val; -} touch_aon_pad0_th2_reg_t; - -/** Type of aon_pad1_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad1_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad1_th0:16; - }; - uint32_t val; -} touch_aon_pad1_th0_reg_t; - -/** Type of aon_pad1_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad1_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad1_th1:16; - }; - uint32_t val; -} touch_aon_pad1_th1_reg_t; - -/** Type of aon_pad1_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad1_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad1_th2:16; - }; - uint32_t val; -} touch_aon_pad1_th2_reg_t; - -/** Type of aon_pad2_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad2_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad2_th0:16; - }; - uint32_t val; -} touch_aon_pad2_th0_reg_t; - -/** Type of aon_pad2_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad2_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad2_th1:16; - }; - uint32_t val; -} touch_aon_pad2_th1_reg_t; - -/** Type of aon_pad2_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad2_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad2_th2:16; - }; - uint32_t val; -} touch_aon_pad2_th2_reg_t; - -/** Type of aon_pad3_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad3_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad3_th0:16; - }; - uint32_t val; -} touch_aon_pad3_th0_reg_t; - -/** Type of aon_pad3_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad3_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad3_th1:16; - }; - uint32_t val; -} touch_aon_pad3_th1_reg_t; - -/** Type of aon_pad3_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad3_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad3_th2:16; - }; - uint32_t val; -} touch_aon_pad3_th2_reg_t; - -/** Type of aon_pad4_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad4_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad4_th0:16; - }; - uint32_t val; -} touch_aon_pad4_th0_reg_t; - -/** Type of aon_pad4_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad4_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad4_th1:16; - }; - uint32_t val; -} touch_aon_pad4_th1_reg_t; - -/** Type of aon_pad4_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad4_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad4_th2:16; - }; - uint32_t val; -} touch_aon_pad4_th2_reg_t; - -/** Type of aon_pad5_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad5_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad5_th0:16; - }; - uint32_t val; -} touch_aon_pad5_th0_reg_t; - -/** Type of aon_pad5_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad5_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad5_th1:16; - }; - uint32_t val; -} touch_aon_pad5_th1_reg_t; - -/** Type of aon_pad5_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad5_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad5_th2:16; - }; - uint32_t val; -} touch_aon_pad5_th2_reg_t; - -/** Type of aon_pad6_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad6_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad6_th0:16; - }; - uint32_t val; -} touch_aon_pad6_th0_reg_t; - -/** Type of aon_pad6_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad6_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad6_th1:16; - }; - uint32_t val; -} touch_aon_pad6_th1_reg_t; - -/** Type of aon_pad6_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad6_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad6_th2:16; - }; - uint32_t val; -} touch_aon_pad6_th2_reg_t; - -/** Type of aon_pad7_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad7_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad7_th0:16; - }; - uint32_t val; -} touch_aon_pad7_th0_reg_t; - -/** Type of aon_pad7_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad7_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad7_th1:16; - }; - uint32_t val; -} touch_aon_pad7_th1_reg_t; - -/** Type of aon_pad7_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad7_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad7_th2:16; - }; - uint32_t val; -} touch_aon_pad7_th2_reg_t; - -/** Type of aon_pad8_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad8_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad8_th0:16; - }; - uint32_t val; -} touch_aon_pad8_th0_reg_t; - -/** Type of aon_pad8_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad8_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad8_th1:16; - }; - uint32_t val; -} touch_aon_pad8_th1_reg_t; - -/** Type of aon_pad8_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad8_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad8_th2:16; - }; - uint32_t val; -} touch_aon_pad8_th2_reg_t; - -/** Type of aon_pad9_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad9_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad9_th0:16; - }; - uint32_t val; -} touch_aon_pad9_th0_reg_t; - -/** Type of aon_pad9_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad9_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad9_th1:16; - }; - uint32_t val; -} touch_aon_pad9_th1_reg_t; - -/** Type of aon_pad9_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad9_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad9_th2:16; - }; - uint32_t val; -} touch_aon_pad9_th2_reg_t; - -/** Type of aon_pad10_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad10_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad10_th0:16; - }; - uint32_t val; -} touch_aon_pad10_th0_reg_t; - -/** Type of aon_pad10_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad10_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad10_th1:16; - }; - uint32_t val; -} touch_aon_pad10_th1_reg_t; - -/** Type of aon_pad10_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad10_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad10_th2:16; - }; - uint32_t val; -} touch_aon_pad10_th2_reg_t; - -/** Type of aon_pad11_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad11_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad11_th0:16; - }; - uint32_t val; -} touch_aon_pad11_th0_reg_t; - -/** Type of aon_pad11_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad11_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad11_th1:16; - }; - uint32_t val; -} touch_aon_pad11_th1_reg_t; - -/** Type of aon_pad11_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad11_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad11_th2:16; - }; - uint32_t val; -} touch_aon_pad11_th2_reg_t; - -/** Type of aon_pad12_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad12_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad12_th0:16; - }; - uint32_t val; -} touch_aon_pad12_th0_reg_t; - -/** Type of aon_pad12_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad12_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad12_th1:16; - }; - uint32_t val; -} touch_aon_pad12_th1_reg_t; - -/** Type of aon_pad12_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad12_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad12_th2:16; - }; - uint32_t val; -} touch_aon_pad12_th2_reg_t; - -/** Type of aon_pad13_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad13_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad13_th0:16; - }; - uint32_t val; -} touch_aon_pad13_th0_reg_t; - -/** Type of aon_pad13_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad13_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad13_th1:16; - }; - uint32_t val; -} touch_aon_pad13_th1_reg_t; - -/** Type of aon_pad13_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad13_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad13_th2:16; - }; - uint32_t val; -} touch_aon_pad13_th2_reg_t; - -/** Type of aon_pad14_th0 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad14_th0 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad14_th0:16; - }; - uint32_t val; -} touch_aon_pad14_th0_reg_t; - -/** Type of aon_pad14_th1 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad14_th1 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad14_th1:16; - }; - uint32_t val; -} touch_aon_pad14_th1_reg_t; - -/** Type of aon_pad14_th2 register - * need_des - */ -typedef union { - struct { - uint32_t reserved_0:16; - /** aon_touch_pad14_th2 : R/W; bitpos: [31:16]; default: 0; - * Reserved - */ - uint32_t aon_touch_pad14_th2:16; - }; - uint32_t val; -} touch_aon_pad14_th2_reg_t; +} touch_aon_threshold_reg_t; /** Type of aon_date register * need_des @@ -1166,6 +482,10 @@ typedef union { } touch_aon_date_reg_t; +typedef struct { + volatile touch_aon_threshold_reg_t thresh[3]; +} touch_aon_pad_thresh_reg_t; + typedef struct { volatile touch_aon_approach_work_meas_num_reg_t aon_approach_work_meas_num; volatile touch_aon_scan_ctrl1_reg_t aon_scan_ctrl1; @@ -1179,57 +499,11 @@ typedef struct { volatile touch_aon_slp1_reg_t aon_slp1; volatile touch_aon_clr_reg_t aon_clr; volatile touch_aon_approach_reg_t aon_approach; - volatile touch_aon_freq0_scan_para_reg_t aon_freq0_scan_para; - volatile touch_aon_freq1_scan_para_reg_t aon_freq1_scan_para; - volatile touch_aon_freq2_scan_para_reg_t aon_freq2_scan_para; + volatile touch_aon_freq_scan_para_reg_t aon_freq_scan_para[3]; volatile touch_aon_ana_para_reg_t aon_ana_para; volatile touch_aon_mux0_reg_t aon_mux0; volatile touch_aon_mux1_reg_t aon_mux1; - volatile touch_aon_pad0_th0_reg_t aon_pad0_th0; - volatile touch_aon_pad0_th1_reg_t aon_pad0_th1; - volatile touch_aon_pad0_th2_reg_t aon_pad0_th2; - volatile touch_aon_pad1_th0_reg_t aon_pad1_th0; - volatile touch_aon_pad1_th1_reg_t aon_pad1_th1; - volatile touch_aon_pad1_th2_reg_t aon_pad1_th2; - volatile touch_aon_pad2_th0_reg_t aon_pad2_th0; - volatile touch_aon_pad2_th1_reg_t aon_pad2_th1; - volatile touch_aon_pad2_th2_reg_t aon_pad2_th2; - volatile touch_aon_pad3_th0_reg_t aon_pad3_th0; - volatile touch_aon_pad3_th1_reg_t aon_pad3_th1; - volatile touch_aon_pad3_th2_reg_t aon_pad3_th2; - volatile touch_aon_pad4_th0_reg_t aon_pad4_th0; - volatile touch_aon_pad4_th1_reg_t aon_pad4_th1; - volatile touch_aon_pad4_th2_reg_t aon_pad4_th2; - volatile touch_aon_pad5_th0_reg_t aon_pad5_th0; - volatile touch_aon_pad5_th1_reg_t aon_pad5_th1; - volatile touch_aon_pad5_th2_reg_t aon_pad5_th2; - volatile touch_aon_pad6_th0_reg_t aon_pad6_th0; - volatile touch_aon_pad6_th1_reg_t aon_pad6_th1; - volatile touch_aon_pad6_th2_reg_t aon_pad6_th2; - volatile touch_aon_pad7_th0_reg_t aon_pad7_th0; - volatile touch_aon_pad7_th1_reg_t aon_pad7_th1; - volatile touch_aon_pad7_th2_reg_t aon_pad7_th2; - volatile touch_aon_pad8_th0_reg_t aon_pad8_th0; - volatile touch_aon_pad8_th1_reg_t aon_pad8_th1; - volatile touch_aon_pad8_th2_reg_t aon_pad8_th2; - volatile touch_aon_pad9_th0_reg_t aon_pad9_th0; - volatile touch_aon_pad9_th1_reg_t aon_pad9_th1; - volatile touch_aon_pad9_th2_reg_t aon_pad9_th2; - volatile touch_aon_pad10_th0_reg_t aon_pad10_th0; - volatile touch_aon_pad10_th1_reg_t aon_pad10_th1; - volatile touch_aon_pad10_th2_reg_t aon_pad10_th2; - volatile touch_aon_pad11_th0_reg_t aon_pad11_th0; - volatile touch_aon_pad11_th1_reg_t aon_pad11_th1; - volatile touch_aon_pad11_th2_reg_t aon_pad11_th2; - volatile touch_aon_pad12_th0_reg_t aon_pad12_th0; - volatile touch_aon_pad12_th1_reg_t aon_pad12_th1; - volatile touch_aon_pad12_th2_reg_t aon_pad12_th2; - volatile touch_aon_pad13_th0_reg_t aon_pad13_th0; - volatile touch_aon_pad13_th1_reg_t aon_pad13_th1; - volatile touch_aon_pad13_th2_reg_t aon_pad13_th2; - volatile touch_aon_pad14_th0_reg_t aon_pad14_th0; - volatile touch_aon_pad14_th1_reg_t aon_pad14_th1; - volatile touch_aon_pad14_th2_reg_t aon_pad14_th2; + volatile touch_aon_pad_thresh_reg_t aon_padx_thn[15]; volatile touch_aon_date_reg_t aon_date; } touch_aon_dev_t; diff --git a/components/soc/esp32h4/register/soc/touch_struct.h b/components/soc/esp32h4/register/soc/touch_struct.h index 57dc78e5ef..cb930def89 100644 --- a/components/soc/esp32h4/register/soc/touch_struct.h +++ b/components/soc/esp32h4/register/soc/touch_struct.h @@ -40,10 +40,10 @@ typedef union { * need_des */ uint32_t approach_loop_done_int_raw:1; - /** baseline_update_int_raw : R/WTC/SS; bitpos: [6]; default: 0; + /** benchmark_update_int_raw : R/WTC/SS; bitpos: [6]; default: 0; * need_des */ - uint32_t baseline_update_int_raw:1; + uint32_t benchmark_update_int_raw:1; uint32_t reserved_7:25; }; uint32_t val; @@ -78,10 +78,10 @@ typedef union { * need_des */ uint32_t approach_loop_done_int_st:1; - /** baseline_update_int_st : RO; bitpos: [6]; default: 0; + /** benchmark_update_int_st : RO; bitpos: [6]; default: 0; * need_des */ - uint32_t baseline_update_int_st:1; + uint32_t benchmark_update_int_st:1; uint32_t reserved_7:25; }; uint32_t val; @@ -116,10 +116,10 @@ typedef union { * need_des */ uint32_t approach_loop_done_int_ena:1; - /** baseline_update_int_ena : R/W; bitpos: [6]; default: 0; + /** benchmark_update_int_ena : R/W; bitpos: [6]; default: 0; * need_des */ - uint32_t baseline_update_int_ena:1; + uint32_t benchmark_update_int_ena:1; uint32_t reserved_7:25; }; uint32_t val; @@ -154,10 +154,10 @@ typedef union { * need_des */ uint32_t approach_loop_done_int_clr:1; - /** baseline_update_int_clr : WT; bitpos: [6]; default: 0; + /** benchmark_update_int_clr : WT; bitpos: [6]; default: 0; * need_des */ - uint32_t baseline_update_int_clr:1; + uint32_t benchmark_update_int_clr:1; uint32_t reserved_7:25; }; uint32_t val; @@ -185,342 +185,34 @@ typedef union { uint32_t val; } touch_chn_status_reg_t; -/** Type of status_0 register +/** Type of chn_data register * need_des */ typedef union { struct { - /** pad0_data : RO; bitpos: [15:0]; default: 0; + /** pad_data : RO; bitpos: [15:0]; default: 0; * need_des */ - uint32_t pad0_data:16; - /** pad0_debounce_cnt : RO; bitpos: [18:16]; default: 0; + uint32_t pad_data:16; + /** pad_debounce_cnt : RO; bitpos: [18:16]; default: 0; * need_des */ - uint32_t pad0_debounce_cnt:3; - /** pad0_nn_cnt : RO; bitpos: [22:19]; default: 0; + uint32_t pad_debounce_cnt:3; + /** pad_neg_noise_cnt : RO; bitpos: [22:19]; default: 0; * need_des */ - uint32_t pad0_nn_cnt:4; + uint32_t pad_neg_noise_cnt:4; uint32_t reserved_23:9; }; uint32_t val; -} touch_status_0_reg_t; +} touch_chn_data_reg_t; -/** Type of status_1 register +/** Type of slp_ch_data register * need_des */ typedef union { struct { - /** pad1_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad1_data:16; - /** pad1_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad1_debounce_cnt:3; - /** pad1_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad1_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_1_reg_t; - -/** Type of status_2 register - * need_des - */ -typedef union { - struct { - /** pad2_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad2_data:16; - /** pad2_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad2_debounce_cnt:3; - /** pad2_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad2_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_2_reg_t; - -/** Type of status_3 register - * need_des - */ -typedef union { - struct { - /** pad3_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad3_data:16; - /** pad3_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad3_debounce_cnt:3; - /** pad3_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad3_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_3_reg_t; - -/** Type of status_4 register - * need_des - */ -typedef union { - struct { - /** pad4_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad4_data:16; - /** pad4_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad4_debounce_cnt:3; - /** pad4_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad4_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_4_reg_t; - -/** Type of status_5 register - * need_des - */ -typedef union { - struct { - /** pad5_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad5_data:16; - /** pad5_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad5_debounce_cnt:3; - /** pad5_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad5_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_5_reg_t; - -/** Type of status_6 register - * need_des - */ -typedef union { - struct { - /** pad6_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad6_data:16; - /** pad6_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad6_debounce_cnt:3; - /** pad6_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad6_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_6_reg_t; - -/** Type of status_7 register - * need_des - */ -typedef union { - struct { - /** pad7_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad7_data:16; - /** pad7_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad7_debounce_cnt:3; - /** pad7_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad7_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_7_reg_t; - -/** Type of status_8 register - * need_des - */ -typedef union { - struct { - /** pad8_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad8_data:16; - /** pad8_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad8_debounce_cnt:3; - /** pad8_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad8_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_8_reg_t; - -/** Type of status_9 register - * need_des - */ -typedef union { - struct { - /** pad9_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad9_data:16; - /** pad9_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad9_debounce_cnt:3; - /** pad9_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad9_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_9_reg_t; - -/** Type of status_10 register - * need_des - */ -typedef union { - struct { - /** pad10_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad10_data:16; - /** pad10_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad10_debounce_cnt:3; - /** pad10_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad10_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_10_reg_t; - -/** Type of status_11 register - * need_des - */ -typedef union { - struct { - /** pad11_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad11_data:16; - /** pad11_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad11_debounce_cnt:3; - /** pad11_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad11_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_11_reg_t; - -/** Type of status_12 register - * need_des - */ -typedef union { - struct { - /** pad12_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad12_data:16; - /** pad12_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad12_debounce_cnt:3; - /** pad12_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad12_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_12_reg_t; - -/** Type of status_13 register - * need_des - */ -typedef union { - struct { - /** pad13_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad13_data:16; - /** pad13_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad13_debounce_cnt:3; - /** pad13_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad13_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_13_reg_t; - -/** Type of status_14 register - * need_des - */ -typedef union { - struct { - /** pad14_data : RO; bitpos: [15:0]; default: 0; - * need_des - */ - uint32_t pad14_data:16; - /** pad14_debounce_cnt : RO; bitpos: [18:16]; default: 0; - * need_des - */ - uint32_t pad14_debounce_cnt:3; - /** pad14_nn_cnt : RO; bitpos: [22:19]; default: 0; - * need_des - */ - uint32_t pad14_nn_cnt:4; - uint32_t reserved_23:9; - }; - uint32_t val; -} touch_status_14_reg_t; - -/** Type of status_15 register - * need_des - */ -typedef union { - struct { - /** slp_data : RO; bitpos: [15:0]; default: 65535; + /** slp_data : RO; bitpos: [15:0]; default: 0; * need_des */ uint32_t slp_data:16; @@ -528,16 +220,16 @@ typedef union { * need_des */ uint32_t slp_debounce_cnt:3; - /** slp_nn_cnt : RO; bitpos: [22:19]; default: 0; + /** slp_neg_noise_cnt : RO; bitpos: [22:19]; default: 0; * need_des */ - uint32_t slp_nn_cnt:4; + uint32_t slp_neg_noise_cnt:4; uint32_t reserved_23:9; }; uint32_t val; -} touch_status_15_reg_t; +} touch_slp_ch_data_reg_t; -/** Type of status_16 register +/** Type of aprch_ch_data register * need_des */ typedef union { @@ -560,9 +252,9 @@ typedef union { uint32_t slp_approach_cnt:8; }; uint32_t val; -} touch_status_16_reg_t; +} touch_aprch_ch_data_reg_t; -/** Type of status_17 register +/** Type of config register * need_des */ typedef union { @@ -594,7 +286,7 @@ typedef union { uint32_t reserved_25:7; }; uint32_t val; -} touch_status_17_reg_t; +} touch_sample_status_reg_t; /** Type of chn_tmp_status register * need_des @@ -637,24 +329,10 @@ typedef struct { volatile touch_int_ena_reg_t int_ena; volatile touch_int_clr_reg_t int_clr; volatile touch_chn_status_reg_t chn_status; - volatile touch_status_0_reg_t status_0; - volatile touch_status_1_reg_t status_1; - volatile touch_status_2_reg_t status_2; - volatile touch_status_3_reg_t status_3; - volatile touch_status_4_reg_t status_4; - volatile touch_status_5_reg_t status_5; - volatile touch_status_6_reg_t status_6; - volatile touch_status_7_reg_t status_7; - volatile touch_status_8_reg_t status_8; - volatile touch_status_9_reg_t status_9; - volatile touch_status_10_reg_t status_10; - volatile touch_status_11_reg_t status_11; - volatile touch_status_12_reg_t status_12; - volatile touch_status_13_reg_t status_13; - volatile touch_status_14_reg_t status_14; - volatile touch_status_15_reg_t status_15; - volatile touch_status_16_reg_t status_16; - volatile touch_status_17_reg_t status_17; + volatile touch_chn_data_reg_t chn_data[15]; + volatile touch_slp_ch_data_reg_t slp_ch_data; + volatile touch_aprch_ch_data_reg_t aprch_ch_data; + volatile touch_sample_status_reg_t sample_status; volatile touch_chn_tmp_status_reg_t chn_tmp_status; uint32_t reserved_060[40]; volatile touch_date_reg_t date; diff --git a/docs/docs_not_updated/esp32h4.txt b/docs/docs_not_updated/esp32h4.txt index 0478270ca8..c126ff0da4 100644 --- a/docs/docs_not_updated/esp32h4.txt +++ b/docs/docs_not_updated/esp32h4.txt @@ -118,7 +118,6 @@ api-reference/bluetooth/esp_gap_bt.rst api-reference/bluetooth/classic_bt.rst api-reference/bluetooth/esp_a2dp.rst api-reference/bluetooth/esp_hf_defs.rst -api-reference/peripherals/cap_touch_sens.rst api-reference/peripherals/index.rst api-reference/peripherals/sdio_slave.rst api-reference/peripherals/temp_sensor.rst diff --git a/docs/doxygen/Doxyfile_esp32h4 b/docs/doxygen/Doxyfile_esp32h4 index 9ece8d2c72..e3083020b6 100644 --- a/docs/doxygen/Doxyfile_esp32h4 +++ b/docs/doxygen/Doxyfile_esp32h4 @@ -1,3 +1,6 @@ INPUT += \ $(PROJECT_PATH)/components/esp_phy/include/esp_phy_init.h \ $(PROJECT_PATH)/components/esp_phy/include/esp_phy_cert_test.h \ + $(PROJECT_PATH)/components/esp_driver_touch_sens/hw_ver3/include/driver/touch_version_types.h \ + $(PROJECT_PATH)/components/esp_driver_touch_sens/include/driver/touch_sens.h \ + $(PROJECT_PATH)/components/esp_driver_touch_sens/include/driver/touch_sens_types.h \ diff --git a/docs/en/api-reference/peripherals/cap_touch_sens.rst b/docs/en/api-reference/peripherals/cap_touch_sens.rst index f02035597c..9cfdd6d327 100644 --- a/docs/en/api-reference/peripherals/cap_touch_sens.rst +++ b/docs/en/api-reference/peripherals/cap_touch_sens.rst @@ -3,7 +3,7 @@ Capacitive Touch Sensor :link_to_translation:`zh_CN:[中文]` -{IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32="v1", esp32s2="v2", esp32s3="v2", esp32p4="v3"} +{IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32="v1", esp32s2="v2", esp32s3="v2", esp32p4="v3", esp32h4="v3"} Introduction --------------- @@ -30,6 +30,7 @@ Overview of Capacitive Touch Sensor Versions | | ESP32-S3 | Version 2, support proximity measurement done interrupt | +------------------+-----------+---------------------------------------------------------------------------------------+ | V3 | ESP32-P4 | Version 3, support frequency hopping | +| | ESP32-H4 | | +------------------+-----------+---------------------------------------------------------------------------------------+ Measurement Principle @@ -72,11 +73,11 @@ Terminology in the Driver - **Touch Sensor Controller**: The controller of the touch sensor, responsible for configuring and managing the touch sensor. - **Touch Sensor Channel**: A specific touch sensor sampling channel. A touch sensor module has multiple touch channels, which are usually connected to the touch pad for measuring the capacitance change. In the driver, sampling of **one** channel is called one ``measurement`` and the scanning of **all** registered channels is called one ``scan``. -.. only:: SOC_TOUCH_SUPPORT_FREQ_HOP +.. only:: not esp32 and not esp32s2 and not esp32s3 - **Touch Sensor Sampling Configuration**: Touch sensor sampling configuration refers to all the hardware configurations that related to the sampling. It can determine how the touch channels sample by setting the number of charging times, charging frequency, measurement interval, etc. The {IDF_TARGET_NAME} supports multiple sets of sample configuration, which means it can support frequency hopping. -.. only:: not SOC_TOUCH_SUPPORT_FREQ_HOP +.. only:: esp32 or esp32s2 or esp32s3 - **Touch Sensor Sampling Configuration**: Touch sensor sampling configuration refers to all the hardware configurations that related to the sampling. It can determine how the touch channels sample by setting the number of charging times, charging frequency, measurement interval, etc. The {IDF_TARGET_NAME} only support one set of sample configuration, so it doesn't support frequency hopping. @@ -310,7 +311,7 @@ Read Measurement Data Call :cpp:func:`touch_channel_read_data` to read the data with different types. Like, benchmark, smooth data, etc. You can refer to :cpp:type:`touch_chan_data_type_t` for the supported data types. -.. only:: SOC_TOUCH_SUPPORT_FREQ_HOP +.. only:: not esp32 and not esp32s2 and not esp32s3 The {IDF_TARGET_NAME} supports frequency hopping by configuring multiple set of sample configurations, :cpp:func:`touch_channel_read_data` can read out the data of each sample configuration in a single call, you can determine the sample configuration number by :cpp:member:`touch_sensor_config_t::sample_cfg_num`, and pass an array (which length is not smaller than the configuration number) to the third parameter ``*data``, so that all the measured data of this channel will be stored in the array. @@ -373,11 +374,11 @@ Call :cpp:func:`touch_channel_read_data` to read the data with different types. The {IDF_TARGET_NAME} supports proximity sensing. Proximity sensing can be registered by calling :cpp:func:`touch_sensor_config_proximity_sensing` and specify the configurations :cpp:type:`touch_proximity_config_t`. - .. only:: esp32p4 + .. only:: not esp32s2 and not esp32s3 Since the capacitance change caused by proximity sensing is far less than that caused by physical touch, large area of copper foil is often used on PCB to increase the sensing area. In addition, multiple rounds of scans are needed and the result of each scan will be accumulated in the driver to improve the measurement sensitivity. The scan times (rounds) can be determined by :cpp:member:`touch_proximity_config_t::scan_times` and the charging times of the proximity channel in one scan can be determined by :cpp:member:`touch_proximity_config_t::charge_times`. Generally, the larger the scan times and charging times is, the higher the sensitivity will be, however, the read data will be unstable if the sensitivity is too high. Proper parameters should be determined regarding the application. - .. only:: not esp32p4 + .. only:: esp32s2 or esp32s3 Since the capacitance change caused by proximity sensing is far less than that caused by physical touch, large area of copper foil is often used on PCB to increase the sensing area. In addition, multiple rounds of scans are needed and the result of each scan will be accumulated in the driver to improve the measurement sensitivity. The scan times (rounds) can be determined by :cpp:member:`touch_proximity_config_t::scan_times`. Generally, the larger the scan times and charging times is, the higher the sensitivity will be, however, the read data will be unstable if the sensitivity is too high. Proper parameters should be determined regarding the application. @@ -495,7 +496,7 @@ Due to the capacitive charging and discharging operation in the touch sensor mea :esp32s2 or esp32s3: - Set the current bias type to self-bias: By configuring :cpp:member:`touch_sensor_sample_config_t::bias_type` to :cpp:enumerator:`touch_bias_type_t::TOUCH_BIAS_TYPE_SELF` to use self-bias, which is more power-saving but less stable. :esp32 or esp32s2 or esp32s3: - Lower down the charging and discharging amplitudes: :cpp:member:`touch_sensor_sample_config_t::charge_volt_lim_l` and :cpp:member:`touch_sensor_sample_config_t::charge_volt_lim_h` can specify the lower voltage limit during the discharging and the upper voltage limit during the charging. Reducing both voltage limitations and the voltage error between them can also decrease the power consumption. :esp32 or esp32s2 or esp32s3: - Reduce the current bias intensity: Lowering down :cpp:member:`touch_channel_config_t::charge_speed` (i.e., the current magnitude of the current bias) can help to reduce the power consumption. - :esp32p4: - Lower down the LDO voltage biasing intensity: Decreasing :cpp:member:`touch_channel_config_t::bias_volt` can reduce the power consumption. + :not esp32 and not esp32s2 and not esp32s3: - Lower down the LDO voltage biasing intensity: Decreasing :cpp:member:`touch_channel_config_t::bias_volt` can reduce the power consumption. API Reference ------------- diff --git a/docs/en/api-reference/peripherals/cap_touch_sens/esp32h4.inc b/docs/en/api-reference/peripherals/cap_touch_sens/esp32h4.inc new file mode 100644 index 0000000000..44c59de8c4 --- /dev/null +++ b/docs/en/api-reference/peripherals/cap_touch_sens/esp32h4.inc @@ -0,0 +1,64 @@ +.. This file gets included from other .rst files in this folder. +.. It contains target-specific snippets. +.. Comments and '---' lines act as delimiters. +.. +.. This is necessary mainly because RST doesn't support substitutions +.. (defined in RST, not in Python) inside code blocks. If that is ever implemented, +.. These code blocks can be moved back to the main .rst files, with target-specific +.. file names being replaced by substitutions. + +.. touch-chan-mapping + +.. list-table:: + :header-rows: 1 + :widths: 20 20 + + * - Channel + - GPIO + + * - CH0 + - IO0 + + * - CH1 + - IO1 + + * - CH2 + - IO2 + + * - CH3 + - IO3 + + * - CH4 + - IO29 + + * - CH5 + - IO30 + + * - CH6 + - IO31 + + * - CH7 + - IO32 + + * - CH8 + - IO33 + + * - CH9 + - IO34 + + * - CH10 + - IO35 + + * - CH11 + - IO36 + + * - CH12 + - IO37 + + * - CH13 + - IO38 + + * - CH14 + - IO39 + +--- diff --git a/docs/zh_CN/api-reference/peripherals/cap_touch_sens.rst b/docs/zh_CN/api-reference/peripherals/cap_touch_sens.rst index aa9bba3613..21e120da30 100644 --- a/docs/zh_CN/api-reference/peripherals/cap_touch_sens.rst +++ b/docs/zh_CN/api-reference/peripherals/cap_touch_sens.rst @@ -3,7 +3,7 @@ :link_to_translation:`en:[English]` -{IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32="v1", esp32s2="v2", esp32s3="v2", esp32p4="v3"} +{IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32="v1", esp32s2="v2", esp32s3="v2", esp32p4="v3", esp32h4="v3"} 概述 ------ @@ -30,6 +30,7 @@ | | ESP32-S3 | 第二代触摸传感器,新增接近感应测量完成中断 | +-----------+--------------+------------------------------------------------------------------------+ | V3 | ESP32-P4 | 第三代触摸传感器,新增跳频扫描 | +| | ESP32-H4 | | +-----------+--------------+------------------------------------------------------------------------+ 测量原理 @@ -72,11 +73,11 @@ - **触摸传感器控制器**:触摸传感器驱动的控制器,负责触摸传感器的配置和管理。 - **触摸传感器通道**:具体的一路触摸传感器采样通道。一个触摸传感器模块具有多个通道,一般连接到触摸板上,用于测量该触摸板电容的变化。驱动中把对 **一个** 通道的采样称为 ``测量``,而对 **所有** 注册通道的 ``测量`` 称为一次 ``扫描``。 -.. only:: IDF_TARGET_TOUCH_SAMPLE_CFG_DESC +.. only:: not esp32 and not esp32s2 and not esp32s3 - **触摸传感器采样配置**:触摸传感器采样配置是驱动中对采样有关的硬件配置的统称。采样配置负责触摸传感器通道的采样,其配置决定了触摸通道的充放电次数、充放电频率、测量间隔等。{IDF_TARGET_NAME} 支持多套采样配置,支持跳频采样。 -.. only:: not IDF_TARGET_TOUCH_SAMPLE_CFG_DESC +.. only:: esp32 or esp32s2 or esp32s3 - **触摸传感器采样配置**:触摸传感器采样配置是驱动中对采样有关的硬件配置的统称。采样配置负责触摸传感器通道的采样,其配置决定了触摸通道的充放电次数、充放电频率、测量间隔等。{IDF_TARGET_NAME} 仅支持一套采样配置,不支持跳频采样。 @@ -310,7 +311,7 @@ 调用 :cpp:func:`touch_channel_read_data` 可读取每个通道不同种类的数据,例如基线值、经过滤波后的平滑值等。支持的数据类型请参考 :cpp:type:`touch_chan_data_type_t`。 -.. only:: SOC_TOUCH_SUPPORT_FREQ_HOP +.. only:: not esp32 and not esp32s2 and not esp32s3 {IDF_TARGET_NAME} 支持通过配置多套采样配置来实现跳频采样,:cpp:func:`touch_channel_read_data` 可一次性读出一个通道所有采样配置的测量值。根据配置的 :cpp:member:`touch_sensor_config_t::sample_cfg_num` 采样配置数量,第三个参数 (``*data``) 数据指针传入数组长度大于等于采样配置数量的数组指针即可,该函数会将所指定通道的所有采样配置的测量值存入该数组中。 @@ -373,11 +374,11 @@ {IDF_TARGET_NAME} 支持接近感应功能。可通过调用 :cpp:func:`touch_sensor_config_proximity_sensing` 并配置 :cpp:type:`touch_proximity_config_t` 来注册接近感应功能。 - .. only:: esp32p4 + .. only:: not esp32s2 and not esp32s3 由于接近感应引起的电容变化远小于物理触摸,PCB 上常用较大面积的铺铜来增大触摸通道的感应面积,另外需要在硬件上对接近感应通道进行多轮扫描并在驱动中进行累加来提高测量灵敏度。接近感应的灵敏度由测量轮数 :cpp:member:`touch_proximity_config_t::scan_times` 以及单次测量的充放电次数 :cpp:member:`touch_proximity_config_t::charge_times` 决定。测量轮数以及充放电次数越高,灵敏度越高,但是过高的灵敏度容易导致误触发,请选择适当的灵敏度来保证触发的稳定性。 - .. only:: not esp32p4 + .. only:: esp32s2 or esp32s3 由于接近感应引起的电容变化远小于物理触摸,PCB 上常用较大面积的铺铜来增大触摸通道的感应面积,另外需要在硬件上对接近感应通道进行多轮扫描并在驱动中进行累加来提高测量灵敏度。接近感应的灵敏度由测量轮数 :cpp:member:`touch_proximity_config_t::scan_times` 决定。测量轮数以及充放电次数越高,灵敏度越高,但是过高的灵敏度容易导致误触发,请选择适当的灵敏度来保证触发的稳定性。 @@ -495,7 +496,7 @@ :esp32s2 or esp32s3: - 电流偏置类型设为自偏置:通过设置 :cpp:member:`touch_sensor_sample_config_t::bias_type` 为 :cpp:enumerator:`touch_bias_type_t::TOUCH_BIAS_TYPE_SELF` 来使用功耗更低的自偏置。 :esp32 or esp32s2 or esp32s3: - 降低充放电幅度::cpp:member:`touch_sensor_sample_config_t::charge_volt_lim_l` 和 :cpp:member:`touch_sensor_sample_config_t::charge_volt_lim_h` 用于指定放电时的电压下限和充电时的电压上限,同时降低这两个电压值以及上下限之间的压差可降低功耗。 :esp32 or esp32s2 or esp32s3: - 降低电流偏置强度:降低 :cpp:member:`touch_channel_config_t::charge_speed` 充放电速度(即电流偏置的电流大小)从而降低功耗。 - :esp32p4: - 降低 LDO 电压偏置强度:降低 :cpp:member:`touch_channel_config_t::bias_volt` 从而降低功耗。 + :not esp32 and not esp32s2 and not esp32s3: - 降低 LDO 电压偏置强度:降低 :cpp:member:`touch_channel_config_t::bias_volt` 从而降低功耗。 API 参考 ---------- diff --git a/docs/zh_CN/api-reference/peripherals/cap_touch_sens/esp32h4.inc b/docs/zh_CN/api-reference/peripherals/cap_touch_sens/esp32h4.inc new file mode 100644 index 0000000000..bcdcbd31bc --- /dev/null +++ b/docs/zh_CN/api-reference/peripherals/cap_touch_sens/esp32h4.inc @@ -0,0 +1,64 @@ +.. This file gets included from other .rst files in this folder. +.. It contains target-specific snippets. +.. Comments and '---' lines act as delimiters. +.. +.. This is necessary mainly because RST doesn't support substitutions +.. (defined in RST, not in Python) inside code blocks. If that is ever implemented, +.. These code blocks can be moved back to the main .rst files, with target-specific +.. file names being replaced by substitutions. + +.. touch-chan-mapping + +.. list-table:: + :header-rows: 1 + :widths: 20 20 + + * - 通道 + - GPIO + + * - CH0 + - IO0 + + * - CH1 + - IO1 + + * - CH2 + - IO2 + + * - CH3 + - IO3 + + * - CH4 + - IO29 + + * - CH5 + - IO30 + + * - CH6 + - IO31 + + * - CH7 + - IO32 + + * - CH8 + - IO33 + + * - CH9 + - IO34 + + * - CH10 + - IO35 + + * - CH11 + - IO36 + + * - CH12 + - IO37 + + * - CH13 + - IO38 + + * - CH14 + - IO39 + +--- diff --git a/examples/peripherals/touch_sensor/touch_sens_basic/README.md b/examples/peripherals/touch_sensor/touch_sens_basic/README.md index 07b350acd0..864d370f89 100644 --- a/examples/peripherals/touch_sensor/touch_sens_basic/README.md +++ b/examples/peripherals/touch_sensor/touch_sens_basic/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-P4 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | # Capacity Touch Sensor Example