diff --git a/components/driver/esp32/include/touch_sensor.h b/components/driver/esp32/include/touch_sensor.h index e7ed06ff8..b56f4439e 100644 --- a/components/driver/esp32/include/touch_sensor.h +++ b/components/driver/esp32/include/touch_sensor.h @@ -18,6 +18,8 @@ extern "C" { #endif +#include "driver/touch_sensor_common.h" + /** * @brief Configure touch pad interrupt threshold. * @@ -51,7 +53,7 @@ esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold); * - ESP_ERR_INVALID_STATE This touch pad hardware connection is error, the value of "touch_value" is 0. * - ESP_FAIL Touch pad not initialized */ -esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t * touch_value); +esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value); /** * @brief get filtered touch sensor counter value by IIR filter. @@ -121,13 +123,13 @@ esp_err_t touch_pad_set_filter_read_cb(filter_cb_t read_cb); * - ESP_ERR_INVALID_ARG GPIO error * - ESP_ERR_NO_MEM No memory */ -esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg); +esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg); /** * @brief Set touch sensor measurement and sleep time. - * Excessive total time will slow down the touch response. + * Excessive total time will slow down the touch response. * Too small measurement time will not be sampled enough, resulting in inaccurate measurements. - * + * * @note The greater the duty cycle of the measurement time, the more system power is consumed. * @param sleep_cycle The touch sensor will sleep after each measurement. * sleep_cycle decide the interval between each measurement. @@ -267,6 +269,13 @@ esp_err_t touch_pad_intr_enable(void); */ esp_err_t touch_pad_intr_disable(void); +/** + * @brief To clear touch pad interrupt + * @return + * - ESP_OK on success + */ +esp_err_t touch_pad_intr_clear(void); + /** * @brief set touch pad filter calibration period, in ms. * Need to call touch_pad_filter_start before all touch filter APIs @@ -287,7 +296,7 @@ esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms); * - ESP_ERR_INVALID_STATE driver state error * - ESP_ERR_INVALID_ARG parameter error */ -esp_err_t touch_pad_get_filter_period(uint32_t* p_period_ms); +esp_err_t touch_pad_get_filter_period(uint32_t *p_period_ms); /** * @brief start touch pad filter function diff --git a/components/driver/esp32/touch_sensor.c b/components/driver/esp32/touch_sensor.c index ccee01bf8..c79249485 100644 --- a/components/driver/esp32/touch_sensor.c +++ b/components/driver/esp32/touch_sensor.c @@ -49,7 +49,7 @@ typedef struct { bool enable; } touch_pad_filter_t; static touch_pad_filter_t *s_touch_pad_filter = NULL; -// check if touch pad be inited. +// check if touch pad be initialized. static uint16_t s_touch_pad_init_bit = 0x0000; static filter_cb_t s_filter_cb = NULL; static SemaphoreHandle_t rtc_touch_mux = NULL; @@ -227,7 +227,7 @@ esp_err_t touch_pad_clear_group_mask(uint16_t set1_mask, uint16_t set2_mask, uin esp_err_t touch_pad_intr_enable(void) { TOUCH_ENTER_CRITICAL(); - touch_hal_enable_interrupt(); + touch_hal_intr_enable(); TOUCH_EXIT_CRITICAL(); return ESP_OK; } @@ -235,11 +235,24 @@ esp_err_t touch_pad_intr_enable(void) esp_err_t touch_pad_intr_disable(void) { TOUCH_ENTER_CRITICAL(); - touch_hal_disable_interrupt(); + touch_hal_intr_disable(); TOUCH_EXIT_CRITICAL(); return ESP_OK; } +esp_err_t touch_pad_intr_clear(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_intr_clear(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +bool touch_pad_meas_is_done(void) +{ + return touch_hal_meas_is_done(); +} + esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold) { TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); diff --git a/components/driver/esp32s2/include/touch_sensor.h b/components/driver/esp32s2/include/touch_sensor.h index d4de6ba3a..16140b520 100644 --- a/components/driver/esp32s2/include/touch_sensor.h +++ b/components/driver/esp32s2/include/touch_sensor.h @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at - // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software @@ -18,10 +17,12 @@ extern "C" { #endif +#include "driver/touch_sensor_common.h" + /** * @brief Set touch sensor FSM start * @note Start FSM after the touch sensor FSM mode is set. - * @note Call this function will reset beseline of all touch channels. + * @note Call this function will reset baseline of all touch channels. * @return * - ESP_OK on success */ @@ -43,62 +44,62 @@ esp_err_t touch_pad_sw_start(void); /** * @brief Set touch sensor times of charge and discharge and sleep time. - * Excessive total time will slow down the touch response. + * Excessive total time will slow down the touch response. * Too small measurement time will not be sampled enough, resulting in inaccurate measurements. - * + * * @note The greater the duty cycle of the measurement time, the more system power is consumed. * @param sleep_cycle The touch sensor will sleep after each measurement. * sleep_cycle decide the interval between each measurement. * t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency). * The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function. - * @param meas_time The time of charge and discharge in each measure process of touch channels. + * @param meas_times The times of charge and discharge in each measure process of touch channels. * The timer frequency is 8Mhz. Range: 0 ~ 0xffff. * Recommended typical value: Modify this value to make the measurement time around 1ms. * @return * - ESP_OK on success */ -esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_time); +esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times); /** * @brief Get touch sensor times of charge and discharge and sleep time * @param sleep_cycle Pointer to accept sleep cycle number - * @param meas_time Pointer to accept measurement time count. + * @param meas_times Pointer to accept measurement times count. * @return * - ESP_OK on success */ -esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_time); +esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times); /** * @brief Set connection type of touch channel in idle status. - * When a channel is in measurement mode, other initialized channels are in idle mode. + * 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_HIGHZ`(high resistance) setting increases the sensitivity of touch channels. * The `CONN_GND`(grounding) setting increases the stability of touch channels. * @param type Select idle channel connect to high resistance state or ground. * @return * - ESP_OK on success */ -esp_err_t touch_pad_set_inactive_connect(touch_pad_conn_type_t type); +esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type); /** * @brief Set connection type of touch channel in idle status. - * When a channel is in measurement mode, other initialized channels are in idle mode. + * 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_HIGHZ`(high resistance) setting increases the sensitivity of touch channels. * The `CONN_GND`(grounding) setting increases the stability of touch channels. * @param type Pointer to connection type. * @return * - ESP_OK on success */ -esp_err_t touch_pad_get_inactive_connect(touch_pad_conn_type_t *type); +esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type); /** * @brief Set the trigger threshold of touch sensor. * The threshold determines the sensitivity of the touch sensor. * The threshold is the original value of the trigger state minus the baseline value. - * @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be trigered. + * @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered. * @param touch_num touch pad index * @param threshold threshold of touch sensor. Should be less than the max change value of touch. * @return @@ -122,7 +123,7 @@ esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold); * This function will set the scan bits according to the given bitmask. * @note If set this mask, the FSM timer should be stop firsty. * @note The touch sensor that in scan map, should be deinit GPIO function firstly by `touch_pad_io_init`. - * @param enable_mask bitmask of touch sensor scan group. + * @param enable_mask bitmask of touch sensor scan group. * e.g. TOUCH_PAD_NUM14 -> BIT(14) * @return * - ESP_OK on success @@ -131,7 +132,7 @@ esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask); /** * @brief Get the touch sensor scan group bit mask. - * @param enable_mask Pointer to bitmask of touch sensor scan group. + * @param enable_mask Pointer to bitmask of touch sensor scan group. * e.g. TOUCH_PAD_NUM14 -> BIT(14) * @return * - ESP_OK on success @@ -143,7 +144,7 @@ esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask); * The working mode of the touch sensor is cyclically scanned. * This function will clear the scan bits according to the given bitmask. * @note If clear all mask, the FSM timer should be stop firsty. - * @param enable_mask bitmask of touch sensor scan group. + * @param enable_mask bitmask of touch sensor scan group. * e.g. TOUCH_PAD_NUM14 -> BIT(14) * @return * - ESP_OK on success @@ -162,26 +163,16 @@ esp_err_t touch_pad_clear_channel_mask(uint16_t enable_mask); esp_err_t touch_pad_config(touch_pad_t touch_num); /** - * @brief Reset the whole of touch module. - * @note Call this funtion after `touch_pad_fsm_stop`, + * @brief Reset the FSM of touch module. + * @note Call this function after `touch_pad_fsm_stop`. * @return * - ESP_OK Success */ esp_err_t touch_pad_reset(void); /** - * @brief Check touch sensor measurement status. - * If doing measurement, the flag will be clear. - * If finish measurement. the flag will be set. - * @return - * - TRUE finish measurement - * - FALSE doing measurement - */ -bool touch_pad_meas_is_done(void); - -/** - * @brief Get the current measure channel. - * Touch sensor measurement is cyclic scan mode. + * @brief Get the current measure channel. + * @note Should be called when touch sensor measurement is in cyclic scan mode. * @return * - touch channel number */ @@ -190,7 +181,7 @@ touch_pad_t touch_pad_get_current_meas_channel(void); /** * @brief Get the touch sensor interrupt status mask. * @return - * - touch intrrupt bit + * - touch interrupt bit */ uint32_t touch_pad_read_intr_status_mask(void); @@ -210,18 +201,54 @@ esp_err_t touch_pad_intr_enable(touch_pad_intr_mask_t int_mask); */ esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask); +/** + * @brief Clear touch sensor interrupt by bitmask. + * @param int_mask Pad mask to clear interrupts + * @return + * - ESP_OK on success + */ +esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask); + /** * @brief Register touch-pad ISR. * The handler will be attached to the same CPU core that this function is running on. * @param fn Pointer to ISR handler * @param arg Parameter for ISR - * @param int_mask Initial pad mask to enable interrupt for + * @param intr_mask Enable touch sensor interrupt handler by bitmask. * @return - * - ESP_OK Success ; - * - ESP_ERR_INVALID_ARG GPIO error + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Arguments error * - ESP_ERR_NO_MEM No memory */ -esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg, touch_pad_intr_mask_t int_mask); +esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask); + +/** + * @brief Enable/disable the timeout check and set timeout threshold for all touch sensor channels measurements. + * If enable: When the touch reading of a touch channel exceeds the measurement threshold, a timeout interrupt will be generated. + * If disable: the FSM does not check if the channel under measurement times out. + * + * @note The threshold compared with touch readings. + * @note In order to avoid abnormal short circuit of some touch channels. This function should be turned on. + * Ensure the normal operation of other touch channels. + * + * @param enable true(default): Enable the timeout check; false: Disable the timeout check. + * @param threshold For all channels, the maximum value that will not be exceeded during normal operation. + * +* @return + * - ESP_OK Success + */ +esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold); + +/** + * @brief Call this interface after timeout to make the touch channel resume normal work. Point on the next channel to measure. + * If this API is not called, the touch FSM will stop the measurement after timeout interrupt. + * + * @note Call this API after finishes the exception handling by user. + * + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_timeout_resume(void); /** * @brief get raw data of touch sensor. @@ -231,7 +258,7 @@ esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg, touch_pad_intr_ma * @param raw_data pointer to accept touch sensor value * @return * - ESP_OK Success - * - ESP_FAIL Touch channel 0 havent this parameter. + * - ESP_FAIL Touch channel 0 haven't this parameter. */ esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data); @@ -243,10 +270,18 @@ esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data); * @param basedata pointer to accept touch sensor baseline value * @return * - ESP_OK Success - * - ESP_ERR_INVALID_ARG Touch channel 0 havent this parameter. + * - ESP_ERR_INVALID_ARG Touch channel 0 haven't this parameter. */ esp_err_t touch_pad_filter_read_baseline(touch_pad_t touch_num, uint32_t *basedata); +/** + * @brief Get smoothed data that obtained by filtering the raw data. + * + * @param touch_num touch pad index + * @param smooth pointer to smoothed data + */ +esp_err_t touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth); + /** * @brief Force reset baseline to raw data of touch sensor. * @param touch_num touch pad index @@ -283,7 +318,7 @@ esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info); esp_err_t touch_pad_filter_enable(void); /** - * @brief diaable touch sensor filter for detection algorithm. + * @brief disable touch sensor filter for detection algorithm. * For more details on the detection algorithm, please refer to the application documentation. * @return * - ESP_OK Success @@ -292,11 +327,11 @@ esp_err_t touch_pad_filter_disable(void); /** * @brief set parameter of denoise pad (TOUCH_PAD_NUM0). - * T0 is an internal channel that does not have a corresponding external GPIO. - * T0 will work simultaneously with the measured channel Tn. Finally, the actual + * T0 is an internal channel that does not have a corresponding external GPIO. + * T0 will work simultaneously with the measured channel Tn. Finally, the actual * measured value of Tn is the value after subtracting lower bits of T0. - * This denoise function filters out interference introduced on all channels, - * such as noise introduced by the power supply and external EMI. + * The noise reduction function filters out interference introduced simultaneously on all channels, + * such as noise introduced by power supplies and external EMI. * @param denoise parameter of denoise * @return * - ESP_OK Success @@ -313,11 +348,11 @@ esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise); /** * @brief enable denoise function. - * T0 is an internal channel that does not have a corresponding external GPIO. - * T0 will work simultaneously with the measured channel Tn. Finally, the actual + * T0 is an internal channel that does not have a corresponding external GPIO. + * T0 will work simultaneously with the measured channel Tn. Finally, the actual * measured value of Tn is the value after subtracting lower bits of T0. - * This denoise function filters out interference introduced on all channels, - * such as noise introduced by the power supply and external EMI. + * The noise reduction function filters out interference introduced simultaneously on all channels, + * such as noise introduced by power supplies and external EMI. * @return * - ESP_OK Success */ @@ -341,9 +376,9 @@ esp_err_t touch_pad_denoise_read_data(uint32_t *data); /** * @brief set parameter of waterproof function. * The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel. - * The shielded channel outputs the same signal as the channel being measured. + * The shielded channel outputs the same signal as the channel being measured. * It is generally designed as a grid and is placed around the touch buttons. - * The shielded channel does not follow the measurement signal of the protection channel. + * The shielded channel does not follow the measurement signal of the protection channel. * So that the guard channel can detect a large area of water. * @param waterproof parameter of waterproof * @return @@ -362,9 +397,9 @@ esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof); /** * @brief Enable parameter of waterproof function. * The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel. - * The shielded channel outputs the same signal as the channel being measured. + * The shielded channel outputs the same signal as the channel being measured. * It is generally designed as a grid and is placed around the touch buttons. - * The shielded channel does not follow the measurement signal of the protection channel. + * The shielded channel does not follow the measurement signal of the protection channel. * So that the guard channel can detect a large area of water. * @return * - ESP_OK Success @@ -374,9 +409,9 @@ esp_err_t touch_pad_waterproof_enable(void); /** * @brief Enable parameter of waterproof function. * The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel. - * The shielded channel outputs the same signal as the channel being measured. + * The shielded channel outputs the same signal as the channel being measured. * It is generally designed as a grid and is placed around the touch buttons. - * The shielded channel does not follow the measurement signal of the protection channel. + * The shielded channel does not follow the measurement signal of the protection channel. * So that the guard channel can detect a large area of water. * @return * - ESP_OK Success @@ -384,34 +419,44 @@ esp_err_t touch_pad_waterproof_enable(void); esp_err_t touch_pad_waterproof_disable(void); /** - * @brief Set parameter of proximity channel. Three proximity sensing channels can be set. + * @brief Enable/disable proximity function of touch channels. * The proximity sensor measurement is the accumulation of touch channel measurements. - * @note If stop the proximity function for the channel, point this proximity channel to `TOUCH_PAD_NUM0`. - * @param proximity parameter of proximity + * + * @note Supports up to three touch channels configured as proximity sensors. + * @param touch_num touch pad index + * @param enabled true: enable the proximity function; false: disable the proximity function * @return - * - ESP_OK Success + * - ESP_OK: Configured correctly. + * - ESP_ERR_INVALID_ARG: Touch channel number error. + * - ESP_ERR_NOT_SUPPORTED: Don't support configured. */ -esp_err_t touch_pad_proximity_set_config(touch_pad_proximity_t *proximity); +esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled); /** - * @brief Get parameter of proximity channel. Three proximity sensing channels can be set. + * @brief Set measure count of proximity channel. * The proximity sensor measurement is the accumulation of touch channel measurements. - * @param proximity parameter of proximity + * + * @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`. + * @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`. + * @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255. * @return - * - ESP_OK Success + * - ESP_OK: Configured correctly. + * - ESP_ERR_INVALID_ARG: Touch channel number error. */ -esp_err_t touch_pad_proximity_get_config(touch_pad_proximity_t *proximity); +esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count); /** * @brief Get measure count of proximity channel. * The proximity sensor measurement is the accumulation of touch channel measurements. - * @param touch_num touch pad index - * @param cnt Pointer to receive proximity channel measurement count + * + * @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`. + * @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`. + * @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255. * @return - * - ESP_OK Success - * - ESP_ERR_INVALID_ARG parameter is NULL + * - ESP_OK: Configured correctly. + * - ESP_ERR_INVALID_ARG: Touch channel number error. */ -esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt); +esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count); /** * @brief Get the accumulated measurement of the proximity sensor. @@ -420,46 +465,125 @@ esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt * @param measure_out If the accumulation process does not end, the `measure_out` is the process value. * @return * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Touch num is not proximity */ -esp_err_t touch_pad_proximity_data_get(touch_pad_t touch_num, uint32_t *measure_out); +esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out); /** - * @brief Set parameter of touch sensor in sleep mode. - * In order to achieve low power consumption in sleep mode, other circuits except the RTC part of the register are in a power-off state. - * Only one touch channel is supported in the sleep state, which can be used as a wake-up function. - * If in non-sleep mode, the sleep parameters do not work. - * @param slp_config touch pad config + * @brief Get parameter of touch sensor sleep channel. + * The touch sensor can works in sleep mode to wake up sleep. + * + * @note After the sleep channel is configured, Please use special functions for sleep channel. + * e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading. + * + * @param slp_config touch sleep pad config. * @return * - ESP_OK Success */ -esp_err_t touch_pad_sleep_channel_config(touch_pad_sleep_channel_t *slp_config); +esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config); /** - * @brief Read baseline of touch sensor in sleep mode. + * @brief Enable/Disable sleep channel function for touch sensor. + * The touch sensor can works in sleep mode to wake up sleep. + * + * @note ESP32S2 only support one sleep channel. + * @note After the sleep channel is configured, Please use special functions for sleep channel. + * e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading. + * + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. + * @param enable true: enable sleep pad for touch sensor; false: disable sleep pad for touch sensor; + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable); + +/** + * @brief Enable/Disable proximity function for sleep channel. + * The touch sensor can works in sleep mode to wake up sleep. + * + * @note ESP32S2 only support one sleep channel. + * + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. + * @param enable true: enable proximity for sleep channel; false: disable proximity for sleep channel; + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable); + +/** + * @brief Set the trigger threshold of touch sensor in deep sleep. + * The threshold determines the sensitivity of the touch sensor. + * + * @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep. + * + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. + * @param touch_thres touch sleep pad threshold + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres); + +/** + * @brief Get the trigger threshold of touch sensor in deep sleep. + * The threshold determines the sensitivity of the touch sensor. + * + * @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep. + * + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. + * @param touch_thres touch sleep pad threshold + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres); + +/** + * @brief Read baseline of touch sensor sleep channel. + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. * @param baseline pointer to accept touch sensor baseline value * @return * - ESP_OK Success * - ESP_ERR_INVALID_ARG parameter is NULL */ -esp_err_t touch_pad_sleep_channel_read_baseline(uint32_t *baseline); +esp_err_t touch_pad_sleep_channel_read_baseline(touch_pad_t pad_num, uint32_t *baseline); /** - * @brief Read debounce of touch sensor in sleep mode. - * @param debounce pointer to accept touch sensor debounce value + * @brief Read smoothed data of touch sensor sleep channel. + * Smoothed data is filtered from the raw data. + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. + * @param smooth_data pointer to accept touch sensor smoothed data * @return * - ESP_OK Success * - ESP_ERR_INVALID_ARG parameter is NULL */ -esp_err_t touch_pad_sleep_channel_read_debounce(uint32_t *debounce); +esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data); /** - * @brief Read proximity count of touch sensor in sleep mode. + * @brief Read raw data of touch sensor sleep channel. + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. + * @param raw_data pointer to accept touch sensor raw data + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG parameter is NULL + */ +esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data); + +/** + * @brief Reset baseline of touch sensor sleep channel. + * + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_sleep_channel_reset_baseline(void); + +/** + * @brief Read proximity count of touch sensor sleep channel. + * @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode. * @param proximity_cnt pointer to accept touch sensor proximity count value * @return * - ESP_OK Success * - ESP_ERR_INVALID_ARG parameter is NULL */ -esp_err_t touch_pad_sleep_channel_read_proximity_cnt(uint32_t *proximity_cnt); +esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *proximity_cnt); #ifdef __cplusplus } diff --git a/components/driver/esp32s2/rtc_tempsensor.c b/components/driver/esp32s2/rtc_tempsensor.c index a947d667d..da5863b24 100644 --- a/components/driver/esp32s2/rtc_tempsensor.c +++ b/components/driver/esp32s2/rtc_tempsensor.c @@ -60,7 +60,7 @@ static SemaphoreHandle_t rtc_tsens_mux = NULL; esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) { - SENS.sar_tctrl.tsens_dac = dac_offset[tsens.dac_offset].set_val; + // SENS.sar_tctrl.tsens_dac = dac_offset[tsens.dac_offset].set_val; // TODO: others MR resolve it. SENS.sar_tctrl.tsens_clk_div = tsens.clk_div; SENS.sar_tctrl.tsens_power_up_force = 1; SENS.sar_tctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT; @@ -77,7 +77,7 @@ esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens) { TSENS_CHECK(tsens != NULL, ESP_ERR_INVALID_ARG); - tsens->dac_offset = SENS.sar_tctrl.tsens_dac; + // tsens->dac_offset = SENS.sar_tctrl.tsens_dac; // TODO: others MR resolve it. for(int i=TSENS_DAC_L0; idac_offset == dac_offset[i].set_val) { tsens->dac_offset = dac_offset[i].index; diff --git a/components/driver/esp32s2/touch_sensor.c b/components/driver/esp32s2/touch_sensor.c index 317f97373..fe34b24af 100644 --- a/components/driver/esp32s2/touch_sensor.c +++ b/components/driver/esp32s2/touch_sensor.c @@ -59,6 +59,8 @@ static const char *TOUCH_TAG = "TOUCH_SENSOR"; #define TOUCH_PARAM_CHECK_STR(s) ""s" parameter error" extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished. +#define TOUCH_ENTER_CRITICAL_SAFE() portENTER_CRITICAL_SAFE(&rtc_spinlock) // Can be called in isr and task. +#define TOUCH_EXIT_CRITICAL_SAFE() portEXIT_CRITICAL_SAFE(&rtc_spinlock) #define TOUCH_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock) #define TOUCH_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock) @@ -68,8 +70,29 @@ static SemaphoreHandle_t rtc_touch_mux = NULL; Touch Pad ---------------------------------------------------------------*/ +/** Workaround for scan done interrupt issue. */ +static void touch_pad_workaround_isr_internal(void *arg) +{ + uint16_t ch_mask = 0; + uint32_t intr_mask = touch_hal_read_intr_status_mask(); + uint32_t pad_num = touch_hal_get_current_meas_channel(); + /* Make sure that the scan done interrupt is generated after the last channel measurement is completed. */ + if (intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { + touch_hal_get_channel_mask(&ch_mask); + for (int i = TOUCH_PAD_MAX - 1; i >= 0; i--) { + if (BIT(i) & ch_mask) { + if (pad_num != i) { + touch_hal_intr_clear(TOUCH_PAD_INTR_MASK_SCAN_DONE); + } + break; + } + } + } +} + esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask) { + static bool reg_flag = false; TOUCH_CHECK(fn != NULL, TOUCH_PARAM_CHECK_STR("intr_mask"), ESP_ERR_INVALID_ARG); TOUCH_INTR_MASK_CHECK(intr_mask); @@ -83,7 +106,20 @@ esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_ma if (intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { en_msk |= RTC_CNTL_TOUCH_INACTIVE_INT_ST_M; } - return rtc_isr_register(fn, arg, en_msk); + if (intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { + en_msk |= RTC_CNTL_TOUCH_SCAN_DONE_INT_ST_M; + } + if (intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { + en_msk |= RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M; + } + esp_err_t ret = rtc_isr_register(fn, arg, en_msk); + /* Must ensure: After being registered, it is executed first. */ + if ( (ret == ESP_OK) && (reg_flag == false) && (intr_mask & (TOUCH_PAD_INTR_MASK_SCAN_DONE | TOUCH_PAD_INTR_MASK_TIMEOUT)) ) { + rtc_isr_register(touch_pad_workaround_isr_internal, NULL, RTC_CNTL_TOUCH_SCAN_DONE_INT_ST_M | RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M); + reg_flag = true; + } + + return ret; } esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times) @@ -106,18 +142,18 @@ esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times) return ESP_OK; } -esp_err_t touch_pad_set_inactive_connect(touch_pad_conn_type_t type) +esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type) { TOUCH_CHECK(type < TOUCH_PAD_CONN_MAX, TOUCH_PARAM_CHECK_STR("type"), ESP_ERR_INVALID_ARG); TOUCH_ENTER_CRITICAL(); - touch_hal_set_inactive_connect(type); + touch_hal_set_idle_channel_connect(type); TOUCH_EXIT_CRITICAL(); return ESP_OK; } -esp_err_t touch_pad_get_inactive_connect(touch_pad_conn_type_t *type) +esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type) { - touch_hal_get_inactive_connect(type); + touch_hal_get_idle_channel_connect(type); return ESP_OK; } @@ -177,11 +213,49 @@ esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask) return ESP_OK; } +esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask) +{ + TOUCH_INTR_MASK_CHECK(int_mask); + TOUCH_ENTER_CRITICAL(); + touch_hal_intr_clear(int_mask); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + uint32_t touch_pad_read_intr_status_mask(void) { return touch_hal_read_intr_status_mask(); } +esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold) +{ + TOUCH_ENTER_CRITICAL(); + if (enable) { + touch_hal_timeout_enable(); + } else { + touch_hal_timeout_disable(); + } + touch_hal_timeout_set_threshold(threshold); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_timeout_get_threshold(uint32_t *threshold) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_timeout_get_threshold(threshold); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_timeout_resume(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_timer_force_done(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + esp_err_t touch_pad_config(touch_pad_t touch_num) { TOUCH_CHANNEL_CHECK(touch_num); @@ -232,15 +306,28 @@ esp_err_t touch_pad_reset(void) esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data) { - TOUCH_CHANNEL_CHECK(touch_num); + TOUCH_CHECK(touch_num < TOUCH_PAD_MAX && touch_num >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); + TOUCH_ENTER_CRITICAL_SAFE(); *raw_data = touch_hal_read_raw_data(touch_num); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data) +{ + TOUCH_CHANNEL_CHECK(touch_num); + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_filter_read_smooth(touch_num, smooth_data); + TOUCH_EXIT_CRITICAL_SAFE(); return ESP_OK; } esp_err_t IRAM_ATTR touch_pad_filter_read_baseline(touch_pad_t touch_num, uint32_t *basedata) { TOUCH_CHANNEL_CHECK(touch_num); + TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_filter_read_baseline(touch_num, basedata); + TOUCH_EXIT_CRITICAL_SAFE(); return ESP_OK; } @@ -263,6 +350,7 @@ esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info) TOUCH_CHECK(filter_info->noise_neg_thr <= TOUCH_NOISE_NEG_THR_MAX, TOUCH_PARAM_CHECK_STR("noise"), ESP_ERR_INVALID_ARG); TOUCH_CHECK(filter_info->neg_noise_limit <= TOUCH_NEG_NOISE_CNT_LIMIT, TOUCH_PARAM_CHECK_STR("noise_limit"), ESP_ERR_INVALID_ARG); TOUCH_CHECK(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, TOUCH_PARAM_CHECK_STR("jitter_step"), ESP_ERR_INVALID_ARG); + TOUCH_CHECK(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, TOUCH_PARAM_CHECK_STR("smooth level"), ESP_ERR_INVALID_ARG); TOUCH_ENTER_CRITICAL(); touch_hal_filter_set_config(filter_info); @@ -379,66 +467,163 @@ esp_err_t touch_pad_waterproof_disable(void) return ESP_OK; } -esp_err_t touch_pad_proximity_set_config(touch_pad_proximity_t *proximity) +esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled) { - for (int i=0; iselect_pad[i] < SOC_TOUCH_SENSOR_NUM, TOUCH_PARAM_CHECK_STR("pad"), ESP_ERR_INVALID_ARG); + esp_err_t ret = ESP_OK; + TOUCH_CHECK(touch_num < TOUCH_PAD_MAX, "Touch channel error", ESP_ERR_INVALID_ARG); + + TOUCH_ENTER_CRITICAL(); + if (!touch_hal_enable_proximity(touch_num, enabled)) { + ret = ESP_ERR_NOT_SUPPORTED; } - TOUCH_CHECK(proximity->meas_num <= TOUCH_PROXIMITY_MEAS_NUM_MAX, TOUCH_PARAM_CHECK_STR("meas_num"), ESP_ERR_INVALID_ARG); - - TOUCH_ENTER_CRITICAL(); - touch_hal_proximity_set_config(proximity); TOUCH_EXIT_CRITICAL(); - return ESP_OK; + return ret; } -esp_err_t touch_pad_proximity_get_config(touch_pad_proximity_t *proximity) +esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count) { + TOUCH_CHECK(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG); + TOUCH_ENTER_CRITICAL(); - touch_hal_proximity_get_config(proximity); + touch_hal_proximity_set_meas_times(count); TOUCH_EXIT_CRITICAL(); return ESP_OK; } +esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count) +{ + TOUCH_CHECK(count != NULL, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG); + + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_proximity_get_meas_times(count); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +/** + * @brief Get measure count of proximity channel. + * The proximity sensor measurement is the accumulation of touch channel measurements. + * @param touch_num touch pad index + * @param cnt Pointer to receive proximity channel measurement count + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG parameter is NULL + */ esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt) { - TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch_num is not proximity", ESP_ERR_INVALID_ARG); + TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG); + TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_proximity_read_meas_cnt(touch_num, cnt); + TOUCH_EXIT_CRITICAL_SAFE(); return ESP_OK; } -esp_err_t touch_pad_proximity_data_get(touch_pad_t touch_num, uint32_t *measure_out) +esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out) { - TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch_num is not proximity", ESP_ERR_INVALID_ARG); + TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG); + TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_filter_read_baseline(touch_num, measure_out); + TOUCH_EXIT_CRITICAL_SAFE(); return ESP_OK; } /************** sleep pad setting ***********************/ -esp_err_t touch_pad_sleep_channel_config(touch_pad_sleep_channel_t *slp_config) +esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config) { - TOUCH_CHECK(slp_config->touch_num < SOC_TOUCH_SENSOR_NUM, TOUCH_PARAM_CHECK_STR("pad"), ESP_ERR_INVALID_ARG); + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_channel_get_config(slp_config); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable) +{ + TOUCH_CHANNEL_CHECK(pad_num); TOUCH_ENTER_CRITICAL(); - touch_hal_sleep_channel_config(slp_config); + touch_hal_sleep_channel_enable(pad_num, enable); TOUCH_EXIT_CRITICAL(); return ESP_OK; } -esp_err_t touch_pad_sleep_channel_read_baseline(uint32_t *baseline) +esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable) { - touch_hal_sleep_read_baseline(baseline); + TOUCH_CHANNEL_CHECK(pad_num); + + TOUCH_ENTER_CRITICAL(); + if (enable) { + touch_hal_sleep_enable_approach(); + } else { + touch_hal_sleep_disable_approach(); + } + TOUCH_EXIT_CRITICAL(); return ESP_OK; } -esp_err_t touch_pad_sleep_channel_read_debounce(uint32_t *debounce) +esp_err_t touch_pad_sleep_get_channel_num(touch_pad_t *pad_num) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_get_channel_num(pad_num); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_set_threshold(touch_thres); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_get_threshold(touch_thres); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_baseline(touch_pad_t pad_num, uint32_t *baseline) +{ + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_read_baseline(baseline); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data) +{ + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_read_smooth(smooth_data); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data) +{ + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_read_data(raw_data); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_reset_baseline(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_reset_baseline(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_debounce(touch_pad_t pad_num, uint32_t *debounce) { touch_hal_sleep_read_debounce(debounce); return ESP_OK; } -esp_err_t touch_pad_sleep_channel_read_proximity_cnt(uint32_t *approach_cnt) +esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *approach_cnt) { touch_hal_sleep_read_proximity_cnt(approach_cnt); return ESP_OK; diff --git a/components/driver/include/driver/touch_pad.h b/components/driver/include/driver/touch_pad.h index 2cc851844..8a065dcc6 100644 --- a/components/driver/include/driver/touch_pad.h +++ b/components/driver/include/driver/touch_pad.h @@ -14,4 +14,4 @@ #pragma once -#include "touch_sensor_common.h" \ No newline at end of file +#include "touch_sensor.h" \ No newline at end of file diff --git a/components/driver/include/driver/touch_sensor_common.h b/components/driver/include/driver/touch_sensor_common.h index 7294ffccb..a114b03da 100644 --- a/components/driver/include/driver/touch_sensor_common.h +++ b/components/driver/include/driver/touch_sensor_common.h @@ -16,9 +16,7 @@ #include "esp_err.h" #include "esp_intr_alloc.h" -#include "soc/touch_sensor_periph.h" #include "hal/touch_sensor_types.h" -#include "touch_sensor.h" #ifdef __cplusplus extern "C" { @@ -141,22 +139,32 @@ esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode); /** - * @brief To clear the touch status register, usually use this function in touch ISR to clear status. + * @brief To clear the touch sensor channel active status. * - * @note Generally no manual removal is required. + * @note The FSM automatically updates the touch sensor status. It is generally not necessary to call this API to clear the status. * @return * - ESP_OK on success */ esp_err_t touch_pad_clear_status(void); /** - * @brief Get the touch sensor status, usually used in ISR to decide which pads are 'touched'. + * @brief Get the touch sensor channel active status mask. + * The bit position represents the channel number. The 0/1 status of the bit represents the trigger status. * * @return * - The touch sensor status. e.g. Touch1 trigger status is `status_mask & (BIT1)`. */ uint32_t touch_pad_get_status(void); +/** + * @brief Check touch sensor measurement status. + * + * @return + * - True measurement is under way + * - False measurement done + */ +bool touch_pad_meas_is_done(void); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/components/driver/test/CMakeLists.txt b/components/driver/test/CMakeLists.txt index 05d12cf5c..a0e2f5d14 100644 --- a/components/driver/test/CMakeLists.txt +++ b/components/driver/test/CMakeLists.txt @@ -1,3 +1,3 @@ -idf_component_register(SRC_DIRS . param_test +idf_component_register(SRC_DIRS . param_test touch_sensor_test PRIV_INCLUDE_DIRS include param_test/include PRIV_REQUIRES unity test_utils driver nvs_flash esp_serial_slave_link infrared_tools) diff --git a/components/driver/test/touch_sensor_test/test_esp32.c b/components/driver/test/touch_sensor_test/test_esp32.c new file mode 100644 index 000000000..fb6d4056e --- /dev/null +++ b/components/driver/test/touch_sensor_test/test_esp32.c @@ -0,0 +1,376 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* + Tests for the touch sensor device driver +*/ +#include "esp_system.h" +#include "driver/touch_pad.h" +#include "unity.h" +#include "esp_system.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_log.h" +#include "nvs_flash.h" +#include "test_utils.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/rtc_cntl_struct.h" +#include "soc/sens_reg.h" +#include "soc/sens_struct.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/rtc_cntl_struct.h" +#include "soc/rtc_io_reg.h" +#include "soc/rtc_io_struct.h" + +#if !DISABLED_FOR_TARGETS(ESP8266, ESP32S2) // This testcase for ESP32 + +static const char *TAG = "test_touch"; + +#define TOUCH_READ_INVALID_VAL (0) +#define TOUCHPAD_FILTER_TOUCH_PERIOD (10) + +#define TOUCH_REG_BASE_TEST() ({ \ + TEST_ASSERT_EQUAL_UINT32(RTC_CNTL_BROWN_OUT_REG, &RTCCNTL.brown_out.val); \ + TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(SENS_SARDATE_REG, SENS_SAR_DATE), SENS.sardate.sar_date); \ + TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_IO_DATE_REG, RTC_IO_IO_DATE), RTCIO.date.date); \ +}) + +#define TOUCH_READ_ERROR (100) +#define TEST_TOUCH_COUNT_NUM (10) +#define TEST_TOUCH_CHANNEL (3) +static touch_pad_t touch_list[TEST_TOUCH_CHANNEL] = { + // TOUCH_PAD_NUM0, + // TOUCH_PAD_NUM1 is GPIO0, for download. + // TOUCH_PAD_NUM2, + // TOUCH_PAD_NUM3, + // TOUCH_PAD_NUM4, + // TOUCH_PAD_NUM5, + // TOUCH_PAD_NUM6, + TOUCH_PAD_NUM7, + TOUCH_PAD_NUM8, + TOUCH_PAD_NUM9, +}; + +static void printf_touch_hw_read(const char *str) +{ + uint16_t touch_value; + printf("[%s] ", str); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + while (!touch_pad_meas_is_done()) ; + touch_pad_read_raw_data(touch_list[i], &touch_value); + printf("[%d]%d ", touch_list[i], touch_value); + } + printf("\r\n"); +} + +/* + * Change the slope to get larger value from touch sensor. + */ +static void test_press_fake(touch_pad_t pad_num) +{ + touch_pad_set_cnt_mode(pad_num, TOUCH_PAD_SLOPE_2, TOUCH_PAD_TIE_OPT_DEFAULT); +} + +/* + * Change the slope to get smaller value from touch sensor. + */ +static void test_release_fake(touch_pad_t pad_num) +{ + touch_pad_set_cnt_mode(pad_num, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_DEFAULT); +} + +static esp_err_t test_touch_sw_read_test_runner(void) +{ + ESP_LOGI(TAG, "%s", __func__); + uint16_t touch_value; + + TEST_ESP_OK( touch_pad_init() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW) ); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i], TOUCH_READ_INVALID_VAL) ); + } + + // Start task to read values sensed by pads + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + printf("test T%d\n", touch_list[i]); + touch_pad_read(touch_list[i], &touch_value); + printf("T%d:[%4d] ", touch_list[i], touch_value); + } + printf("\n"); + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +static esp_err_t test_touch_sw_read(void) +{ + ESP_LOGI(TAG, "%s", __func__); + uint16_t touch_value; + + TEST_ESP_OK( touch_pad_init() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW) ); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i], TOUCH_READ_INVALID_VAL) ); + } + + // Start task to read values sensed by pads + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + printf("test T%d\n", touch_list[i]); + TEST_ESP_OK( touch_pad_read(touch_list[i], &touch_value) ); + printf("T%d:[%4d] ", touch_list[i], touch_value); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); + } + printf("\n"); + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +static esp_err_t test_touch_timer_read(void) +{ + ESP_LOGI(TAG, "%s", __func__); + uint16_t touch_value[TEST_TOUCH_CHANNEL], touch_temp[TEST_TOUCH_CHANNEL]; + int t_cnt = TEST_TOUCH_COUNT_NUM; + + TEST_ESP_OK( touch_pad_init() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i], TOUCH_READ_INVALID_VAL) ); + } + // Start task to read values sensed by pads + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read(touch_list[i], &touch_value[i]) ); + printf("T%d:[%4d] ", touch_list[i], touch_value[i]); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value[i]); + } + while (t_cnt--) { + // Start task to read values sensed by pads + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read(touch_list[i], &touch_temp[i]) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp[i]); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + } + vTaskDelay(50 / portTICK_PERIOD_MS); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +static esp_err_t test_touch_filtered_read(void) +{ + ESP_LOGI(TAG, "%s", __func__); + uint16_t touch_value, touch_temp; + int t_cnt = TEST_TOUCH_COUNT_NUM; + + TEST_ESP_OK( touch_pad_init() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i], TOUCH_READ_INVALID_VAL) ); + } + // Initialize and start a software filter to detect slight change of capacitance. + touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); + vTaskDelay(10 / portTICK_PERIOD_MS); + + while (t_cnt--) { + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read(touch_list[i], &touch_value) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); + TEST_ESP_OK( touch_pad_read_filtered(touch_list[i], &touch_temp) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + printf("T%d:[%4d] ", touch_list[i], touch_value); + } + vTaskDelay(50 / portTICK_PERIOD_MS); + } + printf("\n"); + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +// test the basic configuration function with right parameters and error parameters +TEST_CASE("Touch Sensor all channel read test", "[touch]") +{ + TOUCH_REG_BASE_TEST(); + test_touch_sw_read_test_runner(); + TEST_ESP_OK( test_touch_sw_read() ); + TEST_ESP_OK( test_touch_timer_read() ); + TEST_ESP_OK( test_touch_filtered_read() ); +} + +static int test_touch_parameter(touch_pad_t pad_num, int meas_time, int slp_time, int vol_h, int vol_l, int vol_a, int slope) +{ + ESP_LOGI(TAG, "%s", __func__); + uint16_t touch_value; + TEST_ESP_OK( touch_pad_init() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_config(pad_num, TOUCH_READ_INVALID_VAL) ); + + touch_pad_set_meas_time(slp_time, meas_time); + touch_pad_set_voltage(vol_h, vol_l, vol_a); + touch_pad_set_cnt_mode(pad_num, slope, TOUCH_PAD_TIE_OPT_DEFAULT); + + // Initialize and start a software filter to detect slight change of capacitance. + touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); + vTaskDelay(500 / portTICK_PERIOD_MS); + + // Start task to read values sensed by pads + TEST_ESP_OK( touch_pad_read(pad_num, &touch_value) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); + printf("T%d:[%4d] ", pad_num, touch_value); + TEST_ESP_OK( touch_pad_read_raw_data(pad_num, &touch_value) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); + printf("T%d:[%4d] ", pad_num, touch_value); + TEST_ESP_OK( touch_pad_read_filtered(pad_num, &touch_value) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); + printf("T%d:[%4d] \n", pad_num, touch_value); + + TEST_ESP_OK( touch_pad_deinit() ); + + return touch_value; +} + +TEST_CASE("Touch Sensor parameters test", "[touch]") +{ + int touch_val[5] = {0}; + + ESP_LOGI(TAG, "Charge / incharge voltage level test"); + touch_val[0] = test_touch_parameter(touch_list[2], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V, + TOUCH_PAD_SLOPE_DEFAULT); + touch_val[1] = test_touch_parameter(touch_list[2], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_HVOLT_2V5, TOUCH_LVOLT_0V6, TOUCH_HVOLT_ATTEN_1V, + TOUCH_PAD_SLOPE_DEFAULT); + touch_val[2] = test_touch_parameter(touch_list[0], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5, + TOUCH_PAD_SLOPE_DEFAULT); + + TEST_ASSERT_GREATER_OR_EQUAL(touch_val[0], touch_val[1]); + TEST_ASSERT_GREATER_OR_EQUAL(touch_val[1], touch_val[2]); + + ESP_LOGI(TAG, "Measure time / sleep time test"); + touch_val[0] = test_touch_parameter(touch_list[0], 0xff, 0xa, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT); + touch_val[1] = test_touch_parameter(touch_list[0], 0x1ff, 0xf, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT); + touch_val[2] = test_touch_parameter(touch_list[0], 0x2fff, 0x1f, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT); + + TEST_ASSERT_GREATER_OR_EQUAL(touch_val[0], touch_val[1]); + TEST_ASSERT_GREATER_OR_EQUAL(touch_val[1], touch_val[2]); + + ESP_LOGI(TAG, "Charge / incharge slope level test"); + touch_val[0] = test_touch_parameter(touch_list[1], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, 1); + touch_val[1] = test_touch_parameter(touch_list[1], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, 3); + touch_val[2] = test_touch_parameter(touch_list[1], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, 7); + + TEST_ASSERT_GREATER_OR_EQUAL(touch_val[0], touch_val[1]); + TEST_ASSERT_GREATER_OR_EQUAL(touch_val[1], touch_val[2]); +} + +static bool s_pad_activated[TOUCH_PAD_MAX]; + +static void test_touch_intr_cb(void *arg) +{ + uint32_t pad_intr = touch_pad_get_status(); + ets_printf("T%x ", pad_intr); + //clear interrupt + touch_pad_clear_status(); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + if ((pad_intr >> touch_list[i]) & 0x1) { + s_pad_activated[touch_list[i]] = true; + } + } +} + +static esp_err_t test_touch_interrupt(void) +{ + ESP_LOGI(TAG, "%s", __func__); + uint16_t touch_value; + + TEST_ESP_OK( touch_pad_init() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i], TOUCH_READ_INVALID_VAL) ); + } + // Initialize and start a software filter to detect slight change of capacitance. + touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); + vTaskDelay(10 / portTICK_PERIOD_MS); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + //read filtered value + TEST_ESP_OK( touch_pad_read_filtered(touch_list[i], &touch_value) ); + ESP_LOGI(TAG, "test init: touch pad [%d] val is %d", touch_list[i], touch_value); + //set interrupt threshold. + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * 2 / 3) ); + } + + // Register touch interrupt ISR + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL) ); + TEST_ESP_OK( touch_pad_clear_status() ); + TEST_ESP_OK( touch_pad_intr_enable() ); + + int test_cnt = TEST_TOUCH_COUNT_NUM; + while (test_cnt--) { + ESP_LOGI(TAG, "touch push"); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + test_press_fake(touch_list[i]); + } + vTaskDelay(100 / portTICK_PERIOD_MS); + printf_touch_hw_read("push"); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + if (s_pad_activated[touch_list[i]] == false) { + ESP_LOGE(TAG, "touch%d not active", touch_list[i]); + TEST_FAIL(); + } + } + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + s_pad_activated[touch_list[i]] = 0; + } + + ESP_LOGI(TAG, "touch release"); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + test_release_fake(touch_list[i]); + } + printf_touch_hw_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +TEST_CASE("Touch Sensor interrupt test", "[touch]") +{ + TEST_ESP_OK( test_touch_interrupt() ); +} + +#endif // !DISABLED_FOR_TARGETS(ESP8266, ESP32) \ No newline at end of file diff --git a/components/driver/test/touch_sensor_test/test_esp32s2.c b/components/driver/test/touch_sensor_test/test_esp32s2.c new file mode 100644 index 000000000..4b9e3a3fe --- /dev/null +++ b/components/driver/test/touch_sensor_test/test_esp32s2.c @@ -0,0 +1,2174 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* + Tests for the touch sensor device driver +*/ +#include +#include "esp_system.h" +#include "driver/touch_pad.h" +#include "unity.h" +#include "esp_system.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" +#include "esp_log.h" +#include "test_utils.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/rtc_cntl_struct.h" +#include "soc/sens_reg.h" +#include "soc/sens_struct.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/rtc_cntl_struct.h" +#include "soc/rtc_io_reg.h" +#include "soc/rtc_io_struct.h" +#include "soc/apb_ctrl_reg.h" +#include "driver/rtc_io.h" + +#if !DISABLED_FOR_TARGETS(ESP8266, ESP32) // This testcase for ESP32S2 + +static const char *TAG = "test_touch"; + +#define PLATFORM_SELECT (1) //0: pxp; 1: chip +#if (PLATFORM_SELECT == 0) //PXP platform +#define SET_BREAK_POINT(flag) REG_WRITE(APB_CTRL_DATE_REG, flag) +//PXP clk is slower. +#define SYS_DELAY_TIME_MOM (1/40) +#define RTC_SLOW_CLK_FLAG 1 // Slow clock is 32KHz. +void test_pxp_deinit_io(void) +{ + for (int i = 0; i < 22; i++) { + rtc_gpio_init(i); + } +} +#else +//PXP clk is slower. +#define SET_BREAK_POINT(flag) +#define SYS_DELAY_TIME_MOM (1) +#define RTC_SLOW_CLK_FLAG 0 // Slow clock is 32KHz. +void test_pxp_deinit_io(void) +{ + ; +} +#endif + +#define TOUCH_READ_INVALID_VAL (SOC_TOUCH_PAD_THRESHOLD_MAX) +#define TOUCH_READ_ERROR (100) +#define TOUCH_INTR_THRESHOLD (0.1) +#define TOUCH_EXCEED_TIME_MS (1000) + +#define TOUCH_REG_BASE_TEST() ({ \ + TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_CNTL_DATE_REG, RTC_CNTL_CNTL_DATE), RTCCNTL.date.date); \ + TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(SENS_SARDATE_REG, SENS_SAR_DATE), SENS.sardate.sar_date); \ + TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_IO_DATE_REG, RTC_IO_IO_DATE), RTCIO.date.date); \ +}) + +#define TEST_TOUCH_COUNT_NUM (5) +#define TEST_TOUCH_CHANNEL (14) +static touch_pad_t touch_list[TEST_TOUCH_CHANNEL] = { + // TOUCH_PAD_NUM0, is GPIO0, for download. + TOUCH_PAD_NUM1, + TOUCH_PAD_NUM2, + TOUCH_PAD_NUM3, + TOUCH_PAD_NUM4, + TOUCH_PAD_NUM5, + TOUCH_PAD_NUM6, + TOUCH_PAD_NUM7, + TOUCH_PAD_NUM8, + TOUCH_PAD_NUM9, + TOUCH_PAD_NUM10, + TOUCH_PAD_NUM11, + TOUCH_PAD_NUM12, + TOUCH_PAD_NUM13, + TOUCH_PAD_NUM14 +}; + +#define TOUCH_WATERPROOF_RING_PAD TOUCH_PAD_NUM1 +static touch_pad_t proximity_pad[3] = { + TOUCH_PAD_NUM2, + TOUCH_PAD_NUM3, + TOUCH_PAD_NUM4, +}; + +static QueueHandle_t que_touch = NULL; +typedef struct touch_msg { + touch_pad_intr_mask_t intr_mask; + uint32_t pad_num; + uint32_t pad_status; + uint32_t pad_val; + uint32_t slp_proxi_cnt; + uint32_t slp_proxi_base; +} touch_event_t; + +static uint32_t s_touch_timeout_mask = 0; + +static void printf_touch_hw_read(const char *str) +{ + uint32_t touch_value; + printf("[%s] ", str); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + touch_pad_read_raw_data(touch_list[i], &touch_value); + printf("[%d]%d ", touch_list[i], touch_value); + } + printf("\r\n"); +} + +static void printf_touch_baseline_read(const char *str) +{ + uint32_t touch_value; + printf("[%s] ", str); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + printf("[%d]%d ", touch_list[i], touch_value); + } + printf("\r\n"); +} + +static void printf_touch_smooth_read(const char *str) +{ + uint32_t touch_value; + printf("[%s] ", str); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + touch_pad_filter_read_smooth(touch_list[i], &touch_value); + printf("[%d]%d ", touch_list[i], touch_value); + } + printf("\r\n"); +} + + +static void test_timeout_trigger_fake(touch_pad_t pad_num) +{ + touch_pad_set_cnt_mode(pad_num, TOUCH_PAD_SLOPE_0, TOUCH_PAD_TIE_OPT_DEFAULT); +} + +static void test_timeout_normal(touch_pad_t pad_num) +{ + touch_pad_set_cnt_mode(pad_num, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_DEFAULT); +} + +/* + * Change the slope to get larger value from touch sensor. + */ +static void test_press_fake(touch_pad_t pad_num) +{ + touch_pad_set_cnt_mode(pad_num, TOUCH_PAD_SLOPE_3, TOUCH_PAD_TIE_OPT_DEFAULT); +} + +/* + * Change the slope to get larger value from touch sensor. + */ +static void test_release_fake(touch_pad_t pad_num) +{ + touch_pad_set_cnt_mode(pad_num, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_DEFAULT); +} + +static void test_touch_push_all(void) +{ + ESP_LOGI(TAG, "touch push"); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + test_press_fake(touch_list[i]); + } +} + +static void test_touch_release_all(void) +{ + ESP_LOGI(TAG, "touch release"); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + test_release_fake(touch_list[i]); + } +} + +/* Test: if the raw data exceed noise threshold, the baseline should not be updated. */ +static void test_touch_baseline_not_update(void) +{ + uint32_t touch_val[TEST_TOUCH_CHANNEL] = {0}; + uint32_t touch_temp[TEST_TOUCH_CHANNEL] = {0}; + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_val[i]) ); + } + for (int i = 0; i < 10; i++) { + vTaskDelay(20 / portTICK_PERIOD_MS); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_temp[i]) ); + TEST_ASSERT_EQUAL(touch_temp[i], touch_val[i]); + } + } +} + +/* + * Test the stable and change of touch sensor reading in SW mode. + */ +esp_err_t test_touch_sw_read(void) +{ + uint32_t touch_value[TEST_TOUCH_CHANNEL] = {0}; + uint32_t touch_temp[TEST_TOUCH_CHANNEL] = {0}; + uint32_t touch_push[TEST_TOUCH_CHANNEL] = {0}; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + while (test_cnt--) { + test_touch_release_all(); + + /* Read the touch sensor raw data in SW mode. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_sw_start() ); + while (!touch_pad_meas_is_done()) ; + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value[i]) ); + printf("T%d:[%4d] ", touch_list[i], touch_value[i]); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value[i]); + } + printf("\n"); + /* Check the stable of reading. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + if (touch_temp[i]) { + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + } + touch_temp[i] = touch_value[i]; + } + + test_touch_push_all(); + + /* Read the touch sensor raw data in SW mode. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_sw_start() ); + while (!touch_pad_meas_is_done()) ; + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_push[i]) ); + printf("T%d:[%4d] ", touch_list[i], touch_push[i]); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_push[i]); + } + printf("\n"); + /* Check the change of reading. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ASSERT_GREATER_THAN(touch_value[i], touch_push[i]); + } + } + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +/* + * Test the stable and change of touch sensor reading in timer mode. + * TEST POINT: + * 1. Timer mode for FSM. + * 2. Touch channel slope setting. + * 3. Touch reading stable. + */ +esp_err_t test_touch_timer_read(void) +{ + uint32_t touch_value[TEST_TOUCH_CHANNEL] = {0}; + uint32_t touch_temp[TEST_TOUCH_CHANNEL] = {0}; + uint32_t touch_push[TEST_TOUCH_CHANNEL] = {0}; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + TEST_ESP_OK( touch_pad_init() ); + /* Set different slope for channels to test slope function. */ + printf("Set slope for channel: "); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + TEST_ESP_OK( touch_pad_set_cnt_mode(touch_list[i], i % 7 ? i % 7 : 1, TOUCH_PAD_TIE_OPT_DEFAULT) ); + printf("[ch%d-%d] ", touch_list[i], i % 7 ? i % 7 : 1); + } + printf("\n"); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + /* Wait touch sensor stable */ + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + while (test_cnt--) { + test_touch_release_all(); + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + // Start task to read values sensed by pads + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value[i]) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value[i]); + printf("T%d:[%4d] ", touch_list[i], touch_value[i]); + } + printf("\n"); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + if (touch_temp[i]) { + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + } + touch_temp[i] = touch_value[i]; + } + + test_touch_push_all(); + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + /* Read the touch sensor raw data in FSM mode. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_push[i]) ); + printf("T%d:[%4d] ", touch_list[i], touch_push[i]); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_push[i]); + } + printf("\n"); + /* Check the change of reading. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ASSERT_GREATER_THAN(touch_value[i], touch_push[i]); + } + } + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +/* + * Test the filter mode. + * TEST POINT: + * 1. Timer mode for FSM. + * 2. Touch reading stable. + * 3. Touch reading init value. + * 4. Touch reading filtered value equal to raw data. + */ +esp_err_t test_touch_filtered_read(void) +{ + uint32_t touch_value[TEST_TOUCH_CHANNEL] = {0}; + uint32_t touch_temp[TEST_TOUCH_CHANNEL] = {0}; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_32, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + /* Wait touch pad init done. */ + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + /* Test the stable for init value of touch reading. + * Ideal: baseline == raw data == smooth data. + */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value[i]) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value[i]); + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_temp[i]) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp[i]); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &touch_temp[i]) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp[i]); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + } + printf("touch filter init value:\n"); + printf_touch_hw_read("raw "); + printf_touch_baseline_read("base "); + printf_touch_smooth_read("smooth"); + printf("\n"); + + int test_cnt = TEST_TOUCH_COUNT_NUM; + while (test_cnt--) { + /* Touch reading filtered value equal to raw data. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value[i]) ); + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_temp[i]) ); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &touch_temp[i]) ); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + } + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + if (touch_temp[i]) { + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + } + touch_temp[i] = touch_value[i]; + } + vTaskDelay(20 / portTICK_PERIOD_MS); + } + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +TEST_CASE("Touch Sensor reading test (SW, Timer, filter)", "[touch]") +{ + TOUCH_REG_BASE_TEST(); + TEST_ESP_OK( test_touch_sw_read() ); + TEST_ESP_OK( test_touch_timer_read() ); + TEST_ESP_OK( test_touch_filtered_read() ); +} + +/* + * Test the base patameter mode. + * TEST POINT: + * 1. measure time and sleep time setting. + * 2. Charge / incharge voltage threshold setting. + * 3. Touch slope setting. + * 4. Touch reading filtered value equal to raw data. + */ +int test_touch_base_parameter(touch_pad_t pad_num, int meas_time, int slp_time, + int vol_h, int vol_l, int vol_a, int slope, bool is_conn_gnd) +{ + uint32_t touch_value = 0; + uint32_t touch_temp = 0, touch_filter; + uint64_t val_sum = 0; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + TEST_ESP_OK( touch_pad_init() ); + /* Note: init all channel, but test one channel. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + + TEST_ESP_OK( touch_pad_set_cnt_mode(pad_num, slope, TOUCH_PAD_TIE_OPT_DEFAULT) ); + TEST_ESP_OK( touch_pad_set_meas_time(slp_time, meas_time) ); + TEST_ESP_OK( touch_pad_set_voltage(vol_h, vol_l, vol_a) ); + TEST_ESP_OK( touch_pad_set_idle_channel_connect(is_conn_gnd) ); + ESP_LOGI(TAG, "meas_time[%d]_slp_time[%d]_vol_h[%d]_vol_l[%d]_vol_a[%d]_slope[%d]_is_conn_gnd[%d]", + meas_time, slp_time, vol_h, vol_l, vol_a, slope, is_conn_gnd); + + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_32, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + /* Some parameters will delay the init time. so wait longger time */ + vTaskDelay(100 / portTICK_PERIOD_MS); + + while (test_cnt--) { + /* Correctness of reading. Ideal: baseline == raw data == smooth data. */ + TEST_ESP_OK( touch_pad_read_raw_data(pad_num, &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_baseline(pad_num, &touch_filter) ); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_filter, touch_value); + TEST_ESP_OK( touch_pad_filter_read_smooth(pad_num, &touch_filter) ); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_filter, touch_value); + + /* Stable of reading */ + TEST_ESP_OK( touch_pad_read_raw_data(pad_num, &touch_value) ); + TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); + if (touch_temp) { + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + } + touch_temp = touch_value; + + printf("T%d:[%4d] ", pad_num, touch_value); + val_sum += touch_value; // For check. + vTaskDelay(20 / portTICK_PERIOD_MS); + } + printf("\n"); + + TEST_ESP_OK( touch_pad_deinit() ); + return (uint32_t)(val_sum / TEST_TOUCH_COUNT_NUM); +} + +TEST_CASE("Touch Sensor base parameters test (meas_time, voltage, slope, inv_conn)", "[touch]") +{ + int touch_val[5] = {0}; + + ESP_LOGI(TAG, "Charge / incharge voltage level test"); + touch_val[0] = test_touch_base_parameter(touch_list[2], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5, + TOUCH_PAD_SLOPE_DEFAULT, true); + touch_val[1] = test_touch_base_parameter(touch_list[2], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_HVOLT_2V5, TOUCH_LVOLT_0V6, TOUCH_HVOLT_ATTEN_1V, + TOUCH_PAD_SLOPE_DEFAULT, true); + touch_val[2] = test_touch_base_parameter(touch_list[2], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V, + TOUCH_PAD_SLOPE_DEFAULT, true); + + TEST_ASSERT_GREATER_THAN(touch_val[0], touch_val[1]); + TEST_ASSERT_GREATER_THAN(touch_val[1], touch_val[2]); + + ESP_LOGI(TAG, "Measure time / sleep time test"); + touch_val[0] = test_touch_base_parameter(touch_list[1], 0xff, 0x1ff, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT, true); + touch_val[1] = test_touch_base_parameter(touch_list[1], 0xfff, 0xff, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT, true); + touch_val[2] = test_touch_base_parameter(touch_list[1], 0x1fff, 0xf, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT, true); + + TEST_ASSERT_GREATER_THAN(touch_val[0], touch_val[1]); + TEST_ASSERT_GREATER_THAN(touch_val[1], touch_val[2]); + + ESP_LOGI(TAG, "Charge / incharge slope level test"); + touch_val[0] = test_touch_base_parameter(touch_list[0], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, 7, true); + touch_val[1] = test_touch_base_parameter(touch_list[0], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, 5, true); + touch_val[2] = test_touch_base_parameter(touch_list[0], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, 3, true); + + TEST_ASSERT_GREATER_THAN(touch_val[0], touch_val[1]); + TEST_ASSERT_GREATER_THAN(touch_val[1], touch_val[2]); + + /* The GND option causes larger parasitic capacitance and larger reading */ + ESP_LOGI(TAG, "Inactive connect test"); + touch_val[0] = test_touch_base_parameter(touch_list[3], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT, + false); + touch_val[1] = test_touch_base_parameter(touch_list[3], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD, TOUCH_PAD_SLOPE_DEFAULT, + true); + TEST_ASSERT_GREATER_THAN(touch_val[0], touch_val[1]); +} + +/* + * Check active interrupt of touch channels. + */ +static esp_err_t test_touch_check_ch_touched(uint32_t test_ch_num, uint32_t exceed_time_ms) +{ + touch_event_t evt = {0}; + esp_err_t ret = ESP_FAIL; + printf("Active: "); + while (1) { + if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { + printf("0x%x, ", evt.pad_status); + if (test_ch_num == __builtin_popcount(evt.pad_status)) { + ret = ESP_OK; + break; + } + } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_DONE | TOUCH_PAD_INTR_MASK_SCAN_DONE)) { + continue; + } else { // If the interrupt type error, test error. + ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + break; + } + } else { + ESP_LOGI(TAG, "Touch intr exceed time"); + break; + } + } + printf("\n"); + return ret; +} + +/* + * Check inactive interrupt of touch channels. + */ +static esp_err_t test_touch_check_ch_released(uint32_t test_ch_num, uint32_t exceed_time_ms) +{ + touch_event_t evt = {0}; + esp_err_t ret = ESP_FAIL; + printf("Inactive: "); + while (1) { + if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { + printf("0x%x, ", evt.pad_status); + if ((TEST_TOUCH_CHANNEL - test_ch_num) == __builtin_popcount(evt.pad_status)) { + ret = ESP_OK; + break; + } + } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_DONE | TOUCH_PAD_INTR_MASK_SCAN_DONE)) { + continue; + } else { // If the interrupt type error, test error. + ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + break; + } + } else { + ESP_LOGI(TAG, "Touch intr exceed time"); + break; + } + } + printf("\n"); + return ret; +} + +static esp_err_t test_touch_check_ch_touched_with_proximity(uint32_t test_ch_num, uint32_t exceed_time_ms) +{ + uint32_t count = 0; + uint16_t ch_mask = 0; + touch_event_t evt = {0}; + esp_err_t ret = ESP_FAIL; + + TEST_ESP_OK( touch_pad_proximity_get_count(TOUCH_PAD_MAX, &count) ); + printf("Active: "); + while (1) { + if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { + printf("0x%x, ", evt.pad_status); + if (test_ch_num == __builtin_popcount(evt.pad_status)) { + ret = ESP_OK; + break; + } + } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_SCAN_DONE)) { + touch_pad_get_channel_mask(&ch_mask); + for (int i = TOUCH_PAD_MAX - 1; i >= 0; i--) { + if (BIT(i) & ch_mask) { + if (evt.pad_num == i) { + if (count == evt.slp_proxi_cnt) { + ets_printf("priximity base(%d) cnt(%d)\n", evt.slp_proxi_base, evt.slp_proxi_cnt); + } + } + } + } + continue; + } else { // If the interrupt type error, test error. + ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + continue;; + } + } else { + ESP_LOGI(TAG, "Touch intr exceed time"); + break; + } + } + printf("\n"); + return (esp_err_t)ret; +} + +static esp_err_t test_touch_check_ch_released_with_proximity(uint32_t test_ch_num, uint32_t exceed_time_ms) +{ + uint32_t count = 0; + uint16_t ch_mask = 0; + touch_event_t evt = {0}; + esp_err_t ret = ESP_FAIL; + + TEST_ESP_OK( touch_pad_proximity_get_count(TOUCH_PAD_MAX, &count) ); + printf("Inactive: "); + while (1) { + if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { + printf("0x%x, ", evt.pad_status); + if ((TEST_TOUCH_CHANNEL - test_ch_num) == __builtin_popcount(evt.pad_status)) { + ret = ESP_OK; + break; + } + } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_SCAN_DONE)) { + touch_pad_get_channel_mask(&ch_mask); + for (int i = TOUCH_PAD_MAX - 1; i >= 0; i--) { + if (BIT(i) & ch_mask) { + if (evt.pad_num == i) { + if (count == evt.slp_proxi_cnt) { + ets_printf("priximity base(%d) cnt(%d)\n", evt.slp_proxi_base, evt.slp_proxi_cnt); + } + } + } + } + continue; + } else { // If the interrupt type error, test error. + ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + continue;; + } + } else { + ESP_LOGI(TAG, "Touch intr exceed time"); + break; + } + } + printf("\n"); + return (esp_err_t)ret; +} + +/* + * Check scan done interrupt of touch channels. + */ +static esp_err_t test_touch_check_ch_intr_scan_done(void) +{ + touch_event_t evt = {0}; + uint16_t ch_mask = 0; + esp_err_t ret = ESP_FAIL; + /* Check the scan done interrupt. */ + while (1) { + if (pdTRUE == xQueueReceive(que_touch, &evt, 1000 / portTICK_PERIOD_MS)) { + /* Scan done interrupt have bug that be trigger by last two channel. */ + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { + touch_pad_get_channel_mask(&ch_mask); + for (int i = TOUCH_PAD_MAX - 1; i >= 0; i--) { + if (BIT(i) & ch_mask) { + if (evt.pad_num == i) { + ESP_LOGI(TAG, "touch _SCAN_DONE INTR be triggered"); + ret = ESP_OK; + } + goto NEXT_TEST; + } + } + } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_DONE | TOUCH_PAD_INTR_MASK_SCAN_DONE)) { + continue; + } else { // If the interrupt type error, test error. + ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + break; + } + } else { + ESP_LOGI(TAG, "Touch intr exceed time"); + break; + } + } +NEXT_TEST: + printf("\n"); + return (esp_err_t)ret; +} + +/* + * Check timeout interrupt of touch channels. + */ +static esp_err_t test_touch_check_ch_intr_timeout(touch_pad_t pad_num) +{ + esp_err_t ret = ESP_FAIL; + touch_event_t evt = {0}; + + while (1) { + if (pdTRUE == xQueueReceive(que_touch, &evt, 1000 / portTICK_PERIOD_MS)) { + /* Scan done interrupt have bug that be trigger by last two channel. */ + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { + if (pad_num == evt.pad_num) { + ESP_LOGI(TAG, "touch TIMEOUT be triggered"); + s_touch_timeout_mask = 0; + ret = ESP_OK; + touch_pad_timeout_resume(); + break; + } else { + ets_printf("-timeout %x T[%d] status %d, evt_msk %x -\n", + s_touch_timeout_mask, evt.pad_num, evt.pad_status, evt.intr_mask); + touch_pad_timeout_resume(); + } + } else { + continue; + } + } else { + ESP_LOGI(TAG, "Touch intr exceed time"); + break; + } + } + printf("\n"); + return (esp_err_t)ret; +} + +static void test_touch_intr_cb(void *arg) +{ + uint32_t cnt, touch_value; + int task_awoken = pdFALSE; + touch_event_t evt; + evt.intr_mask = touch_pad_read_intr_status_mask(); + evt.pad_status = touch_pad_get_status(); + evt.pad_num = touch_pad_get_current_meas_channel(); + + if (!evt.intr_mask) { + ets_printf("."); + return; + } + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { + touch_pad_filter_read_baseline(evt.pad_num, &evt.pad_val); + touch_pad_sleep_channel_t slp_config; + touch_pad_sleep_channel_get_info(&slp_config); + touch_pad_sleep_channel_read_baseline(slp_config.touch_num, &touch_value); + touch_pad_sleep_channel_read_proximity_cnt(slp_config.touch_num, &cnt); + evt.slp_proxi_cnt = cnt; + evt.slp_proxi_base = touch_value; + // ets_printf("[intr] base(%d) cnt(%d)\n", touch_value, cnt); + } + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { + s_touch_timeout_mask |= (BIT(evt.pad_num)); + ets_printf("-%dtout-", SENS.sar_touch_status0.touch_scan_curr); + } + + xQueueSendFromISR(que_touch, &evt, &task_awoken); + if (task_awoken == pdTRUE) { + portYIELD_FROM_ISR(); + } +} + +/* + * Test the touch active/inactive interrupt. + * TEST POINT: + * 1. Touch interrupt. + * 2. Raw data noise. + * 3. smooth data and baseline data. + */ +esp_err_t test_touch_interrupt(void) +{ + uint32_t touch_value, smooth; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + // Initialize and start a software filter to detect slight change of capacitance. + vTaskDelay(50 / portTICK_PERIOD_MS); + + /* Set threshold of touch sensor */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + + while (test_cnt--) { + test_touch_push_all(); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("push"); + + /* Test: if the raw data exceed noise threshold, the baseline should not be updated. */ + test_touch_baseline_not_update(); + + test_touch_release_all(); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +/* + * Test the touch active/inactive, scan_done interrupt. + * TEST POINT: + * 1. Touch interrupt. + * 2. Raw data noise. + * 3. smooth data and baseline data. + */ +esp_err_t test_touch_scan_done_interrupt(void) +{ + ESP_LOGI(TAG, " >> %s << \n", __func__); + uint32_t touch_value, smooth; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_SCAN_DONE | TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + /* Check the scan done interrupt */ + TEST_ESP_OK( test_touch_check_ch_intr_scan_done() ); + + vTaskDelay(50 / portTICK_PERIOD_MS); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", \ + touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + + while (test_cnt--) { + test_touch_push_all(); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("push"); + + /* Test: if the raw data exceed noise threshold, the baseline should not be updated. */ + test_touch_baseline_not_update(); + + test_touch_release_all(); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +/* + * Test the touch active/inactive, timeout interrupt. + * TEST POINT: + * 1. Touch interrupt. + * 2. Raw data noise. + * 3. smooth data and baseline data. + */ +esp_err_t test_touch_timeout_interrupt(void) +{ + ESP_LOGI(TAG, " >> %s << \n", __func__); + uint32_t touch_value, smooth; + + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_TIMEOUT | TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + // Initialize and start a software filter to detect slight change of capacitance. + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + /* Set timeout parameter */ + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[0], &touch_value) ); + TEST_ESP_OK( touch_pad_timeout_set(true , touch_value * 10) ); + + // Only fake push one touch pad. + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + test_timeout_trigger_fake(touch_list[0]); + TEST_ESP_OK( test_touch_check_ch_intr_timeout(touch_list[0]) ); + test_timeout_normal(touch_list[0]); + + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + printf_touch_hw_read("raw "); + printf_touch_baseline_read("base "); + printf_touch_smooth_read("smooth"); + + int test_cnt = TEST_TOUCH_COUNT_NUM; + while (test_cnt--) { + test_touch_push_all(); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("push"); + + /* Test: if the raw data exceed noise threshold, the baseline should not be updated. */ + test_touch_baseline_not_update(); + + test_touch_release_all(); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +TEST_CASE("Touch Sensor interrupt test (active, inactive, scan_done, timeout)", "[touch]") +{ + TEST_ESP_OK( test_touch_interrupt() ); + TEST_ESP_OK( test_touch_scan_done_interrupt() ); + TEST_ESP_OK( test_touch_timeout_interrupt() ); +} + +static void test_touch_measure_step(uint32_t step) +{ + /* Fake the process of debounce. */ + // printf("measure cnt %d: [ ", step); + for (int i = 0; i < step; i++) { + for (int j = 0; j < TEST_TOUCH_CHANNEL; j++) { + TEST_ESP_OK( touch_pad_sw_start() ); + while (!touch_pad_meas_is_done()) ; + } + // printf("."); + } + // printf(" ]\n"); +} + +/* + * Test the touch active/inactive, scan_done interrupt. + * TEST POINT: + * 1. Touch interrupt. + * 2. Raw data noise. + * 3. smooth data and baseline data. + */ +esp_err_t test_touch_filter_parameter_debounce(int deb_cnt) +{ + uint32_t touch_value; + int test_cnt = 2; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_128, // Test jitter and filter 1/4. + .debounce_cnt = ((deb_cnt < 0) ? 1 : deb_cnt) , // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_OFF, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + /* Run to wait the data become stable. */ + test_touch_measure_step(20); // 2 scan loop + + /* Set the threshold. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + + while (test_cnt--) { + test_touch_push_all(); + /* Fake the process of push debounce. */ + test_touch_measure_step(deb_cnt); // measure n times. touch state not changed. + TEST_ESP_ERR( ESP_FAIL, test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + test_touch_measure_step(1); // measure n+1 times. touch state changed. + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("push"); + + test_touch_release_all(); + /* Fake the process of release debounce. */ + test_touch_measure_step(deb_cnt); // measure n times. touch state not changed. + TEST_ESP_ERR( ESP_FAIL, test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + test_touch_measure_step(1); // measure n+1 times. touch state changed. + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +esp_err_t test_touch_filter_parameter_neg_reset(int reset_cnt) +{ + uint32_t touch_value, base_value; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + reset_cnt = ((reset_cnt < 0) ? 10 : reset_cnt); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = reset_cnt, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_OFF, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + /* Run to wait the data become stable. */ + test_touch_measure_step(20); // 2 scan loop + + /* Set the threshold. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + + /* 1. Fake init status is touched. */ + test_touch_push_all(); + TEST_ESP_OK( touch_pad_filter_reset_baseline(TOUCH_PAD_MAX) ); + /* Run to wait the data become stable. */ + test_touch_measure_step(20); // 2 scan loop + printf_touch_hw_read("[raw ] reset:"); + printf_touch_baseline_read("[base] reset:"); + + /* 2. Fake the touch status is released. */ + test_touch_release_all(); + /* 3. Fake measure `reset_cnt + 1` times to reset the baseline. */ + test_touch_measure_step(reset_cnt); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &base_value) ); + if ((base_value - touch_value) < (base_value * TOUCH_INTR_THRESHOLD)) { + ESP_LOGE(TAG, "neg reset cnt err"); + TEST_FAIL(); + } + } + printf_touch_hw_read("[raw ] neg_cnt:"); + printf_touch_baseline_read("[base] neg_cnt:"); + + test_touch_measure_step(1); + /* ESP32S2 neg reset baseline to raw data */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &base_value) ); + TEST_ASSERT_EQUAL_UINT32(base_value, touch_value); + } + printf_touch_hw_read("[raw ] neg_cnt+1:"); + printf_touch_baseline_read("[base] neg_cnt+1:"); + + int test_cnt = 2; + while (test_cnt--) { + test_touch_push_all(); + /* Fake the process of push debounce. */ + test_touch_measure_step(filter_info.debounce_cnt + 1); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("push"); + + test_touch_release_all(); + /* Fake the process of release debounce. */ + test_touch_measure_step(filter_info.debounce_cnt + 1); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +esp_err_t test_touch_filter_parameter_jitter(int jitter_step) +{ + uint32_t touch_value, base_value = 0; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + jitter_step = ((jitter_step < 0) ? 4 : jitter_step); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_JITTER, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = jitter_step, // use for jitter mode. + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + /* Run to wait the data become stable. */ + test_touch_measure_step(20); // 2 scan loop + + /* Check the jitter step. */ + printf_touch_baseline_read("[smooth] t1:"); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + test_touch_measure_step(1); + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + test_press_fake(touch_list[i]); + test_touch_measure_step(1); + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &base_value) ); + TEST_ASSERT_EQUAL_UINT32(jitter_step, (base_value - touch_value)); + } + printf_touch_baseline_read("[smooth] t2:"); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + test_touch_measure_step(1); + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + test_release_fake(touch_list[i]); + test_touch_measure_step(1); + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &base_value) ); + TEST_ASSERT_EQUAL_UINT32(jitter_step, (touch_value - base_value)); + } + printf_touch_baseline_read("[smooth] t3:"); + + /* Set the threshold. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + //read baseline value + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + //set interrupt threshold. + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + + int test_cnt = 2; + while (test_cnt--) { + test_touch_push_all(); + /* Fake the process of push debounce. */ + test_touch_measure_step(filter_info.debounce_cnt + 1); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_smooth_read("push"); + + test_touch_release_all(); + /* Fake the process of release debounce. */ + test_touch_measure_step(filter_info.debounce_cnt + 1); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_smooth_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +TEST_CASE("Touch Sensor filter paramter test (debounce, neg_reset, jitter)", "[touch]") +{ + ESP_LOGI(TAG, "*********** touch filter debounce test ********************"); + TEST_ESP_OK( test_touch_filter_parameter_debounce(0) ); + TEST_ESP_OK( test_touch_filter_parameter_debounce(3) ); + TEST_ESP_OK( test_touch_filter_parameter_debounce(7) ); + + ESP_LOGI(TAG, "*********** touch filter neg threshold reset limit test ********************"); + TEST_ESP_OK( test_touch_filter_parameter_neg_reset(1) ); + TEST_ESP_OK( test_touch_filter_parameter_neg_reset(5) ); + TEST_ESP_OK( test_touch_filter_parameter_neg_reset(15) ); + + ESP_LOGI(TAG, "*********** touch filter jitter test ********************"); + TEST_ESP_OK( test_touch_filter_parameter_jitter(1) ); + TEST_ESP_OK( test_touch_filter_parameter_jitter(5) ); + TEST_ESP_OK( test_touch_filter_parameter_jitter(15) ); +} + +esp_err_t test_touch_denoise(uint32_t out_val[], uint32_t *denoise_val, touch_pad_denoise_grade_t grade, touch_pad_denoise_cap_t cap) +{ + uint32_t touch_value; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + ESP_LOGI(TAG, "Denoise level (%d), cap level (%d) \n", grade, cap); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = (grade < 0) ? TOUCH_PAD_DENOISE_BIT4 : grade, + .cap_level = (cap < 0) ? TOUCH_PAD_DENOISE_CAP_L4 : cap, + }; + TEST_ESP_OK( touch_pad_denoise_set_config(&denoise) ); + TEST_ESP_OK( touch_pad_denoise_enable() ); + ESP_LOGI(TAG, "Denoise function init"); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + /* Run to wait the data become stable. */ + test_touch_measure_step(20); // 2 scan loop + + /* Set the threshold. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + if (out_val) { + /* Output value for check. */ + out_val[i] = touch_value; + } + } + printf_touch_baseline_read("Denoise"); + if (denoise_val) { + touch_pad_denoise_read_data(denoise_val); + } + + int test_cnt = 1; + while (test_cnt--) { + test_touch_push_all(); + /* Fake the process of push debounce. */ + test_touch_measure_step(filter_info.debounce_cnt + 1); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + + test_touch_release_all(); + /* Fake the process of release debounce. */ + test_touch_measure_step(filter_info.debounce_cnt + 1); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +TEST_CASE("Touch Sensor denoise test (cap, level)", "[touch]") +{ + uint32_t val_1[TEST_TOUCH_CHANNEL]; + uint32_t val_2[TEST_TOUCH_CHANNEL]; + uint32_t val_3[TEST_TOUCH_CHANNEL]; + uint32_t denoise_val[TOUCH_PAD_DENOISE_CAP_MAX]; + + ESP_LOGI(TAG, "*********** touch filter denoise level test ********************"); + TEST_ESP_OK( test_touch_denoise(val_1, NULL, TOUCH_PAD_DENOISE_BIT4, TOUCH_PAD_DENOISE_CAP_L0) ); + TEST_ESP_OK( test_touch_denoise(val_2, NULL, TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L0) ); + TEST_ESP_OK( test_touch_denoise(val_3, NULL, TOUCH_PAD_DENOISE_BIT12, TOUCH_PAD_DENOISE_CAP_L0) ); + + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ASSERT_GREATER_OR_EQUAL(val_3[i], val_2[i]); + TEST_ASSERT_GREATER_OR_EQUAL(val_2[i], val_1[i]); + } + + ESP_LOGI(TAG, "*********** touch filter denoise cap level test ********************"); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[0], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L0) ); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[1], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L1) ); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[2], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L2) ); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[3], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L3) ); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[4], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L4) ); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[5], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L5) ); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[6], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L6) ); + TEST_ESP_OK( test_touch_denoise(NULL, &denoise_val[7], TOUCH_PAD_DENOISE_BIT8, TOUCH_PAD_DENOISE_CAP_L7) ); + + printf("denoise read: "); + for (int i = 0; i < TOUCH_PAD_DENOISE_CAP_MAX - 1; i++) { + TEST_ASSERT_GREATER_OR_EQUAL(denoise_val[i], denoise_val[i + 1]); + printf("%d ", denoise_val[i]); + } + printf("\n"); +} + +esp_err_t test_touch_waterproof(void) +{ + uint32_t touch_value; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + TEST_ESP_OK( touch_pad_denoise_set_config(&denoise) ); + TEST_ESP_OK( touch_pad_denoise_enable() ); + ESP_LOGI(TAG, "Denoise function init"); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + /* Waterproof function */ + touch_pad_waterproof_t waterproof = { + .guard_ring_pad = TOUCH_WATERPROOF_RING_PAD, // If no ring pad, set 0; + /* It depends on the number of the parasitic capacitance of the shield pad. */ + .shield_driver = TOUCH_PAD_SHIELD_DRV_L0, //40pf + }; + TEST_ESP_OK( touch_pad_waterproof_set_config(&waterproof) ); + TEST_ESP_OK( touch_pad_waterproof_enable() ); + ESP_LOGI(TAG, "touch pad waterproof init"); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + vTaskDelay(50 / portTICK_PERIOD_MS); + + /* Set the threshold. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + } + + while (test_cnt--) { + test_touch_push_all(); + vTaskDelay(20 / portTICK_PERIOD_MS); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL - 1, TOUCH_EXCEED_TIME_MS) ); // take off shield pad + printf_touch_hw_read("push"); + + test_touch_release_all(); + vTaskDelay(20 / portTICK_PERIOD_MS); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +TEST_CASE("Touch Sensor waterproof guard test", "[touch]") +{ + ESP_LOGI(TAG, "*********** touch filter waterproof guard test ********************"); + TEST_ESP_OK( test_touch_waterproof() ); +} + +esp_err_t test_touch_proximity(int meas_num) +{ + ESP_LOGI(TAG, " >> %s << \n", __func__); + + uint32_t touch_value; + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + TEST_ESP_OK( touch_pad_denoise_set_config(&denoise) ); + TEST_ESP_OK( touch_pad_denoise_enable() ); + ESP_LOGI(TAG, "Denoise function init"); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + /* Waterproof function */ + touch_pad_waterproof_t waterproof = { + .guard_ring_pad = TOUCH_WATERPROOF_RING_PAD,// If no ring pad, set 0; + /* It depends on the number of the parasitic capacitance of the shield pad. */ + .shield_driver = TOUCH_PAD_SHIELD_DRV_L0, //40pf + }; + TEST_ESP_OK( touch_pad_waterproof_set_config(&waterproof) ); + TEST_ESP_OK( touch_pad_waterproof_enable() ); + ESP_LOGI(TAG, "touch pad waterproof init"); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + vTaskDelay(50 / portTICK_PERIOD_MS); + + /* Set the threshold. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + if (touch_list[i] == proximity_pad[0] || + touch_list[i] == proximity_pad[1] || + touch_list[i] == proximity_pad[2]) { + /* The threshold of proximity pad is the sum of touch reading `meas_num` times */ + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], + meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD)) ); + ESP_LOGI(TAG, "proximity pad [%d] base %d, thresh %d", touch_list[i], touch_value, + (uint32_t)(meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD))); + } else { + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "touch pad [%d] base %d, thresh %d", \ + touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + } + /* Should stop the measure, then change the config. */ + while (!touch_pad_meas_is_done()); + TEST_ESP_OK( touch_pad_fsm_stop() ); + /* Proximity function */ + TEST_ESP_OK( touch_pad_proximity_enable(proximity_pad[0], true) ); + TEST_ESP_OK( touch_pad_proximity_enable(proximity_pad[1], true) ); + TEST_ESP_OK( touch_pad_proximity_enable(proximity_pad[2], true) ); + TEST_ESP_OK( touch_pad_proximity_set_count(TOUCH_PAD_MAX, meas_num < 0 ? 16 : meas_num) ); + ESP_LOGI(TAG, "touch pad proximity init"); + TEST_ESP_OK( touch_pad_fsm_start() ); + + vTaskDelay(20 / portTICK_PERIOD_MS); + int test_cnt = TEST_TOUCH_COUNT_NUM; + while (test_cnt--) { + test_touch_push_all(); + vTaskDelay(20 / portTICK_PERIOD_MS); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL - 1, TOUCH_EXCEED_TIME_MS) ); // take off shield pad + printf_touch_hw_read("push"); + + test_touch_release_all(); + vTaskDelay(20 / portTICK_PERIOD_MS); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ESP_OK; +} + +TEST_CASE("Touch Sensor proximity test", "[touch]") +{ + ESP_LOGI(TAG, "*********** touch proximity test ********************"); + + TEST_ESP_OK( test_touch_proximity(5) ); + TEST_ESP_OK( test_touch_proximity(1) ); +} + +esp_err_t test_touch_sleep_reading_stable(touch_pad_t sleep_pad) +{ + uint32_t touch_temp = 0; + uint32_t touch_value, smooth, ret_val; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + // /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + TEST_ESP_OK( touch_pad_denoise_set_config(&denoise) ); + TEST_ESP_OK( touch_pad_denoise_enable() ); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_OFF, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + TEST_ESP_OK( touch_pad_sleep_channel_enable(sleep_pad, true) ); + TEST_ESP_OK( touch_pad_sleep_channel_enable_proximity(sleep_pad, false) ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + // Initialize and start a software filter to detect slight change of capacitance. + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + /* Set threshold of touch sensor */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + + /* Sleep channel setting */ + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &touch_value) ); + TEST_ESP_OK( touch_pad_sleep_set_threshold(sleep_pad, touch_value * TOUCH_INTR_THRESHOLD) ); + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + while (test_cnt--) { + /* Touch reading filtered value equal to raw data. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_sleep_channel_read_data(sleep_pad, &touch_value) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &touch_temp) ); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &touch_temp) ); + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + } + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + if (touch_temp) { + TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + } + touch_temp = touch_value; + } + vTaskDelay(20 / portTICK_PERIOD_MS); + } + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &ret_val) ); + + TEST_ESP_OK( touch_pad_deinit() ); + + return ret_val; +} + + +TEST_CASE("Touch Sensor sleep pad reading stable test", "[touch]") +{ + ESP_LOGI(TAG, "*********** touch sleep pad low power (wakeup) test ********************"); + test_touch_sleep_reading_stable(touch_list[0]); +} + +/* + * Test the touch sleep pad interrupt in normal mode. + * TEST POINT: + * 1. Touch sleep pad interrupt. + * 2. sleep pad reading. + * 3. sleep pad enable proximity. + */ +uint32_t test_touch_sleep_pad_proximity(touch_pad_t sleep_pad, bool is_proximity, uint32_t meas_num) +{ + uint32_t touch_value, smooth, ret_val; + uint32_t measure_out; + uint32_t proximity_cnt; + uint32_t touch_thres; + int test_cnt = TEST_TOUCH_COUNT_NUM; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + TEST_ESP_OK( touch_pad_denoise_set_config(&denoise) ); + TEST_ESP_OK( touch_pad_denoise_enable() ); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_OFF, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Sleep channel setting */ + TEST_ESP_OK( touch_pad_sleep_channel_enable(sleep_pad, true) ); + TEST_ESP_OK( touch_pad_sleep_channel_enable_proximity(sleep_pad, is_proximity) ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_SCAN_DONE | TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + // Initialize and start a software filter to detect slight change of capacitance. + vTaskDelay(100 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + if (is_proximity) { + /* Set the threshold. */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + if (touch_list[i] == sleep_pad) { + touch_pad_sleep_channel_read_smooth(sleep_pad, &touch_value); + touch_pad_sleep_set_threshold(sleep_pad, meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD)); + ESP_LOGI(TAG, "Sleep pad [%d] base %d, thresh %d", touch_list[i], touch_value, + (uint32_t)(meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD))); + } else if (touch_list[i] == sleep_pad) { + // TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + touch_pad_sleep_channel_read_smooth(sleep_pad, &touch_value); + /* The threshold of proximity pad is the sum of touch reading `meas_num` times */ + touch_pad_sleep_set_threshold(sleep_pad, meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD)); + ESP_LOGI(TAG, "proximity pad [%d] base %d, thresh %d", touch_list[i], touch_value, + (uint32_t)(meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD))); + } else { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "touch pad [%d] base %d, thresh %d", \ + touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + } + /* Should stop the measure, then change the config. */ + while (!touch_pad_meas_is_done()); + TEST_ESP_OK( touch_pad_fsm_stop() ); + /* Proximity function */ + TEST_ESP_OK( touch_pad_proximity_enable(proximity_pad[0], false) ); + TEST_ESP_OK( touch_pad_proximity_enable(proximity_pad[1], false) ); + TEST_ESP_OK( touch_pad_proximity_enable(proximity_pad[2], false) ); + TEST_ESP_OK( touch_pad_proximity_enable(sleep_pad, true) ); + TEST_ESP_OK( touch_pad_proximity_set_count(TOUCH_PAD_MAX, meas_num) ); + ESP_LOGI(TAG, "touch pad proximity init"); + TEST_ESP_OK( touch_pad_fsm_start() ); + vTaskDelay(100 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + } else { + /* Set threshold of touch sensor */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + /* Sleep channel setting */ + TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &touch_value) ); + TEST_ESP_OK( touch_pad_sleep_set_threshold(sleep_pad, touch_value * TOUCH_INTR_THRESHOLD) ); + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + } + + TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &ret_val) ); + + while (test_cnt--) { + test_touch_push_all(); + TEST_ESP_OK( test_touch_check_ch_touched_with_proximity(TEST_TOUCH_CHANNEL, 5000) ); + printf_touch_hw_read("push"); + if (is_proximity) { + TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &smooth) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &touch_value) ); + TEST_ESP_OK( touch_pad_proximity_get_data(sleep_pad, &measure_out) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_proximity_cnt(sleep_pad, &proximity_cnt) ); + TEST_ESP_OK( touch_pad_sleep_get_threshold(sleep_pad, &touch_thres) ); + printf("touch slp smooth %d, base %d, proxi %d cnt %d thres%d status 0x%x\n", + smooth, touch_value, measure_out, proximity_cnt, + touch_thres, touch_pad_get_status()); + } + test_touch_release_all(); + TEST_ESP_OK( test_touch_check_ch_released_with_proximity(TEST_TOUCH_CHANNEL, 5000) ); + printf_touch_hw_read("release"); + if (is_proximity) { + TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &smooth) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &touch_value) ); + TEST_ESP_OK( touch_pad_proximity_get_data(sleep_pad, &measure_out) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_proximity_cnt(sleep_pad, &proximity_cnt) ); + printf("touch slp smooth %d, base %d, proxi %d cnt %d status 0x%x\n", + smooth, touch_value, measure_out, proximity_cnt, touch_pad_get_status()); + } + } + + TEST_ESP_OK( touch_pad_deinit() ); + + return ret_val; +} + +TEST_CASE("Touch Sensor sleep pad and proximity interrupt test", "[touch]") +{ + ESP_LOGI(TAG, "*********** touch sleep pad interrupt test ********************"); + test_touch_sleep_pad_proximity(touch_list[0], false, 0); + test_touch_sleep_pad_proximity(touch_list[0], false, 0); + test_touch_sleep_pad_proximity(touch_list[0], false, 0); + + ESP_LOGI(TAG, "*********** touch sleep pad interrupt (proximity) test ********************"); + test_touch_sleep_pad_proximity(touch_list[0], true, 1); + test_touch_sleep_pad_proximity(touch_list[0], true, 3); + test_touch_sleep_pad_proximity(touch_list[0], true, 5); +} + +/* + * Test the touch sleep pad interrupt in normal mode. + * TEST POINT: + * 1. Touch sleep pad interrupt. + * 2. sleep pad reading. + * 3. denoise, waterproof + */ +esp_err_t test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_pad_t sleep_pad) +{ + uint32_t touch_value, smooth, raw; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + TEST_ESP_OK( touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL) ); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + // /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + TEST_ESP_OK( touch_pad_denoise_set_config(&denoise) ); + TEST_ESP_OK( touch_pad_denoise_disable() ); + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_16, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 3, // 0% + .noise_thr = 0, // 50% + .noise_neg_thr = 0, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_OFF, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Sleep channel setting */ + TEST_ESP_OK( touch_pad_sleep_channel_enable(sleep_pad, true) ); + TEST_ESP_OK( touch_pad_sleep_channel_enable_proximity(sleep_pad, false) ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + + // Initialize and start a software filter to detect slight change of capacitance. + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + /* Set threshold of touch sensor */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); + } + + /* Sleep channel setting */ + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &touch_value) ); + TEST_ESP_OK( touch_pad_sleep_set_threshold(sleep_pad, touch_value * TOUCH_INTR_THRESHOLD) ); + + vTaskDelay(50 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + test_touch_push_all(); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("push"); + TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &smooth) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_data(sleep_pad, &raw) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &touch_value) ); + printf("touch slp raw %d, smooth %d, base %d, status 0x%x\n", raw, smooth, touch_value, touch_pad_get_status()); + + test_touch_release_all(); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &smooth) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_data(sleep_pad, &raw) ); + TEST_ESP_OK( touch_pad_sleep_channel_read_baseline(sleep_pad, &touch_value) ); + printf("touch slp raw %d, smooth %d, base %d, status 0x%x\n", raw, smooth, touch_value, touch_pad_get_status()); + + return ESP_OK; +} + +#include +#include "esp_sleep.h" + +static RTC_DATA_ATTR struct timeval sleep_enter_time; + +static void test_deep_sleep_init(void) +{ + struct timeval now; + gettimeofday(&now, NULL); + int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; + printf("RTC_CNTL_SLP_WAKEUP_CAUSE_REG %x\n", REG_READ(RTC_CNTL_SLP_WAKEUP_CAUSE_REG)); + switch (esp_sleep_get_wakeup_cause()) { + case ESP_SLEEP_WAKEUP_EXT1: { + uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); + if (wakeup_pin_mask != 0) { + int pin = __builtin_ffsll(wakeup_pin_mask) - 1; + printf("Wake up from GPIO %d\n", pin); + } else { + printf("Wake up from GPIO\n"); + } + break; + } + case ESP_SLEEP_WAKEUP_TIMER: { + printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms); + break; + } + case ESP_SLEEP_WAKEUP_TOUCHPAD: { + printf("Wake up from touch on pad %d\n", esp_sleep_get_touchpad_wakeup_status()); + break; + } + case ESP_SLEEP_WAKEUP_UNDEFINED: + default: { + printf("Not a deep sleep reset\n"); + ESP_LOGI(TAG, "*********** touch sleep pad wakeup test ********************"); + /* Sleep pad should be init once. */ + test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_list[0]); + } + } + + vTaskDelay(100 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); + + printf("Enabling touch pad wakeup\n"); + esp_sleep_enable_touchpad_wakeup(); + + printf("Entering deep sleep\n"); + gettimeofday(&sleep_enter_time, NULL); +} + +TEST_CASE("Touch Sensor sleep pad wakeup deep sleep test", "[touch][ignore]") +{ + test_deep_sleep_init(); + + /* Change the work duty of touch sensor to reduce current. */ + touch_pad_set_meas_time(100, TOUCH_PAD_MEASURE_CYCLE_DEFAULT); + + /* Close PD current in deep sleep. */ + RTCCNTL.bias_conf.pd_cur_deep_slp = 1; + RTCCNTL.bias_conf.pd_cur_monitor = 1; + RTCCNTL.bias_conf.bias_sleep_deep_slp = 1; + RTCCNTL.bias_conf.bias_sleep_monitor = 1; + + esp_deep_sleep_start(); +} + +#include "touch_scope.h" +/* + * 0: 10 channels raw/smooth/baseline data debug. + * 1: 5 channges smooth + baseline data debug. + * 2: 1 channels filter data. + */ +#define SCOPE_DEBUG_TYPE 2 +#define TOUCH_THRESHOLD 0.5 +#define TOUCH_SHELD_PAD (1) +#define SCOPE_DEBUG_CHANNEL_MAX (10) +#define SCOPE_DEBUG_ENABLE (0) +#define SCOPE_UART_BUADRATE (256000) +#define SCOPE_DEBUG_FREQ_MS (50) + +void test_touch_slope_debug(int pad_num) +{ + touch_event_t evt; + uint32_t touch_value, smooth; + + ESP_LOGI(TAG, " >> %s << \n", __func__); + if (que_touch == NULL) { + que_touch = xQueueCreate(TEST_TOUCH_CHANNEL, sizeof(touch_event_t)); + /* Should register once. */ + touch_pad_isr_register(test_touch_intr_cb, NULL, TOUCH_PAD_INTR_MASK_ALL); + } else { + xQueueReset(que_touch); + } + TEST_ESP_OK( touch_pad_init() ); + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_config(touch_list[i]) ); + } + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_32, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 2, // 6.25% + .noise_thr = 3, // 50% + .noise_neg_thr = 3, // 50% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, + }; + TEST_ESP_OK( touch_pad_filter_set_config(&filter_info) ); + TEST_ESP_OK( touch_pad_filter_enable() ); + /* Register touch interrupt ISR, enable intr type. */ + TEST_ESP_OK( touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE) ); + TEST_ESP_OK( touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER) ); + TEST_ESP_OK( touch_pad_fsm_start() ); + /* Waterproof function */ + touch_pad_waterproof_t waterproof = { + .guard_ring_pad = 0, // If no ring pad, set 0; + /* It depends on the number of the parasitic capacitance of the shield pad. */ + .shield_driver = TOUCH_PAD_SHIELD_DRV_L2, //40pf + }; + TEST_ESP_OK( touch_pad_waterproof_set_config(&waterproof) ); + TEST_ESP_OK( touch_pad_waterproof_enable() ); + ESP_LOGI(TAG, "touch pad waterproof init"); + + // Initialize and start a software filter to detect slight change of capacitance. + vTaskDelay(50 / portTICK_PERIOD_MS); + + /* Set threshold of touch sensor */ + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + TEST_ESP_OK( touch_pad_filter_read_baseline(touch_list[i], &touch_value) ); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); + TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_THRESHOLD) ); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", \ + touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_THRESHOLD)); + } + + float scope_temp[SCOPE_DEBUG_CHANNEL_MAX] = {0}; // max scope channel is 10. + uint32_t scope_data[SCOPE_DEBUG_CHANNEL_MAX] = {0}; // max scope channel is 10. + test_tp_scope_debug_init(0, -1, -1, SCOPE_UART_BUADRATE); + +#if SCOPE_DEBUG_TYPE == 0 + while (1) { + for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { + touch_pad_read_raw_data(touch_list[i], &scope_data[i]); + // touch_pad_filter_read_smooth(touch_list[i], &scope_data[i]); + // touch_pad_filter_read_baseline(touch_list[i], &scope_data[i]); + scope_temp[i] = scope_data[i]; + } + test_tp_print_to_scope(scope_temp, TEST_TOUCH_CHANNEL); + vTaskDelay(SCOPE_DEBUG_FREQ_MS / portTICK_RATE_MS); + } +#elif SCOPE_DEBUG_TYPE == 1 + while (1) { + int cnt = 0; + for (int i = 0; i < 5; i++) { + touch_pad_read_raw_data(touch_list[i], &scope_data[i]); + scope_temp[i] = scope_data[i]; + } + for (int i = 0; i < 5; i++) { + touch_pad_filter_read_smooth(touch_list[i], &scope_data[i]); + scope_temp[i + SCOPE_DEBUG_CHANNEL_MAX / 2] = scope_data[i]; + } + test_tp_print_to_scope(scope_temp, SCOPE_DEBUG_CHANNEL_MAX); + vTaskDelay(SCOPE_DEBUG_FREQ_MS / portTICK_RATE_MS); + } +#elif SCOPE_DEBUG_TYPE == 2 + uint32_t status; + touch_pad_filter_read_baseline(pad_num, &status); + while (1) { + xQueueReceive(que_touch, &evt, SCOPE_DEBUG_FREQ_MS / portTICK_RATE_MS); + //read filtered value + touch_pad_read_raw_data(pad_num, &scope_data[0]); + touch_pad_filter_read_baseline(pad_num, &scope_data[1]); + touch_pad_get_thresh(pad_num, &scope_data[2]); + touch_pad_filter_read_smooth(pad_num, &scope_data[8]); + // raw data + scope_temp[0] = scope_data[0]; + // baseline + scope_temp[1] = scope_data[1]; + // smooth data + scope_temp[8] = scope_data[8]; + // noise neg thr + scope_temp[2] = scope_temp[1] - scope_data[2] * 0.5; + // noise thr + scope_temp[3] = scope_temp[1] + scope_data[2] * 0.5; + // touch thr + scope_temp[4] = scope_temp[1] + scope_data[2]; + // hysteresis_thr thr + scope_temp[5] = scope_temp[4] - scope_data[2] * 0.0625; + // hysteresis_thr thr + scope_temp[6] = scope_temp[4] + scope_data[2] * 0.0625; + // touch status + if (touch_pad_get_status() & BIT(pad_num)) { + scope_temp[7] = status + 100; + } else { + scope_temp[7] = status - 100; //0:release; 1:push; + } + test_tp_print_to_scope(scope_temp, 9); + } +#elif SCOPE_DEBUG_TYPE == 3 + while (1) { + test_touch_push_all(); + TEST_ESP_OK( test_touch_check_ch_touched(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("push"); + + /* Test: if the raw data exceed noise threshold, the baseline should not be updated. */ + test_touch_baseline_not_update(); + + test_touch_release_all(); + TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); + printf_touch_hw_read("release"); + } +#endif + TEST_ESP_OK( touch_pad_deinit() ); +} + +#endif // !DISABLED_FOR_TARGETS(ESP8266, ESP32) \ No newline at end of file diff --git a/components/driver/test/touch_sensor_test/touch_scope.c b/components/driver/test/touch_sensor_test/touch_scope.c new file mode 100644 index 000000000..d30e3d173 --- /dev/null +++ b/components/driver/test/touch_sensor_test/touch_scope.c @@ -0,0 +1,196 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "esp_err.h" +#include "driver/uart.h" +#include "esp32s2/rom/uart.h" + +#define ROM_UART_DRIVER_ENABLE 0 + +#if ROM_UART_DRIVER_ENABLE +static uint8_t scope_uart_num = 0; +static int8_t uart_used = 0; +#else +static uint8_t scope_uart_num = 255; +static int8_t uart_used = -1; +#endif +static int scope_tx_io_num = 0; +static int scope_rx_io_num = 0; +static int scope_debug_baud_rate = 256000; +static unsigned char datascope_output_buffer[42] = {0}; // Data buff. + +/** + * @brief Translate a float data to four unsigned char data for uart TX. + * @param target target float data address. + * @param buf save translated data. + * @param offset the start position in buf. + * @return + * - void + */ +static void float_to_byte(float *target, unsigned char *buf, unsigned char offset) +{ + memcpy(buf + offset, (uint8_t*)target, 4); +} + +/** + * @brief Add data to channel buff. + * @param Data target data. + * @param Channel target channel (1 - 10). + * @return + * - void + */ +static void datascope_get_channel_data(float data, unsigned char channel) +{ + if ( (channel > 10) || (channel == 0) ) { + return; + } else { + switch (channel) { + case 1: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 2: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 3: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 4: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 5: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 6: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 7: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 8: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 9: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + case 10: float_to_byte(&data,datascope_output_buffer, channel*4-3); break; + } + } +} + +/** + * @brief Transform float data to DataScopeV1.0 data format. + * @param channel_num the number of channel that wait to be translated. + * @return + * - The number of the UART TX data. + */ +static unsigned char datascope_data_generate(unsigned char channel_num) +{ + if ( (channel_num > 10) || (channel_num == 0) ) { + return 0; + } else { + datascope_output_buffer[0] = '$'; //frame header + switch(channel_num) { + case 1: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 2: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 3: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 4: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 5: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 6: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 7: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 8: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 9: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + case 10: datascope_output_buffer[channel_num*4+1] = channel_num*4+1; return channel_num*4+2; break; + } + } + return 0; +} + +/** + * @brief Send touch sensor data to HMI in PC via UART. + * @param uart_num Choose uart port (0, 1). + * @param data The addr of the touch sensor data. + * @param channel_num The number of channel that wait to be translated. + * @return + * - ESP_FAIL Error + * - The number of the UART TX data. + */ +int test_tp_print_to_scope(float *data, unsigned char channel_num) +{ + uint8_t uart_num = scope_uart_num; + + if (uart_num >= UART_NUM_MAX) { + return ESP_FAIL; + } + if ( (channel_num > 10) || (channel_num == 0) || (NULL == data) ) { + return ESP_FAIL; + } + for(uint8_t i = 0 ; i < channel_num; i++) { + datascope_get_channel_data(data[i] , i+1); // write data x into channel 1~10. + } + unsigned char out_len = datascope_data_generate(channel_num); // Generate n number data. + unsigned char *out_data = datascope_output_buffer; + // Init uart. + if(uart_num != uart_used) { + return 0; + } else { +#if ROM_UART_DRIVER_ENABLE + uart_tx_wait_idle(uart_num); // Default print uart mumber is 0. + for(int i=0; i= UART_NUM_MAX) { + return ESP_FAIL; + } + scope_uart_num = uart_num; + scope_tx_io_num = tx_io_num; + scope_rx_io_num = rx_io_num; + scope_debug_baud_rate = baud_rate; + uart_config_t uart_config = { + .baud_rate = scope_debug_baud_rate, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + }; + uart_param_config(uart_num, &uart_config); + // Set UART pins using UART0 default pins i.e. no changes + uart_set_pin(uart_num, scope_tx_io_num, scope_rx_io_num, + UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + uart_driver_install(uart_num, 1024, 2048, 0, NULL, 0); + uart_used = uart_num; +#endif + return ESP_OK; +} diff --git a/components/driver/test/touch_sensor_test/touch_scope.h b/components/driver/test/touch_sensor_test/touch_scope.h new file mode 100644 index 000000000..b9a47f5f3 --- /dev/null +++ b/components/driver/test/touch_sensor_test/touch_scope.h @@ -0,0 +1,31 @@ +// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +/** + * @brief Send data info to digital scope. + * @param data Pointer to send buff. + * @param channel_num The number of channels to be displayed. + * @return the length of successfully transmitted data. + */ +int test_tp_print_to_scope(float *data, unsigned char channel_num); + +/** + * @brief Initialize the UART so that the touch sensor data is output to the digital scope. + * @return + * - ESP_OK Success + * - ESP_FAIL UART error + */ +esp_err_t test_tp_scope_debug_init(uint8_t uart_num, int tx_io_num, int rx_io_num, int baud_rate); \ No newline at end of file diff --git a/components/esp32s2/sleep_modes.c b/components/esp32s2/sleep_modes.c index b209646b4..5acee19af 100644 --- a/components/esp32s2/sleep_modes.c +++ b/components/esp32s2/sleep_modes.c @@ -96,6 +96,7 @@ static uint32_t get_power_down_flags(void); static void ext0_wakeup_prepare(void); static void ext1_wakeup_prepare(void); static void timer_wakeup_prepare(void); +static void touch_wakeup_prepare(void); /* Wake from deep sleep stub See esp_deepsleep.h esp_wake_deep_sleep() comments for details. @@ -188,6 +189,10 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags) if (s_config.wakeup_triggers & RTC_ULP_TRIG_EN) { // no-op for esp32s2 } + // Enable Touch wakeup + if (s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) { + touch_wakeup_prepare(); + } // Enter sleep rtc_sleep_config_t config = RTC_SLEEP_CONFIG_DEFAULT(pd_flags); @@ -409,6 +414,17 @@ static void timer_wakeup_prepare(void) SET_PERI_REG_MASK(RTC_CNTL_SLP_TIMER1_REG, RTC_CNTL_MAIN_TIMER_ALARM_EN_M); } +/* In deep sleep mode, only the sleep channel is supported, and other touch channels should be turned off. */ +static void touch_wakeup_prepare(void) +{ + touch_pad_sleep_channel_t slp_config; + touch_pad_fsm_stop(); + touch_pad_clear_channel_mask(SOC_TOUCH_SENSOR_BIT_MASK_MAX); + touch_pad_sleep_channel_get_info(&slp_config); + touch_pad_set_channel_mask(BIT(slp_config.touch_num)); + touch_pad_fsm_start(); +} + esp_err_t esp_sleep_enable_touchpad_wakeup(void) { if (s_config.wakeup_triggers & (RTC_EXT0_TRIG_EN)) { @@ -572,7 +588,7 @@ esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void) return ESP_SLEEP_WAKEUP_UNDEFINED; } - uint32_t wakeup_cause = REG_GET_FIELD(RTC_CNTL_WAKEUP_STATE_REG, RTC_CNTL_WAKEUP_CAUSE); + uint32_t wakeup_cause = REG_GET_FIELD(RTC_CNTL_SLP_WAKEUP_CAUSE_REG, RTC_CNTL_WAKEUP_CAUSE); if (wakeup_cause & RTC_EXT0_TRIG_EN) { return ESP_SLEEP_WAKEUP_EXT0; } else if (wakeup_cause & RTC_EXT1_TRIG_EN) { diff --git a/components/soc/include/hal/touch_sensor_hal.h b/components/soc/include/hal/touch_sensor_hal.h index db64bac87..a2ad36946 100644 --- a/components/soc/include/hal/touch_sensor_hal.h +++ b/components/soc/include/hal/touch_sensor_hal.h @@ -33,7 +33,7 @@ typedef struct { touch_high_volt_t refh; touch_low_volt_t refl; touch_volt_atten_t atten; -}touch_hal_volt_t; +} touch_hal_volt_t; typedef struct { touch_cnt_slope_t slope; /*! (touch threshold + hysteresis), the touch channel be touched. If (raw data - baseline) < (touch threshold - hysteresis), the touch channel be released. - Range: 0 ~ 3. The coefficient is 0: 1/8; 1: 3/32; 2: 1/16; 3: 1/32 */ - uint32_t noise_thr; /*! (noise), the baseline stop updating. If (raw data - baseline) < (noise), the baseline start updating. - Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; */ - uint32_t noise_neg_thr; /*! (negative noise), the baseline restart reset process(refer to `baseline_reset`). If (baseline - raw data) < (negative noise), the baseline stop reset process(refer to `baseline_reset`). - Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; */ - uint32_t neg_noise_limit; /*! - #ifdef __cplusplus extern "C" { #endif @@ -37,15 +34,8 @@ typedef volatile struct { uint32_t bbpll_force_pu: 1; /*BB_PLL force power up*/ uint32_t xtl_force_pd: 1; /*crystall force power down*/ uint32_t xtl_force_pu: 1; /*crystall force power up*/ - uint32_t bias_sleep_folw_8m: 1; /*BIAS_SLEEP follow CK8M*/ - uint32_t bias_force_sleep: 1; /*BIAS_SLEEP force sleep*/ - uint32_t bias_force_nosleep: 1; /*BIAS_SLEEP force no sleep*/ - uint32_t bias_i2c_folw_8m: 1; /*BIAS_I2C follow CK8M*/ - uint32_t bias_i2c_force_pd: 1; /*BIAS_I2C force power down*/ - uint32_t bias_i2c_force_pu: 1; /*BIAS_I2C force power up*/ - uint32_t bias_core_folw_8m: 1; /*BIAS_CORE follow CK8M*/ - uint32_t bias_core_force_pd: 1; /*BIAS_CORE force power down*/ - uint32_t bias_core_force_pu: 1; /*BIAS_CORE force power up*/ + uint32_t xtl_en_wait: 4; /*wait bias_sleep and current source wakeup*/ + uint32_t reserved18: 5; uint32_t xtl_force_iso: 1; uint32_t pll_force_iso: 1; uint32_t analog_force_iso: 1; @@ -155,16 +145,21 @@ typedef volatile struct { } timer6; union { struct { - uint32_t reserved0: 23; - uint32_t plla_force_pd: 1; /*PLLA force power down*/ - uint32_t plla_force_pu: 1; /*PLLA force power up*/ - uint32_t bbpll_cal_slp_start: 1; /*start BBPLL calibration during sleep*/ - uint32_t pvtmon_pu: 1; /*1: PVTMON power up otherwise power down*/ - uint32_t txrf_i2c_pu: 1; /*1: TXRF_I2C power up otherwise power down*/ - uint32_t rfrx_pbus_pu: 1; /*1: RFRX_PBUS power up otherwise power down*/ - uint32_t reserved29: 1; - uint32_t ckgen_i2c_pu: 1; /*1: CKGEN_I2C power up otherwise power down*/ - uint32_t pll_i2c_pu: 1; + uint32_t reserved0: 18; + uint32_t i2c_reset_por_force_pd: 1; + uint32_t i2c_reset_por_force_pu: 1; + uint32_t glitch_rst_en: 1; + uint32_t sar_i2c_force_pd: 1; /*PLLA force power down*/ + uint32_t sar_i2c_force_pu: 1; /*PLLA force power up*/ + uint32_t plla_force_pd: 1; /*PLLA force power down*/ + uint32_t plla_force_pu: 1; /*PLLA force power up*/ + uint32_t bbpll_cal_slp_start: 1; /*start BBPLL calibration during sleep*/ + uint32_t pvtmon_pu: 1; /*1: PVTMON power up otherwise power down*/ + uint32_t txrf_i2c_pu: 1; /*1: TXRF_I2C power up otherwise power down*/ + uint32_t rfrx_pbus_pu: 1; /*1: RFRX_PBUS power up otherwise power down*/ + uint32_t reserved29: 1; + uint32_t ckgen_i2c_pu: 1; /*1: CKGEN_I2C power up otherwise power down*/ + uint32_t pll_i2c_pu: 1; }; uint32_t val; } ana_conf; @@ -180,106 +175,112 @@ typedef volatile struct { } reset_state; union { struct { - uint32_t wakeup_cause: 15; /*wakeup cause*/ - uint32_t rtc_wakeup_ena: 15; /*wakeup enable bitmap*/ - uint32_t gpio_wakeup_filter: 1; /*enable filter for gpio wakeup event*/ - uint32_t reserved31: 1; + uint32_t reserved0: 15; + uint32_t rtc_wakeup_ena:17; /*wakeup enable bitmap*/ }; uint32_t val; } wakeup_state; union { struct { - uint32_t slp_wakeup: 1; /*enable sleep wakeup interrupt*/ - uint32_t slp_reject: 1; /*enable sleep reject interrupt*/ - uint32_t sdio_idle: 1; /*enable SDIO idle interrupt*/ - uint32_t rtc_wdt: 1; /*enable RTC WDT interrupt*/ - uint32_t reserved4: 1; - uint32_t rtc_ulp_cp: 1; /*enable ULP-coprocessor interrupt*/ - uint32_t rtc_touch_done: 1; /*enable touch done interrupt*/ - uint32_t rtc_touch_active: 1; /*enable touch active interrupt*/ - uint32_t rtc_touch_inactive: 1; /*enable touch inactive interrupt*/ - uint32_t rtc_brown_out: 1; /*enable brown out interrupt*/ - uint32_t rtc_main_timer: 1; /*enable RTC main timer interrupt*/ - uint32_t rtc_saradc1: 1; /*enable saradc1 interrupt*/ - uint32_t rtc_tsens: 1; /*enable tsens interrupt*/ - uint32_t rtc_cocpu: 1; /*enable riscV cocpu interrupt*/ - uint32_t rtc_saradc2: 1; /*enable saradc2 interrupt*/ - uint32_t rtc_swd: 1; /*enable super watch dog interrupt*/ - uint32_t rtc_xtal32k_dead: 1; /*enable cocpu trap interrupt*/ - uint32_t rtc_cocpu_trap: 1; - uint32_t reserved18: 14; + uint32_t slp_wakeup: 1; /*enable sleep wakeup interrupt*/ + uint32_t slp_reject: 1; /*enable sleep reject interrupt*/ + uint32_t sdio_idle: 1; /*enable SDIO idle interrupt*/ + uint32_t rtc_wdt: 1; /*enable RTC WDT interrupt*/ + uint32_t rtc_touch_scan_done: 1; /*enable touch scan done interrupt*/ + uint32_t rtc_ulp_cp: 1; /*enable ULP-coprocessor interrupt*/ + uint32_t rtc_touch_done: 1; /*enable touch done interrupt*/ + uint32_t rtc_touch_active: 1; /*enable touch active interrupt*/ + uint32_t rtc_touch_inactive: 1; /*enable touch inactive interrupt*/ + uint32_t rtc_brown_out: 1; /*enable brown out interrupt*/ + uint32_t rtc_main_timer: 1; /*enable RTC main timer interrupt*/ + uint32_t rtc_saradc1: 1; /*enable saradc1 interrupt*/ + uint32_t rtc_tsens: 1; /*enable tsens interrupt*/ + uint32_t rtc_cocpu: 1; /*enable riscV cocpu interrupt*/ + uint32_t rtc_saradc2: 1; /*enable saradc2 interrupt*/ + uint32_t rtc_swd: 1; /*enable super watch dog interrupt*/ + uint32_t rtc_xtal32k_dead: 1; /*enable xtal32k_dead interrupt*/ + uint32_t rtc_cocpu_trap: 1; /*enable cocpu trap interrupt*/ + uint32_t rtc_touch_timeout: 1; /*enable touch timeout interrupt*/ + uint32_t rtc_glitch_det: 1; /*enbale gitch det interrupt*/ + uint32_t reserved20: 12; }; uint32_t val; } int_ena; union { struct { - uint32_t slp_wakeup: 1; /*sleep wakeup interrupt raw*/ - uint32_t slp_reject: 1; /*sleep reject interrupt raw*/ - uint32_t sdio_idle: 1; /*SDIO idle interrupt raw*/ - uint32_t rtc_wdt: 1; /*RTC WDT interrupt raw*/ - uint32_t reserved4: 1; - uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt raw*/ - uint32_t rtc_touch_done: 1; /*touch interrupt raw*/ - uint32_t rtc_touch_active: 1; /*touch active interrupt raw*/ - uint32_t rtc_touch_inactive: 1; /*touch inactive interrupt raw*/ - uint32_t rtc_brown_out: 1; /*brown out interrupt raw*/ - uint32_t rtc_main_timer: 1; /*RTC main timer interrupt raw*/ - uint32_t rtc_saradc1: 1; /*saradc1 interrupt raw*/ - uint32_t rtc_tsens: 1; /*tsens interrupt raw*/ - uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt raw*/ - uint32_t rtc_saradc2: 1; /*saradc2 interrupt raw*/ - uint32_t rtc_swd: 1; /*super watch dog interrupt raw*/ - uint32_t rtc_xtal32k_dead: 1; /*xtal32k dead detection interrupt raw*/ - uint32_t rtc_cocpu_trap: 1; /*cocpu trap interrupt raw*/ - uint32_t reserved18: 14; + uint32_t slp_wakeup: 1; /*sleep wakeup interrupt raw*/ + uint32_t slp_reject: 1; /*sleep reject interrupt raw*/ + uint32_t sdio_idle: 1; /*SDIO idle interrupt raw*/ + uint32_t rtc_wdt: 1; /*RTC WDT interrupt raw*/ + uint32_t rtc_touch_scan_done: 1; + uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt raw*/ + uint32_t rtc_touch_done: 1; /*touch interrupt raw*/ + uint32_t rtc_touch_active: 1; /*touch active interrupt raw*/ + uint32_t rtc_touch_inactive: 1; /*touch inactive interrupt raw*/ + uint32_t rtc_brown_out: 1; /*brown out interrupt raw*/ + uint32_t rtc_main_timer: 1; /*RTC main timer interrupt raw*/ + uint32_t rtc_saradc1: 1; /*saradc1 interrupt raw*/ + uint32_t rtc_tsens: 1; /*tsens interrupt raw*/ + uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt raw*/ + uint32_t rtc_saradc2: 1; /*saradc2 interrupt raw*/ + uint32_t rtc_swd: 1; /*super watch dog interrupt raw*/ + uint32_t rtc_xtal32k_dead: 1; /*xtal32k dead detection interrupt raw*/ + uint32_t rtc_cocpu_trap: 1; /*cocpu trap interrupt raw*/ + uint32_t rtc_touch_timeout: 1; /*touch timeout interrupt raw*/ + uint32_t rtc_glitch_det: 1; /*glitch_det_interrupt_raw*/ + uint32_t reserved20: 12; }; uint32_t val; } int_raw; union { struct { - uint32_t slp_wakeup: 1; /*sleep wakeup interrupt state*/ - uint32_t slp_reject: 1; /*sleep reject interrupt state*/ - uint32_t sdio_idle: 1; /*SDIO idle interrupt state*/ - uint32_t rtc_wdt: 1; /*RTC WDT interrupt state*/ - uint32_t reserved4: 1; - uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt state*/ - uint32_t rtc_touch_done: 1; /*touch done interrupt state*/ - uint32_t rtc_touch_active: 1; /*touch active interrupt state*/ - uint32_t rtc_touch_inactive: 1; /*touch inactive interrupt state*/ - uint32_t rtc_brown_out: 1; /*brown out interrupt state*/ - uint32_t rtc_main_timer: 1; /*RTC main timer interrupt state*/ - uint32_t rtc_saradc1: 1; /*saradc1 interrupt state*/ - uint32_t rtc_tsens: 1; /*tsens interrupt state*/ - uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt state*/ - uint32_t rtc_saradc2: 1; /*saradc2 interrupt state*/ - uint32_t rtc_swd: 1; /*super watch dog interrupt state*/ - uint32_t rtc_xtal32k_dead: 1; /*xtal32k dead detection interrupt state*/ - uint32_t rtc_cocpu_trap: 1; /*cocpu trap interrupt state*/ - uint32_t reserved18: 14; + uint32_t slp_wakeup: 1; /*sleep wakeup interrupt state*/ + uint32_t slp_reject: 1; /*sleep reject interrupt state*/ + uint32_t sdio_idle: 1; /*SDIO idle interrupt state*/ + uint32_t rtc_wdt: 1; /*RTC WDT interrupt state*/ + uint32_t rtc_touch_scan_done: 1; + uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt state*/ + uint32_t rtc_touch_done: 1; /*touch done interrupt state*/ + uint32_t rtc_touch_active: 1; /*touch active interrupt state*/ + uint32_t rtc_touch_inactive: 1; /*touch inactive interrupt state*/ + uint32_t rtc_brown_out: 1; /*brown out interrupt state*/ + uint32_t rtc_main_timer: 1; /*RTC main timer interrupt state*/ + uint32_t rtc_saradc1: 1; /*saradc1 interrupt state*/ + uint32_t rtc_tsens: 1; /*tsens interrupt state*/ + uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt state*/ + uint32_t rtc_saradc2: 1; /*saradc2 interrupt state*/ + uint32_t rtc_swd: 1; /*super watch dog interrupt state*/ + uint32_t rtc_xtal32k_dead: 1; /*xtal32k dead detection interrupt state*/ + uint32_t rtc_cocpu_trap: 1; /*cocpu trap interrupt state*/ + uint32_t rtc_touch_timeout: 1; /*Touch timeout interrupt state*/ + uint32_t rtc_glitch_det: 1; /*glitch_det_interrupt state*/ + uint32_t reserved20: 12; }; uint32_t val; } int_st; union { struct { - uint32_t slp_wakeup: 1; /*Clear sleep wakeup interrupt state*/ - uint32_t slp_reject: 1; /*Clear sleep reject interrupt state*/ - uint32_t sdio_idle: 1; /*Clear SDIO idle interrupt state*/ - uint32_t rtc_wdt: 1; /*Clear RTC WDT interrupt state*/ - uint32_t reserved4: 1; - uint32_t rtc_ulp_cp: 1; /*Clear ULP-coprocessor interrupt state*/ - uint32_t rtc_touch_done: 1; /*Clear touch done interrupt state*/ - uint32_t rtc_touch_active: 1; /*Clear touch active interrupt state*/ - uint32_t rtc_touch_inactive: 1; /*Clear touch inactive interrupt state*/ - uint32_t rtc_brown_out: 1; /*Clear brown out interrupt state*/ - uint32_t rtc_main_timer: 1; /*Clear RTC main timer interrupt state*/ - uint32_t rtc_saradc1: 1; /*Clear saradc1 interrupt state*/ - uint32_t rtc_tsens: 1; /*Clear tsens interrupt state*/ - uint32_t rtc_cocpu: 1; /*Clear riscV cocpu interrupt state*/ - uint32_t rtc_saradc2: 1; /*Clear saradc2 interrupt state*/ - uint32_t rtc_swd: 1; /*Clear super watch dog interrupt state*/ - uint32_t rtc_xtal32k_dead: 1; /*Clear RTC WDT interrupt state*/ - uint32_t rtc_cocpu_trap: 1; /*Clear cocpu trap interrupt state*/ - uint32_t reserved18: 14; + uint32_t slp_wakeup: 1; /*Clear sleep wakeup interrupt state*/ + uint32_t slp_reject: 1; /*Clear sleep reject interrupt state*/ + uint32_t sdio_idle: 1; /*Clear SDIO idle interrupt state*/ + uint32_t rtc_wdt: 1; /*Clear RTC WDT interrupt state*/ + uint32_t rtc_touch_scan_done: 1; + uint32_t rtc_ulp_cp: 1; /*Clear ULP-coprocessor interrupt state*/ + uint32_t rtc_touch_done: 1; /*Clear touch done interrupt state*/ + uint32_t rtc_touch_active: 1; /*Clear touch active interrupt state*/ + uint32_t rtc_touch_inactive: 1; /*Clear touch inactive interrupt state*/ + uint32_t rtc_brown_out: 1; /*Clear brown out interrupt state*/ + uint32_t rtc_main_timer: 1; /*Clear RTC main timer interrupt state*/ + uint32_t rtc_saradc1: 1; /*Clear saradc1 interrupt state*/ + uint32_t rtc_tsens: 1; /*Clear tsens interrupt state*/ + uint32_t rtc_cocpu: 1; /*Clear riscV cocpu interrupt state*/ + uint32_t rtc_saradc2: 1; /*Clear saradc2 interrupt state*/ + uint32_t rtc_swd: 1; /*Clear super watch dog interrupt state*/ + uint32_t rtc_xtal32k_dead: 1; /*Clear RTC WDT interrupt state*/ + uint32_t rtc_cocpu_trap: 1; /*Clear cocpu trap interrupt state*/ + uint32_t rtc_touch_timeout: 1; /*Clear touch timeout interrupt state*/ + uint32_t rtc_glitch_det: 1; /*Clear glitch det interrupt state*/ + uint32_t reserved20: 12; }; uint32_t val; } int_clr; @@ -299,7 +300,8 @@ typedef volatile struct { uint32_t dgm_xtal_32k: 3; /*xtal_32k gm control*/ uint32_t dres_xtal_32k: 3; /*DRES_XTAL_32K*/ uint32_t xpd_xtal_32k: 1; /*XPD_XTAL_32K*/ - uint32_t dac_xtal_32k: 6; /*DAC_XTAL_32K*/ + uint32_t dac_xtal_32k: 3; /*DAC_XTAL_32K*/ + uint32_t rtc_wdt_state: 3; /*state of 32k_wdt*/ uint32_t rtc_xtal32k_gpio_sel: 1; /*XTAL_32K sel. 0: external XTAL_32K 1: CLK from RTC pad X32P_C*/ uint32_t reserved24: 6; uint32_t ctr_lv: 1; /*0: power down XTAL at high level 1: power down XTAL at low level*/ @@ -309,16 +311,17 @@ typedef volatile struct { } ext_xtl_conf; union { struct { - uint32_t reserved0: 30; - uint32_t wakeup0_lv: 1; /*0: external wakeup at low level 1: external wakeup at high level*/ - uint32_t wakeup1_lv: 1; + uint32_t reserved0: 29; + uint32_t gpio_wakeup_filter: 1; /*enable filter for gpio wakeup event*/ + uint32_t wakeup0_lv: 1; /*0: external wakeup at low level 1: external wakeup at high level*/ + uint32_t wakeup1_lv: 1; }; uint32_t val; } ext_wakeup_conf; union { struct { - uint32_t reject_cause: 15; /*sleep reject cause*/ - uint32_t rtc_sleep_reject_ena:15; /*sleep reject enable*/ + uint32_t reserved0: 13; + uint32_t rtc_sleep_reject_ena:17; /*sleep reject enable*/ uint32_t light_slp_reject_en: 1; /*enable reject for light sleep*/ uint32_t deep_slp_reject_en: 1; /*enable reject for deep sleep*/ }; @@ -395,8 +398,17 @@ typedef volatile struct { } sdio_conf; union { struct { - uint32_t reserved0: 22; - uint32_t dbg_atten: 4; /*DBG_ATTEN*/ + uint32_t reserved0: 10; + uint32_t bias_buf_idle: 1; + uint32_t bias_buf_wake: 1; + uint32_t bias_buf_deep_slp: 1; + uint32_t bias_buf_monitor: 1; + uint32_t pd_cur_deep_slp: 1; /*xpd cur when rtc in sleep_state*/ + uint32_t pd_cur_monitor: 1; /*xpd cur when rtc in monitor state*/ + uint32_t bias_sleep_deep_slp: 1; /*bias_sleep when rtc in sleep_state*/ + uint32_t bias_sleep_monitor: 1; /*bias_sleep when rtc in monitor state*/ + uint32_t dbg_atten_deep_slp: 4; /*DBG_ATTEN when rtc in sleep state*/ + uint32_t dbg_atten_monitor: 4; /*DBG_ATTEN when rtc in monitor state*/ uint32_t enb_sck_xtal: 1; /*ENB_SCK_XTAL*/ uint32_t inc_heartbeat_refresh: 1; /*INC_HEARTBEAT_REFRESH*/ uint32_t dec_heartbeat_period: 1; /*DEC_HEARTBEAT_PERIOD*/ @@ -659,7 +671,8 @@ typedef volatile struct { uint32_t pd_rf_ena: 1; /*enable power down RF when brown out happens*/ uint32_t rst_wait: 10; /*brown out reset wait cycles*/ uint32_t rst_ena: 1; /*enable brown out reset*/ - uint32_t reserved27: 2; + uint32_t rst_sel: 1; /*1: 4-pos reset*/ + uint32_t reserved28: 1; uint32_t cnt_clr: 1; /*clear brown out counter*/ uint32_t ena: 1; /*enable brown out*/ uint32_t det: 1; @@ -687,9 +700,7 @@ typedef volatile struct { union { struct { uint32_t ulp_cp_pc_init: 11; /*ULP-coprocessor PC initial address*/ - uint32_t reserved11: 1; - uint32_t ulp_cp_timer_slp_cycle:16; /*sleep cycles for ULP-coprocessor timer*/ - uint32_t reserved28: 1; + uint32_t reserved11: 18; uint32_t ulp_cp_gpio_wakeup_ena: 1; /*ULP-coprocessor wakeup by GPIO enable*/ uint32_t ulp_cp_gpio_wakeup_clr: 1; /*ULP-coprocessor wakeup by GPIO state clear*/ uint32_t ulp_cp_slp_timer_en: 1; /*ULP-coprocessor timer enable bit*/ @@ -715,13 +726,13 @@ typedef volatile struct { uint32_t cocpu_start_2_reset_dis: 6; /*time from start cocpu to pull down reset*/ uint32_t cocpu_start_2_intr_en: 6; /*time from start cocpu to give start interrupt*/ uint32_t cocpu_shut: 1; /*to shut cocpu*/ - uint32_t cocpu_shut_2_clk_dis: 6; /*time from shut cocpu to disable clk*/ + uint32_t cocpu_shut_2_clk_dis: 8; /*time from shut cocpu to disable clk*/ uint32_t cocpu_shut_reset_en: 1; /*to reset cocpu*/ uint32_t cocpu_sel: 1; /*1: old ULP 0: new riscV*/ uint32_t cocpu_done_force: 1; /*1: select riscv done 0: select ulp done*/ uint32_t cocpu_done: 1; /*done signal used by riscv to control timer.*/ uint32_t cocpu_sw_int_trigger: 1; /*trigger cocpu register interrupt*/ - uint32_t reserved25: 7; + uint32_t reserved27: 5; }; uint32_t val; } cocpu_ctrl; @@ -734,23 +745,23 @@ typedef volatile struct { } touch_ctrl1; union { struct { - uint32_t reserved0: 2; - uint32_t touch_drange: 2; /*TOUCH_DRANGE*/ - uint32_t touch_drefl: 2; /*TOUCH_DREFL*/ - uint32_t touch_drefh: 2; /*TOUCH_DREFH*/ - uint32_t touch_xpd_bias: 1; /*TOUCH_XPD_BIAS*/ - uint32_t touch_refc: 3; /*TOUCH pad0 reference cap*/ - uint32_t reserved12: 1; - uint32_t touch_slp_timer_en: 1; /*touch timer enable bit*/ - uint32_t touch_start_fsm_en: 1; /*1: TOUCH_START & TOUCH_XPD is controlled by touch fsm*/ - uint32_t touch_start_en: 1; /*1: start touch fsm*/ - uint32_t touch_start_force: 1; /*1: to start touch fsm by SW*/ - uint32_t touch_xpd_wait: 8; /*the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD*/ - uint32_t touch_slp_cyc_div: 2; /*when a touch pad is active sleep cycle could be divided by this number*/ - uint32_t reserved27: 2; - uint32_t touch_reset: 1; /*reset upgrade touch*/ - uint32_t touch_clk_fo: 1; /*touch clock force on*/ - uint32_t touch_clkgate_en: 1; /*touch clock enable*/ + uint32_t reserved0: 2; + uint32_t touch_drange: 2; /*TOUCH_DRANGE*/ + uint32_t touch_drefl: 2; /*TOUCH_DREFL*/ + uint32_t touch_drefh: 2; /*TOUCH_DREFH*/ + uint32_t touch_xpd_bias: 1; /*TOUCH_XPD_BIAS*/ + uint32_t touch_refc: 3; /*TOUCH pad0 reference cap*/ + uint32_t touch_dbias: 1; /*1:use self bias 0:use bandgap bias*/ + uint32_t touch_slp_timer_en: 1; /*touch timer enable bit*/ + uint32_t touch_start_fsm_en: 1; /*1: TOUCH_START & TOUCH_XPD is controlled by touch fsm*/ + uint32_t touch_start_en: 1; /*1: start touch fsm*/ + uint32_t touch_start_force: 1; /*1: to start touch fsm by SW*/ + uint32_t touch_xpd_wait: 8; /*the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD*/ + uint32_t touch_slp_cyc_div: 2; /*when a touch pad is active sleep cycle could be divided by this number*/ + uint32_t touch_timer_force_done: 2; /*force touch timer done*/ + uint32_t touch_reset: 1; /*reset upgrade touch*/ + uint32_t touch_clk_fo: 1; /*touch clock force on*/ + uint32_t touch_clkgate_en: 1; /*touch clock enable*/ }; uint32_t val; } touch_ctrl2; @@ -786,14 +797,15 @@ typedef volatile struct { } touch_approach; union { struct { - uint32_t reserved0: 12; + uint32_t reserved0: 9; + uint32_t touch_smooth_lvl: 2; uint32_t touch_jitter_step: 4; /*touch jitter step*/ uint32_t touch_neg_noise_limit: 4; /*negative threshold counter limit*/ uint32_t touch_neg_noise_thres: 2; uint32_t touch_noise_thres: 2; uint32_t touch_hysteresis: 2; uint32_t touch_debounce: 3; /*debounce counter*/ - uint32_t touch_filter_mode: 2; /*0: IIR ? 1: IIR ? 2: IIR 1/8 3: Jitter*/ + uint32_t touch_filter_mode: 3; /*0: IIR ? 1: IIR ? 2: IIR 1/8 3: Jitter*/ uint32_t touch_filter_en: 1; /*touch filter enable*/ }; uint32_t val; @@ -821,8 +833,21 @@ typedef volatile struct { }; uint32_t val; } usb_conf; - uint32_t reserved_124; - uint32_t reserved_128; + union { + struct { + uint32_t touch_timeout_num:22; + uint32_t touch_timeout_en: 1; + uint32_t reserved23: 9; + }; + uint32_t val; + } touch_timeout_ctrl; + union { + struct { + uint32_t reject_cause:17; /*sleep reject cause*/ + uint32_t reserved17: 15; + }; + uint32_t val; + } slp_reject_cause; union { struct { uint32_t force_download_boot: 1; @@ -830,6 +855,21 @@ typedef volatile struct { }; uint32_t val; } option1; + union { + struct { + uint32_t wakeup_cause:17; /*sleep wakeup cause*/ + uint32_t reserved17: 15; + }; + uint32_t val; + } slp_wakeup_cause; + union { + struct { + uint32_t reserved0: 8; + uint32_t ulp_cp_timer_slp_cycle:24; /*sleep cycles for ULP-coprocessor timer*/ + }; + uint32_t val; + } ulp_cp_timer_1; + uint32_t reserved_134; union { struct { uint32_t date: 28; diff --git a/components/soc/soc/esp32s2/include/soc/rtc_i2c_struct.h b/components/soc/soc/esp32s2/include/soc/rtc_i2c_struct.h index 938df0c58..ecf4901fc 100644 --- a/components/soc/soc/esp32s2/include/soc/rtc_i2c_struct.h +++ b/components/soc/soc/esp32s2/include/soc/rtc_i2c_struct.h @@ -27,15 +27,16 @@ typedef volatile struct { } scl_low; union { struct { - uint32_t sda_force_out: 1; /*1=push pull 0=open drain*/ - uint32_t scl_force_out: 1; /*1=push pull 0=open drain*/ - uint32_t ms_mode: 1; /*1=master 0=slave*/ - uint32_t trans_start: 1; /*force start*/ - uint32_t tx_lsb_first: 1; /*transit lsb first*/ - uint32_t rx_lsb_first: 1; /*receive lsb first*/ - uint32_t reserved6: 24; - uint32_t i2c_reset: 1; /*rtc i2c sw reset*/ - uint32_t i2cclk_en: 1; /*rtc i2c reg clk gating*/ + uint32_t sda_force_out: 1; /*1=push pull 0=open drain*/ + uint32_t scl_force_out: 1; /*1=push pull 0=open drain*/ + uint32_t ms_mode: 1; /*1=master 0=slave*/ + uint32_t trans_start: 1; /*force start*/ + uint32_t tx_lsb_first: 1; /*transit lsb first*/ + uint32_t rx_lsb_first: 1; /*receive lsb first*/ + uint32_t reserved6: 23; + uint32_t i2c_ctrl_clk_gate_en: 1; + uint32_t i2c_reset: 1; /*rtc i2c sw reset*/ + uint32_t i2cclk_en: 1; /*rtc i2c reg clk gating*/ }; uint32_t val; } ctrl; diff --git a/components/soc/soc/esp32s2/include/soc/rtc_io_struct.h b/components/soc/soc/esp32s2/include/soc/rtc_io_struct.h index 251832f30..c38c9fd4a 100644 --- a/components/soc/soc/esp32s2/include/soc/rtc_io_struct.h +++ b/components/soc/soc/esp32s2/include/soc/rtc_io_struct.h @@ -260,7 +260,14 @@ typedef volatile struct { }; uint32_t val; } sar_i2c_io; - uint32_t reserved_e8; + union { + struct { + uint32_t io_touch_bufsel: 4; /*BUF_SEL when touch work without fsm*/ + uint32_t io_touch_bufmode: 1; /*BUF_MODE when touch work without fsm*/ + uint32_t reserved5: 27; + }; + uint32_t val; + } touch_ctrl; uint32_t reserved_ec; uint32_t reserved_f0; uint32_t reserved_f4; diff --git a/components/soc/soc/esp32s2/include/soc/sens_reg.h b/components/soc/soc/esp32s2/include/soc/sens_reg.h index 9b9052b3a..b8c465f53 100644 --- a/components/soc/soc/esp32s2/include/soc/sens_reg.h +++ b/components/soc/soc/esp32s2/include/soc/sens_reg.h @@ -44,18 +44,6 @@ extern "C" { #define SENS_SAR1_CLK_GATED_M (BIT(18)) #define SENS_SAR1_CLK_GATED_V 0x1 #define SENS_SAR1_CLK_GATED_S 18 -/* SENS_SAR1_SAMPLE_BIT : R/W ;bitpos:[17:16] ;default: 2'd3 ; */ -/*description: 00: for 9-bit width*/ -#define SENS_SAR1_SAMPLE_BIT 0x00000003 -#define SENS_SAR1_SAMPLE_BIT_M ((SENS_SAR1_SAMPLE_BIT_V)<<(SENS_SAR1_SAMPLE_BIT_S)) -#define SENS_SAR1_SAMPLE_BIT_V 0x3 -#define SENS_SAR1_SAMPLE_BIT_S 16 -/* SENS_SAR1_SAMPLE_CYCLE : R/W ;bitpos:[15:8] ;default: 8'd9 ; */ -/*description: sample cycles for SAR ADC1*/ -#define SENS_SAR1_SAMPLE_CYCLE 0x000000FF -#define SENS_SAR1_SAMPLE_CYCLE_M ((SENS_SAR1_SAMPLE_CYCLE_V)<<(SENS_SAR1_SAMPLE_CYCLE_S)) -#define SENS_SAR1_SAMPLE_CYCLE_V 0xFF -#define SENS_SAR1_SAMPLE_CYCLE_S 8 /* SENS_SAR1_CLK_DIV : R/W ;bitpos:[7:0] ;default: 8'd2 ; */ /*description: clock divider*/ #define SENS_SAR1_CLK_DIV 0x000000FF @@ -99,18 +87,18 @@ extern "C" { #define SENS_FORCE_XPD_AMP_FSM 0 // Use FSM to control power down #define SENS_FORCE_XPD_AMP_PD 2 // Force power down #define SENS_FORCE_XPD_AMP_PU 3 // Force power up -/* SENS_SAR1_STOP : R/W ;bitpos:[2] ;default: 1'b0 ; */ -/*description: stop SAR ADC1 conversion*/ -#define SENS_SAR1_STOP (BIT(2)) -#define SENS_SAR1_STOP_M (BIT(2)) -#define SENS_SAR1_STOP_V 0x1 -#define SENS_SAR1_STOP_S 2 -/* SENS_SAR1_BIT_WIDTH : R/W ;bitpos:[1:0] ;default: 2'b11 ; */ -/*description: 00: 9 bit*/ -#define SENS_SAR1_BIT_WIDTH 0x00000003 -#define SENS_SAR1_BIT_WIDTH_M ((SENS_SAR1_BIT_WIDTH_V)<<(SENS_SAR1_BIT_WIDTH_S)) -#define SENS_SAR1_BIT_WIDTH_V 0x3 -#define SENS_SAR1_BIT_WIDTH_S 0 +/* SENS_RTC_CLKGATE_EN : R/W ;bitpos:[23] ;default: 1'b0 ; */ +/*description: */ +#define SENS_RTC_CLKGATE_EN (BIT(23)) +#define SENS_RTC_CLKGATE_EN_M (BIT(23)) +#define SENS_RTC_CLKGATE_EN_V 0x1 +#define SENS_RTC_CLKGATE_EN_S 23 +/* SENS_RTC_RESET : R/W ;bitpos:[22] ;default: 1'b0 ; */ +/*description: */ +#define SENS_RTC_RESET (BIT(22)) +#define SENS_RTC_RESET_M (BIT(22)) +#define SENS_RTC_RESET_V 0x1 +#define SENS_RTC_RESET_S 22 #define SENS_SAR_MEAS1_CTRL2_REG (DR_REG_SENS_BASE + 0x000c) /* SENS_SAR1_EN_PAD_FORCE : R/W ;bitpos:[31] ;default: 1'b0 ; */ @@ -299,18 +287,12 @@ extern "C" { #define SENS_SAR2_CLK_GATED_M (BIT(18)) #define SENS_SAR2_CLK_GATED_V 0x1 #define SENS_SAR2_CLK_GATED_S 18 -/* SENS_SAR2_SAMPLE_BIT : R/W ;bitpos:[17:16] ;default: 2'd3 ; */ -/*description: 00: for 9-bit width*/ -#define SENS_SAR2_SAMPLE_BIT 0x00000003 -#define SENS_SAR2_SAMPLE_BIT_M ((SENS_SAR2_SAMPLE_BIT_V)<<(SENS_SAR2_SAMPLE_BIT_S)) -#define SENS_SAR2_SAMPLE_BIT_V 0x3 -#define SENS_SAR2_SAMPLE_BIT_S 16 -/* SENS_SAR2_SAMPLE_CYCLE : R/W ;bitpos:[15:8] ;default: 8'd9 ; */ -/*description: sample cycles for SAR ADC2*/ -#define SENS_SAR2_SAMPLE_CYCLE 0x000000FF -#define SENS_SAR2_SAMPLE_CYCLE_M ((SENS_SAR2_SAMPLE_CYCLE_V)<<(SENS_SAR2_SAMPLE_CYCLE_S)) -#define SENS_SAR2_SAMPLE_CYCLE_V 0xFF -#define SENS_SAR2_SAMPLE_CYCLE_S 8 +/* SENS_SAR2_WAIT_ARB_CYCLE : R/W ;bitpos:[17:16] ;default: 2'b1 ; */ +/*description: wait arbit stable after sar_done*/ +#define SENS_SAR2_WAIT_ARB_CYCLE 0x00000003 +#define SENS_SAR2_WAIT_ARB_CYCLE_M ((SENS_SAR2_WAIT_ARB_CYCLE_V)<<(SENS_SAR2_WAIT_ARB_CYCLE_S)) +#define SENS_SAR2_WAIT_ARB_CYCLE_V 0x3 +#define SENS_SAR2_WAIT_ARB_CYCLE_S 16 /* SENS_SAR2_CLK_DIV : R/W ;bitpos:[7:0] ;default: 8'd2 ; */ /*description: clock divider*/ #define SENS_SAR2_CLK_DIV 0x000000FF @@ -369,18 +351,12 @@ extern "C" { #define SENS_SAR2_PWDET_CAL_EN_M (BIT(3)) #define SENS_SAR2_PWDET_CAL_EN_V 0x1 #define SENS_SAR2_PWDET_CAL_EN_S 3 -/* SENS_SAR2_STOP : R/W ;bitpos:[2] ;default: 1'b0 ; */ -/*description: stop SAR ADC2 conversion*/ -#define SENS_SAR2_STOP (BIT(2)) -#define SENS_SAR2_STOP_M (BIT(2)) -#define SENS_SAR2_STOP_V 0x1 -#define SENS_SAR2_STOP_S 2 -/* SENS_SAR2_BIT_WIDTH : R/W ;bitpos:[1:0] ;default: 2'b11 ; */ -/*description: 00: 9 bit*/ -#define SENS_SAR2_BIT_WIDTH 0x00000003 -#define SENS_SAR2_BIT_WIDTH_M ((SENS_SAR2_BIT_WIDTH_V)<<(SENS_SAR2_BIT_WIDTH_S)) -#define SENS_SAR2_BIT_WIDTH_V 0x3 -#define SENS_SAR2_BIT_WIDTH_S 0 +/* SENS_SAR2_CNTL_STATE : RO ;bitpos:[2:0] ;default: 3'b0 ; */ +/*description: saradc2_cntl_fsm*/ +#define SENS_SAR2_CNTL_STATE 0x00000007 +#define SENS_SAR2_CNTL_STATE_M ((SENS_SAR2_CNTL_STATE_V)<<(SENS_SAR2_CNTL_STATE_S)) +#define SENS_SAR2_CNTL_STATE_V 0x7 +#define SENS_SAR2_CNTL_STATE_S 0 #define SENS_SAR_MEAS2_CTRL2_REG (DR_REG_SENS_BASE + 0x0030) /* SENS_SAR2_EN_PAD_FORCE : R/W ;bitpos:[31] ;default: 1'b0 ; */ @@ -459,19 +435,6 @@ extern "C" { #define SENS_FORCE_XPD_SAR_FSM 0 // Use FSM to control power down #define SENS_FORCE_XPD_SAR_PD 2 // Force power down #define SENS_FORCE_XPD_SAR_PU 3 // Force power up -/* SENS_SAR1_DREF : R/W ;bitpos:[28:26] ;default: 3'd0 ; */ -/*description: Adjust saradc1 offset*/ -#define SENS_SAR1_DREF 0x00000007 -#define SENS_SAR1_DREF_M ((SENS_SAR1_DREF_V)<<(SENS_SAR1_DREF_S)) -#define SENS_SAR1_DREF_V 0x7 -#define SENS_SAR1_DREF_S 26 -/* SENS_SAR2_DREF : R/W ;bitpos:[25:23] ;default: 3'd0 ; */ -/*description: Adjust saradc2 offset*/ -#define SENS_SAR2_DREF 0x00000007 -#define SENS_SAR2_DREF_M ((SENS_SAR2_DREF_V)<<(SENS_SAR2_DREF_S)) -#define SENS_SAR2_DREF_V 0x7 -#define SENS_SAR2_DREF_S 23 - #define SENS_SAR_SLAVE_ADDR1_REG (DR_REG_SENS_BASE + 0x0040) /* SENS_MEAS_STATUS : RO ;bitpos:[29:22] ;default: 8'h0 ; */ /*description: */ @@ -535,26 +498,6 @@ extern "C" { #define SENS_I2C_SLAVE_ADDR7_S 0 #define SENS_SAR_TSENS_CTRL_REG (DR_REG_SENS_BASE + 0x0050) -/* SENS_TSENS_DAC : R/W ;bitpos:[31:28] ;default: 4'hF ; */ -/*description: Temperature sensor offset dac. 15 for 0 offset 5 for -2 7 for - -1 11 for 1 10 for 2*/ -#define SENS_TSENS_DAC 0x0000000F -#define SENS_TSENS_DAC_M ((SENS_TSENS_DAC_V)<<(SENS_TSENS_DAC_S)) -#define SENS_TSENS_DAC_V 0xF -#define SENS_TSENS_DAC_S 28 -/* SENS_TSENS_DIV_CHOP : R/W ;bitpos:[27:26] ;default: 2'b10 ; */ -/*description: 0 for steady phase 0 1 for steady phase 1 2 for chopping with - ½ frequency of TSENS_CK 3 for chopping with ¼*/ -#define SENS_TSENS_DIV_CHOP 0x00000003 -#define SENS_TSENS_DIV_CHOP_M ((SENS_TSENS_DIV_CHOP_V)<<(SENS_TSENS_DIV_CHOP_S)) -#define SENS_TSENS_DIV_CHOP_V 0x3 -#define SENS_TSENS_DIV_CHOP_S 26 -/* SENS_TSENS_DIZ : R/W ;bitpos:[25] ;default: 1'b0 ; */ -/*description: ADC input short*/ -#define SENS_TSENS_DIZ (BIT(25)) -#define SENS_TSENS_DIZ_M (BIT(25)) -#define SENS_TSENS_DIZ_V 0x1 -#define SENS_TSENS_DIZ_S 25 /* SENS_TSENS_DUMP_OUT : R/W ;bitpos:[24] ;default: 1'b0 ; */ /*description: temperature sensor dump out*/ #define SENS_TSENS_DUMP_OUT (BIT(24)) @@ -675,6 +618,24 @@ extern "C" { #define SENS_TOUCH_APPROACH_PAD2_M ((SENS_TOUCH_APPROACH_PAD2_V)<<(SENS_TOUCH_APPROACH_PAD2_S)) #define SENS_TOUCH_APPROACH_PAD2_V 0xF #define SENS_TOUCH_APPROACH_PAD2_S 20 +/* SENS_TOUCH_UNIT_END : RO ;bitpos:[19] ;default: 1'd0 ; */ +/*description: touch_unit_done*/ +#define SENS_TOUCH_UNIT_END (BIT(19)) +#define SENS_TOUCH_UNIT_END_M (BIT(19)) +#define SENS_TOUCH_UNIT_END_V 0x1 +#define SENS_TOUCH_UNIT_END_S 19 +/* SENS_TOUCH_DENOISE_END : RO ;bitpos:[18] ;default: 1'd0 ; */ +/*description: touch_denoise_done*/ +#define SENS_TOUCH_DENOISE_END (BIT(18)) +#define SENS_TOUCH_DENOISE_END_M (BIT(18)) +#define SENS_TOUCH_DENOISE_END_V 0x1 +#define SENS_TOUCH_DENOISE_END_S 18 +/* SENS_TOUCH_DATA_SEL : R/W ;bitpos:[17:16] ;default: 2'd0 ; */ +/*description: 3: smooth data 2: baseline 1 0: raw_data*/ +#define SENS_TOUCH_DATA_SEL 0x00000003 +#define SENS_TOUCH_DATA_SEL_M ((SENS_TOUCH_DATA_SEL_V)<<(SENS_TOUCH_DATA_SEL_S)) +#define SENS_TOUCH_DATA_SEL_V 0x3 +#define SENS_TOUCH_DATA_SEL_S 16 /* SENS_TOUCH_STATUS_CLR : WO ;bitpos:[15] ;default: 1'd0 ; */ /*description: clear all touch active status*/ #define SENS_TOUCH_STATUS_CLR (BIT(15)) @@ -800,126 +761,6 @@ extern "C" { #define SENS_TOUCH_OUT_TH14_V 0x3FFFFF #define SENS_TOUCH_OUT_TH14_S 0 -#define SENS_SAR_TOUCH_OUT0_REG (DR_REG_SENS_BASE + 0x0098) -/* SENS_TOUCH_MEAS_OUT0 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 0*/ -#define SENS_TOUCH_MEAS_OUT0 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT0_M ((SENS_TOUCH_MEAS_OUT0_V)<<(SENS_TOUCH_MEAS_OUT0_S)) -#define SENS_TOUCH_MEAS_OUT0_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT0_S 0 - -#define SENS_SAR_TOUCH_OUT1_REG (DR_REG_SENS_BASE + 0x009c) -/* SENS_TOUCH_MEAS_OUT1 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 1*/ -#define SENS_TOUCH_MEAS_OUT1 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT1_M ((SENS_TOUCH_MEAS_OUT1_V)<<(SENS_TOUCH_MEAS_OUT1_S)) -#define SENS_TOUCH_MEAS_OUT1_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT1_S 0 - -#define SENS_SAR_TOUCH_OUT2_REG (DR_REG_SENS_BASE + 0x00a0) -/* SENS_TOUCH_MEAS_OUT2 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 2*/ -#define SENS_TOUCH_MEAS_OUT2 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT2_M ((SENS_TOUCH_MEAS_OUT2_V)<<(SENS_TOUCH_MEAS_OUT2_S)) -#define SENS_TOUCH_MEAS_OUT2_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT2_S 0 - -#define SENS_SAR_TOUCH_OUT3_REG (DR_REG_SENS_BASE + 0x00a4) -/* SENS_TOUCH_MEAS_OUT3 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 3*/ -#define SENS_TOUCH_MEAS_OUT3 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT3_M ((SENS_TOUCH_MEAS_OUT3_V)<<(SENS_TOUCH_MEAS_OUT3_S)) -#define SENS_TOUCH_MEAS_OUT3_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT3_S 0 - -#define SENS_SAR_TOUCH_OUT4_REG (DR_REG_SENS_BASE + 0x00a8) -/* SENS_TOUCH_MEAS_OUT4 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 4*/ -#define SENS_TOUCH_MEAS_OUT4 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT4_M ((SENS_TOUCH_MEAS_OUT4_V)<<(SENS_TOUCH_MEAS_OUT4_S)) -#define SENS_TOUCH_MEAS_OUT4_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT4_S 0 - -#define SENS_SAR_TOUCH_OUT5_REG (DR_REG_SENS_BASE + 0x00ac) -/* SENS_TOUCH_MEAS_OUT5 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 5*/ -#define SENS_TOUCH_MEAS_OUT5 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT5_M ((SENS_TOUCH_MEAS_OUT5_V)<<(SENS_TOUCH_MEAS_OUT5_S)) -#define SENS_TOUCH_MEAS_OUT5_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT5_S 0 - -#define SENS_SAR_TOUCH_OUT6_REG (DR_REG_SENS_BASE + 0x00b0) -/* SENS_TOUCH_MEAS_OUT6 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 6*/ -#define SENS_TOUCH_MEAS_OUT6 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT6_M ((SENS_TOUCH_MEAS_OUT6_V)<<(SENS_TOUCH_MEAS_OUT6_S)) -#define SENS_TOUCH_MEAS_OUT6_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT6_S 0 - -#define SENS_SAR_TOUCH_OUT7_REG (DR_REG_SENS_BASE + 0x00b4) -/* SENS_TOUCH_MEAS_OUT7 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 7*/ -#define SENS_TOUCH_MEAS_OUT7 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT7_M ((SENS_TOUCH_MEAS_OUT7_V)<<(SENS_TOUCH_MEAS_OUT7_S)) -#define SENS_TOUCH_MEAS_OUT7_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT7_S 0 - -#define SENS_SAR_TOUCH_OUT8_REG (DR_REG_SENS_BASE + 0x00b8) -/* SENS_TOUCH_MEAS_OUT8 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 8*/ -#define SENS_TOUCH_MEAS_OUT8 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT8_M ((SENS_TOUCH_MEAS_OUT8_V)<<(SENS_TOUCH_MEAS_OUT8_S)) -#define SENS_TOUCH_MEAS_OUT8_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT8_S 0 - -#define SENS_SAR_TOUCH_OUT9_REG (DR_REG_SENS_BASE + 0x00bc) -/* SENS_TOUCH_MEAS_OUT9 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 9*/ -#define SENS_TOUCH_MEAS_OUT9 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT9_M ((SENS_TOUCH_MEAS_OUT9_V)<<(SENS_TOUCH_MEAS_OUT9_S)) -#define SENS_TOUCH_MEAS_OUT9_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT9_S 0 - -#define SENS_SAR_TOUCH_OUT10_REG (DR_REG_SENS_BASE + 0x00c0) -/* SENS_TOUCH_MEAS_OUT10 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 10*/ -#define SENS_TOUCH_MEAS_OUT10 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT10_M ((SENS_TOUCH_MEAS_OUT10_V)<<(SENS_TOUCH_MEAS_OUT10_S)) -#define SENS_TOUCH_MEAS_OUT10_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT10_S 0 - -#define SENS_SAR_TOUCH_OUT11_REG (DR_REG_SENS_BASE + 0x00c4) -/* SENS_TOUCH_MEAS_OUT11 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 11*/ -#define SENS_TOUCH_MEAS_OUT11 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT11_M ((SENS_TOUCH_MEAS_OUT11_V)<<(SENS_TOUCH_MEAS_OUT11_S)) -#define SENS_TOUCH_MEAS_OUT11_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT11_S 0 - -#define SENS_SAR_TOUCH_OUT12_REG (DR_REG_SENS_BASE + 0x00c8) -/* SENS_TOUCH_MEAS_OUT12 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 12*/ -#define SENS_TOUCH_MEAS_OUT12 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT12_M ((SENS_TOUCH_MEAS_OUT12_V)<<(SENS_TOUCH_MEAS_OUT12_S)) -#define SENS_TOUCH_MEAS_OUT12_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT12_S 0 - -#define SENS_SAR_TOUCH_OUT13_REG (DR_REG_SENS_BASE + 0x00cc) -/* SENS_TOUCH_MEAS_OUT13 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 13*/ -#define SENS_TOUCH_MEAS_OUT13 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT13_M ((SENS_TOUCH_MEAS_OUT13_V)<<(SENS_TOUCH_MEAS_OUT13_S)) -#define SENS_TOUCH_MEAS_OUT13_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT13_S 0 - -#define SENS_SAR_TOUCH_OUT14_REG (DR_REG_SENS_BASE + 0x00d0) -/* SENS_TOUCH_MEAS_OUT14 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 14*/ -#define SENS_TOUCH_MEAS_OUT14 0x003FFFFF -#define SENS_TOUCH_MEAS_OUT14_M ((SENS_TOUCH_MEAS_OUT14_V)<<(SENS_TOUCH_MEAS_OUT14_S)) -#define SENS_TOUCH_MEAS_OUT14_V 0x3FFFFF -#define SENS_TOUCH_MEAS_OUT14_S 0 - #define SENS_SAR_TOUCH_CHN_ST_REG (DR_REG_SENS_BASE + 0x00d4) /* SENS_TOUCH_MEAS_DONE : RO ;bitpos:[31] ;default: 1'b0 ; */ /*description: */ @@ -961,12 +802,12 @@ extern "C" { #define SENS_TOUCH_PAD1_DEBOUNCE_M ((SENS_TOUCH_PAD1_DEBOUNCE_V)<<(SENS_TOUCH_PAD1_DEBOUNCE_S)) #define SENS_TOUCH_PAD1_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD1_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD1_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD1_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD1_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD1_BASELINE_M ((SENS_TOUCH_PAD1_BASELINE_V)<<(SENS_TOUCH_PAD1_BASELINE_S)) -#define SENS_TOUCH_PAD1_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD1_BASELINE_S 0 +#define SENS_TOUCH_PAD1_DATA 0x003FFFFF +#define SENS_TOUCH_PAD1_DATA_M ((SENS_TOUCH_PAD1_DATA_V)<<(SENS_TOUCH_PAD1_DATA_S)) +#define SENS_TOUCH_PAD1_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD1_DATA_S 0 #define SENS_SAR_TOUCH_STATUS2_REG (DR_REG_SENS_BASE + 0x00e0) /* SENS_TOUCH_PAD2_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -975,12 +816,12 @@ extern "C" { #define SENS_TOUCH_PAD2_DEBOUNCE_M ((SENS_TOUCH_PAD2_DEBOUNCE_V)<<(SENS_TOUCH_PAD2_DEBOUNCE_S)) #define SENS_TOUCH_PAD2_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD2_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD2_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD2_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD2_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD2_BASELINE_M ((SENS_TOUCH_PAD2_BASELINE_V)<<(SENS_TOUCH_PAD2_BASELINE_S)) -#define SENS_TOUCH_PAD2_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD2_BASELINE_S 0 +#define SENS_TOUCH_PAD2_DATA 0x003FFFFF +#define SENS_TOUCH_PAD2_DATA_M ((SENS_TOUCH_PAD2_DATA_V)<<(SENS_TOUCH_PAD2_DATA_S)) +#define SENS_TOUCH_PAD2_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD2_DATA_S 0 #define SENS_SAR_TOUCH_STATUS3_REG (DR_REG_SENS_BASE + 0x00e4) /* SENS_TOUCH_PAD3_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -989,12 +830,12 @@ extern "C" { #define SENS_TOUCH_PAD3_DEBOUNCE_M ((SENS_TOUCH_PAD3_DEBOUNCE_V)<<(SENS_TOUCH_PAD3_DEBOUNCE_S)) #define SENS_TOUCH_PAD3_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD3_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD3_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD3_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD3_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD3_BASELINE_M ((SENS_TOUCH_PAD3_BASELINE_V)<<(SENS_TOUCH_PAD3_BASELINE_S)) -#define SENS_TOUCH_PAD3_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD3_BASELINE_S 0 +#define SENS_TOUCH_PAD3_DATA 0x003FFFFF +#define SENS_TOUCH_PAD3_DATA_M ((SENS_TOUCH_PAD3_DATA_V)<<(SENS_TOUCH_PAD3_DATA_S)) +#define SENS_TOUCH_PAD3_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD3_DATA_S 0 #define SENS_SAR_TOUCH_STATUS4_REG (DR_REG_SENS_BASE + 0x00e8) /* SENS_TOUCH_PAD4_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1003,12 +844,12 @@ extern "C" { #define SENS_TOUCH_PAD4_DEBOUNCE_M ((SENS_TOUCH_PAD4_DEBOUNCE_V)<<(SENS_TOUCH_PAD4_DEBOUNCE_S)) #define SENS_TOUCH_PAD4_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD4_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD4_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD4_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD4_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD4_BASELINE_M ((SENS_TOUCH_PAD4_BASELINE_V)<<(SENS_TOUCH_PAD4_BASELINE_S)) -#define SENS_TOUCH_PAD4_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD4_BASELINE_S 0 +#define SENS_TOUCH_PAD4_DATA 0x003FFFFF +#define SENS_TOUCH_PAD4_DATA_M ((SENS_TOUCH_PAD4_DATA_V)<<(SENS_TOUCH_PAD4_DATA_S)) +#define SENS_TOUCH_PAD4_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD4_DATA_S 0 #define SENS_SAR_TOUCH_STATUS5_REG (DR_REG_SENS_BASE + 0x00ec) /* SENS_TOUCH_PAD5_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1017,12 +858,12 @@ extern "C" { #define SENS_TOUCH_PAD5_DEBOUNCE_M ((SENS_TOUCH_PAD5_DEBOUNCE_V)<<(SENS_TOUCH_PAD5_DEBOUNCE_S)) #define SENS_TOUCH_PAD5_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD5_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD5_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD5_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD5_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD5_BASELINE_M ((SENS_TOUCH_PAD5_BASELINE_V)<<(SENS_TOUCH_PAD5_BASELINE_S)) -#define SENS_TOUCH_PAD5_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD5_BASELINE_S 0 +#define SENS_TOUCH_PAD5_DATA 0x003FFFFF +#define SENS_TOUCH_PAD5_DATA_M ((SENS_TOUCH_PAD5_DATA_V)<<(SENS_TOUCH_PAD5_DATA_S)) +#define SENS_TOUCH_PAD5_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD5_DATA_S 0 #define SENS_SAR_TOUCH_STATUS6_REG (DR_REG_SENS_BASE + 0x00f0) /* SENS_TOUCH_PAD6_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1031,12 +872,12 @@ extern "C" { #define SENS_TOUCH_PAD6_DEBOUNCE_M ((SENS_TOUCH_PAD6_DEBOUNCE_V)<<(SENS_TOUCH_PAD6_DEBOUNCE_S)) #define SENS_TOUCH_PAD6_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD6_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD6_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD6_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD6_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD6_BASELINE_M ((SENS_TOUCH_PAD6_BASELINE_V)<<(SENS_TOUCH_PAD6_BASELINE_S)) -#define SENS_TOUCH_PAD6_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD6_BASELINE_S 0 +#define SENS_TOUCH_PAD6_DATA 0x003FFFFF +#define SENS_TOUCH_PAD6_DATA_M ((SENS_TOUCH_PAD6_DATA_V)<<(SENS_TOUCH_PAD6_DATA_S)) +#define SENS_TOUCH_PAD6_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD6_DATA_S 0 #define SENS_SAR_TOUCH_STATUS7_REG (DR_REG_SENS_BASE + 0x00f4) /* SENS_TOUCH_PAD7_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1045,12 +886,12 @@ extern "C" { #define SENS_TOUCH_PAD7_DEBOUNCE_M ((SENS_TOUCH_PAD7_DEBOUNCE_V)<<(SENS_TOUCH_PAD7_DEBOUNCE_S)) #define SENS_TOUCH_PAD7_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD7_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD7_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD7_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD7_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD7_BASELINE_M ((SENS_TOUCH_PAD7_BASELINE_V)<<(SENS_TOUCH_PAD7_BASELINE_S)) -#define SENS_TOUCH_PAD7_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD7_BASELINE_S 0 +#define SENS_TOUCH_PAD7_DATA 0x003FFFFF +#define SENS_TOUCH_PAD7_DATA_M ((SENS_TOUCH_PAD7_DATA_V)<<(SENS_TOUCH_PAD7_DATA_S)) +#define SENS_TOUCH_PAD7_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD7_DATA_S 0 #define SENS_SAR_TOUCH_STATUS8_REG (DR_REG_SENS_BASE + 0x00f8) /* SENS_TOUCH_PAD8_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1059,12 +900,12 @@ extern "C" { #define SENS_TOUCH_PAD8_DEBOUNCE_M ((SENS_TOUCH_PAD8_DEBOUNCE_V)<<(SENS_TOUCH_PAD8_DEBOUNCE_S)) #define SENS_TOUCH_PAD8_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD8_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD8_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD8_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD8_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD8_BASELINE_M ((SENS_TOUCH_PAD8_BASELINE_V)<<(SENS_TOUCH_PAD8_BASELINE_S)) -#define SENS_TOUCH_PAD8_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD8_BASELINE_S 0 +#define SENS_TOUCH_PAD8_DATA 0x003FFFFF +#define SENS_TOUCH_PAD8_DATA_M ((SENS_TOUCH_PAD8_DATA_V)<<(SENS_TOUCH_PAD8_DATA_S)) +#define SENS_TOUCH_PAD8_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD8_DATA_S 0 #define SENS_SAR_TOUCH_STATUS9_REG (DR_REG_SENS_BASE + 0x00fc) /* SENS_TOUCH_PAD9_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1073,12 +914,12 @@ extern "C" { #define SENS_TOUCH_PAD9_DEBOUNCE_M ((SENS_TOUCH_PAD9_DEBOUNCE_V)<<(SENS_TOUCH_PAD9_DEBOUNCE_S)) #define SENS_TOUCH_PAD9_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD9_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD9_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD9_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD9_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD9_BASELINE_M ((SENS_TOUCH_PAD9_BASELINE_V)<<(SENS_TOUCH_PAD9_BASELINE_S)) -#define SENS_TOUCH_PAD9_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD9_BASELINE_S 0 +#define SENS_TOUCH_PAD9_DATA 0x003FFFFF +#define SENS_TOUCH_PAD9_DATA_M ((SENS_TOUCH_PAD9_DATA_V)<<(SENS_TOUCH_PAD9_DATA_S)) +#define SENS_TOUCH_PAD9_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD9_DATA_S 0 #define SENS_SAR_TOUCH_STATUS10_REG (DR_REG_SENS_BASE + 0x0100) /* SENS_TOUCH_PAD10_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1087,12 +928,12 @@ extern "C" { #define SENS_TOUCH_PAD10_DEBOUNCE_M ((SENS_TOUCH_PAD10_DEBOUNCE_V)<<(SENS_TOUCH_PAD10_DEBOUNCE_S)) #define SENS_TOUCH_PAD10_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD10_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD10_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD10_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD10_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD10_BASELINE_M ((SENS_TOUCH_PAD10_BASELINE_V)<<(SENS_TOUCH_PAD10_BASELINE_S)) -#define SENS_TOUCH_PAD10_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD10_BASELINE_S 0 +#define SENS_TOUCH_PAD10_DATA 0x003FFFFF +#define SENS_TOUCH_PAD10_DATA_M ((SENS_TOUCH_PAD10_DATA_V)<<(SENS_TOUCH_PAD10_DATA_S)) +#define SENS_TOUCH_PAD10_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD10_DATA_S 0 #define SENS_SAR_TOUCH_STATUS11_REG (DR_REG_SENS_BASE + 0x0104) /* SENS_TOUCH_PAD11_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1101,12 +942,12 @@ extern "C" { #define SENS_TOUCH_PAD11_DEBOUNCE_M ((SENS_TOUCH_PAD11_DEBOUNCE_V)<<(SENS_TOUCH_PAD11_DEBOUNCE_S)) #define SENS_TOUCH_PAD11_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD11_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD11_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD11_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD11_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD11_BASELINE_M ((SENS_TOUCH_PAD11_BASELINE_V)<<(SENS_TOUCH_PAD11_BASELINE_S)) -#define SENS_TOUCH_PAD11_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD11_BASELINE_S 0 +#define SENS_TOUCH_PAD11_DATA 0x003FFFFF +#define SENS_TOUCH_PAD11_DATA_M ((SENS_TOUCH_PAD11_DATA_V)<<(SENS_TOUCH_PAD11_DATA_S)) +#define SENS_TOUCH_PAD11_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD11_DATA_S 0 #define SENS_SAR_TOUCH_STATUS12_REG (DR_REG_SENS_BASE + 0x0108) /* SENS_TOUCH_PAD12_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1115,12 +956,12 @@ extern "C" { #define SENS_TOUCH_PAD12_DEBOUNCE_M ((SENS_TOUCH_PAD12_DEBOUNCE_V)<<(SENS_TOUCH_PAD12_DEBOUNCE_S)) #define SENS_TOUCH_PAD12_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD12_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD12_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD12_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD12_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD12_BASELINE_M ((SENS_TOUCH_PAD12_BASELINE_V)<<(SENS_TOUCH_PAD12_BASELINE_S)) -#define SENS_TOUCH_PAD12_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD12_BASELINE_S 0 +#define SENS_TOUCH_PAD12_DATA 0x003FFFFF +#define SENS_TOUCH_PAD12_DATA_M ((SENS_TOUCH_PAD12_DATA_V)<<(SENS_TOUCH_PAD12_DATA_S)) +#define SENS_TOUCH_PAD12_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD12_DATA_S 0 #define SENS_SAR_TOUCH_STATUS13_REG (DR_REG_SENS_BASE + 0x010c) /* SENS_TOUCH_PAD13_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1129,12 +970,12 @@ extern "C" { #define SENS_TOUCH_PAD13_DEBOUNCE_M ((SENS_TOUCH_PAD13_DEBOUNCE_V)<<(SENS_TOUCH_PAD13_DEBOUNCE_S)) #define SENS_TOUCH_PAD13_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD13_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD13_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD13_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD13_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD13_BASELINE_M ((SENS_TOUCH_PAD13_BASELINE_V)<<(SENS_TOUCH_PAD13_BASELINE_S)) -#define SENS_TOUCH_PAD13_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD13_BASELINE_S 0 +#define SENS_TOUCH_PAD13_DATA 0x003FFFFF +#define SENS_TOUCH_PAD13_DATA_M ((SENS_TOUCH_PAD13_DATA_V)<<(SENS_TOUCH_PAD13_DATA_S)) +#define SENS_TOUCH_PAD13_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD13_DATA_S 0 #define SENS_SAR_TOUCH_STATUS14_REG (DR_REG_SENS_BASE + 0x0110) /* SENS_TOUCH_PAD14_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ @@ -1143,28 +984,28 @@ extern "C" { #define SENS_TOUCH_PAD14_DEBOUNCE_M ((SENS_TOUCH_PAD14_DEBOUNCE_V)<<(SENS_TOUCH_PAD14_DEBOUNCE_S)) #define SENS_TOUCH_PAD14_DEBOUNCE_V 0x7 #define SENS_TOUCH_PAD14_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD14_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_PAD14_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_PAD14_BASELINE 0x003FFFFF -#define SENS_TOUCH_PAD14_BASELINE_M ((SENS_TOUCH_PAD14_BASELINE_V)<<(SENS_TOUCH_PAD14_BASELINE_S)) -#define SENS_TOUCH_PAD14_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_PAD14_BASELINE_S 0 +#define SENS_TOUCH_PAD14_DATA 0x003FFFFF +#define SENS_TOUCH_PAD14_DATA_M ((SENS_TOUCH_PAD14_DATA_V)<<(SENS_TOUCH_PAD14_DATA_S)) +#define SENS_TOUCH_PAD14_DATA_V 0x3FFFFF +#define SENS_TOUCH_PAD14_DATA_S 0 -#define SENS_SAR_TOUCH_STATUS15_REG (DR_REG_SENS_BASE + 0x0114) +#define SENS_SAR_TOUCH_SLP_STATUS_REG (DR_REG_SENS_BASE + 0x0114) /* SENS_TOUCH_SLP_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ /*description: */ #define SENS_TOUCH_SLP_DEBOUNCE 0x00000007 #define SENS_TOUCH_SLP_DEBOUNCE_M ((SENS_TOUCH_SLP_DEBOUNCE_V)<<(SENS_TOUCH_SLP_DEBOUNCE_S)) #define SENS_TOUCH_SLP_DEBOUNCE_V 0x7 #define SENS_TOUCH_SLP_DEBOUNCE_S 29 -/* SENS_TOUCH_SLP_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/* SENS_TOUCH_SLP_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ /*description: */ -#define SENS_TOUCH_SLP_BASELINE 0x003FFFFF -#define SENS_TOUCH_SLP_BASELINE_M ((SENS_TOUCH_SLP_BASELINE_V)<<(SENS_TOUCH_SLP_BASELINE_S)) -#define SENS_TOUCH_SLP_BASELINE_V 0x3FFFFF -#define SENS_TOUCH_SLP_BASELINE_S 0 +#define SENS_TOUCH_SLP_DATA 0x003FFFFF +#define SENS_TOUCH_SLP_DATA_M ((SENS_TOUCH_SLP_DATA_V)<<(SENS_TOUCH_SLP_DATA_S)) +#define SENS_TOUCH_SLP_DATA_V 0x3FFFFF +#define SENS_TOUCH_SLP_DATA_S 0 -#define SENS_SAR_TOUCH_STATUS16_REG (DR_REG_SENS_BASE + 0x0118) +#define SENS_SAR_TOUCH_APPR_STATUS_REG (DR_REG_SENS_BASE + 0x0118) /* SENS_TOUCH_SLP_APPROACH_CNT : RO ;bitpos:[31:24] ;default: 8'd0 ; */ /*description: */ #define SENS_TOUCH_SLP_APPROACH_CNT 0x000000FF @@ -1191,6 +1032,18 @@ extern "C" { #define SENS_TOUCH_APPROACH_PAD2_CNT_S 0 #define SENS_SAR_DAC_CTRL1_REG (DR_REG_SENS_BASE + 0x011c) +/* SENS_DAC_CLKGATE_EN : R/W ;bitpos:[27] ;default: 1'b0 ; */ +/*description: */ +#define SENS_DAC_CLKGATE_EN (BIT(27)) +#define SENS_DAC_CLKGATE_EN_M (BIT(27)) +#define SENS_DAC_CLKGATE_EN_V 0x1 +#define SENS_DAC_CLKGATE_EN_S 27 +/* SENS_DAC_RESET : R/W ;bitpos:[26] ;default: 1'b0 ; */ +/*description: */ +#define SENS_DAC_RESET (BIT(26)) +#define SENS_DAC_RESET_M (BIT(26)) +#define SENS_DAC_RESET_V 0x1 +#define SENS_DAC_RESET_S 26 /* SENS_DAC_CLK_INV : R/W ;bitpos:[25] ;default: 1'b0 ; */ /*description: 1: invert PDAC_CLK*/ #define SENS_DAC_CLK_INV (BIT(25)) @@ -1614,8 +1467,22 @@ extern "C" { #define SENS_SAR_NOUSE_V 0xFFFFFFFF #define SENS_SAR_NOUSE_S 0 -#define SENS_SARDATE_REG (DR_REG_SENS_BASE + 0x0144) -/* SENS_SAR_DATE : R/W ;bitpos:[27:0] ;default: 28'h1809210 ; */ +#define SENS_SAR_IO_MUX_CONF_REG (DR_REG_SENS_BASE + 0x0144) +/* SENS_IOMUX_CLK_GATE_EN : R/W ;bitpos:[31] ;default: 1'd0 ; */ +/*description: */ +#define SENS_IOMUX_CLK_GATE_EN (BIT(31)) +#define SENS_IOMUX_CLK_GATE_EN_M (BIT(31)) +#define SENS_IOMUX_CLK_GATE_EN_V 0x1 +#define SENS_IOMUX_CLK_GATE_EN_S 31 +/* SENS_IOMUX_RESET : R/W ;bitpos:[30] ;default: 1'b0 ; */ +/*description: */ +#define SENS_IOMUX_RESET (BIT(30)) +#define SENS_IOMUX_RESET_M (BIT(30)) +#define SENS_IOMUX_RESET_V 0x1 +#define SENS_IOMUX_RESET_S 30 + +#define SENS_SARDATE_REG (DR_REG_SENS_BASE + 0x0148) +/* SENS_SAR_DATE : R/W ;bitpos:[27:0] ;default: 28'h1906140 ; */ /*description: */ #define SENS_SAR_DATE 0x0FFFFFFF #define SENS_SAR_DATE_M ((SENS_SAR_DATE_V)<<(SENS_SAR_DATE_S)) diff --git a/components/soc/soc/esp32s2/include/soc/sens_struct.h b/components/soc/soc/esp32s2/include/soc/sens_struct.h index 98808fc61..ae0f69315 100644 --- a/components/soc/soc/esp32s2/include/soc/sens_struct.h +++ b/components/soc/soc/esp32s2/include/soc/sens_struct.h @@ -20,24 +20,23 @@ extern "C" { typedef volatile struct { union { struct { - uint32_t sar1_clk_div: 8; /*clock divider*/ - uint32_t sar1_sample_cycle: 8; /*sample cycles for SAR ADC1*/ - uint32_t sar1_sample_bit: 2; /*00: for 9-bit width*/ - uint32_t sar1_clk_gated: 1; - uint32_t sar1_sample_num: 8; - uint32_t reserved27: 1; - uint32_t sar1_data_inv: 1; /*Invert SAR ADC1 data*/ - uint32_t sar1_int_en: 1; /*enable saradc1 to send out interrupt*/ - uint32_t reserved30: 2; + uint32_t sar1_clk_div: 8; /*clock divider*/ + uint32_t reserved8: 10; + uint32_t sar1_clk_gated: 1; + uint32_t sar1_sample_num: 8; + uint32_t reserved27: 1; + uint32_t sar1_data_inv: 1; /*Invert SAR ADC1 data*/ + uint32_t sar1_int_en: 1; /*enable saradc1 to send out interrupt*/ + uint32_t reserved30: 2; }; uint32_t val; } sar_reader1_ctrl; uint32_t sar_reader1_status; /**/ union { struct { - uint32_t sar1_bit_width: 2; /*00: 9 bit*/ - uint32_t sar1_stop: 1; /*stop SAR ADC1 conversion*/ - uint32_t reserved3: 21; + uint32_t reserved0: 22; + uint32_t rtc_saradc_reset: 1; + uint32_t rtc_saradc_clkgate_en: 1; uint32_t force_xpd_amp: 2; uint32_t amp_rst_fb_force: 2; uint32_t amp_short_ref_force: 2; @@ -100,23 +99,22 @@ typedef volatile struct { } sar_amp_ctrl3; union { struct { - uint32_t sar2_clk_div: 8; /*clock divider*/ - uint32_t sar2_sample_cycle: 8; /*sample cycles for SAR ADC2*/ - uint32_t sar2_sample_bit: 2; /*00: for 9-bit width*/ - uint32_t sar2_clk_gated: 1; - uint32_t sar2_sample_num: 8; - uint32_t reserved27: 2; - uint32_t sar2_data_inv: 1; /*Invert SAR ADC2 data*/ - uint32_t sar2_int_en: 1; /*enable saradc2 to send out interrupt*/ - uint32_t reserved31: 1; + uint32_t sar2_clk_div: 8; /*clock divider*/ + uint32_t reserved8: 8; + uint32_t sar2_wait_arb_cycle: 2; /*wait arbit stable after sar_done*/ + uint32_t sar2_clk_gated: 1; + uint32_t sar2_sample_num: 8; + uint32_t reserved27: 2; + uint32_t sar2_data_inv: 1; /*Invert SAR ADC2 data*/ + uint32_t sar2_int_en: 1; /*enable saradc2 to send out interrupt*/ + uint32_t reserved31: 1; }; uint32_t val; } sar_reader2_ctrl; uint32_t sar_reader2_status; /**/ union { struct { - uint32_t sar2_bit_width: 2; /*00: 9 bit*/ - uint32_t sar2_stop: 1; /*stop SAR ADC2 conversion*/ + uint32_t sar2_cntl_state: 3; /*saradc2_cntl_fsm*/ uint32_t sar2_pwdet_cal_en: 1; /*rtc control pwdet enable*/ uint32_t sar2_pkdet_cal_en: 1; /*rtc control pkdet enable*/ uint32_t sar2_en_test: 1; /*SAR2_EN_TEST*/ @@ -149,9 +147,7 @@ typedef volatile struct { uint32_t sar_atten2; /*2-bit attenuation for each pad*/ union { struct { - uint32_t reserved0: 23; - uint32_t sar2_dref: 3; /*Adjust saradc2 offset*/ - uint32_t sar1_dref: 3; /*Adjust saradc1 offset*/ + uint32_t reserved0: 29; uint32_t force_xpd_sar: 2; uint32_t sarclk_en: 1; }; @@ -201,9 +197,7 @@ typedef volatile struct { uint32_t tsens_power_up: 1; /*temperature sensor power up*/ uint32_t tsens_power_up_force: 1; /*1: dump out & power up controlled by SW*/ uint32_t tsens_dump_out: 1; /*temperature sensor dump out*/ - uint32_t tsens_diz: 1; /*ADC input short*/ - uint32_t tsens_div_chop: 2; /*0 for steady phase 0 1 for steady phase 1 2 for chopping with ½ frequency of TSENS_CK 3 for chopping with ¼*/ - uint32_t tsens_dac: 4; /*Temperature sensor offset dac. 15 for 0 offset 5 for -2 7 for -1 11 for 1 10 for 2*/ + uint32_t reserved25: 7; }; uint32_t val; } sar_tctrl; @@ -231,7 +225,9 @@ typedef volatile struct { struct { uint32_t touch_outen: 15; /*touch controller output enable*/ uint32_t touch_status_clr: 1; /*clear all touch active status*/ - uint32_t reserved16: 4; + uint32_t touch_data_sel: 2; /*3: smooth data 2: baseline 1 0: raw_data*/ + uint32_t touch_denoise_end: 1; /*touch_denoise_done*/ + uint32_t touch_unit_end: 1; /*touch_unit_done*/ uint32_t touch_approach_pad2: 4; /*indicate which pad is approach pad2*/ uint32_t touch_approach_pad1: 4; /*indicate which pad is approach pad1*/ uint32_t touch_approach_pad0: 4; /*indicate which pad is approach pad0*/ @@ -245,13 +241,21 @@ typedef volatile struct { }; uint32_t val; } touch_thresh[14]; - union { - struct { - uint32_t meas_out: 22; /*the counter for touch pad 1*/ - uint32_t reserved22: 10; - }; - uint32_t val; - } touch_meas[15]; + uint32_t reserved_98; + uint32_t reserved_9c; + uint32_t reserved_a0; + uint32_t reserved_a4; + uint32_t reserved_a8; + uint32_t reserved_ac; + uint32_t reserved_b0; + uint32_t reserved_b4; + uint32_t reserved_b8; + uint32_t reserved_bc; + uint32_t reserved_c0; + uint32_t reserved_c4; + uint32_t reserved_c8; + uint32_t reserved_cc; + uint32_t reserved_d0; union { struct { uint32_t touch_pad_active: 15; /*touch active status*/ @@ -271,12 +275,20 @@ typedef volatile struct { } sar_touch_status0; union { struct { - uint32_t touch_pad_baseline: 22; + uint32_t touch_pad_data: 22; uint32_t reserved22: 7; uint32_t touch_pad_debounce: 3; }; uint32_t val; } sar_touch_status[14]; + union { + struct { + uint32_t touch_slp_data: 22; + uint32_t reserved22: 7; + uint32_t touch_slp_debounce: 3; + }; + uint32_t val; + } sar_touch_slp_status; union { struct { uint32_t touch_approach_pad2_cnt: 8; @@ -285,7 +297,7 @@ typedef volatile struct { uint32_t touch_slp_approach_cnt: 8; }; uint32_t val; - } sar_touch_status16; + } sar_touch_appr_status; union { struct { uint32_t sw_fstep: 16; /*frequency step for CW generator*/ @@ -295,7 +307,9 @@ typedef volatile struct { uint32_t dac_clk_force_low: 1; /*1: force PDAC_CLK to low*/ uint32_t dac_clk_force_high: 1; /*1: force PDAC_CLK to high*/ uint32_t dac_clk_inv: 1; /*1: invert PDAC_CLK*/ - uint32_t reserved26: 6; + uint32_t dac_reset: 1; + uint32_t dac_clkgate_en: 1; + uint32_t reserved28: 4; }; uint32_t val; } sar_dac_ctrl1; @@ -407,6 +421,14 @@ typedef volatile struct { uint32_t val; } sar_hall_ctrl; uint32_t sar_nouse; /**/ + union { + struct { + uint32_t reserved0: 30; + uint32_t iomux_reset: 1; + uint32_t iomux_clk_gate_en: 1; + }; + uint32_t val; + } sar_io_mux_conf; union { struct { uint32_t sar_date: 28; diff --git a/components/soc/soc/esp32s2/include/soc/soc.h b/components/soc/soc/esp32s2/include/soc/soc.h index 53459679d..33c3af218 100644 --- a/components/soc/soc/esp32s2/include/soc/soc.h +++ b/components/soc/soc/esp32s2/include/soc/soc.h @@ -66,6 +66,7 @@ #define DR_REG_PCNT_BASE 0x3f417000 #define DR_REG_SLC_BASE 0x3f418000 #define DR_REG_LEDC_BASE 0x3f419000 +#define DR_REG_MCP_BASE 0x3f4c3000 #define DR_REG_EFUSE_BASE 0x3f41A000 #define DR_REG_NRX_BASE 0x3f41CC00 #define DR_REG_BB_BASE 0x3f41D000 diff --git a/components/soc/soc/esp32s2/include/soc/system_reg.h b/components/soc/soc/esp32s2/include/soc/system_reg.h index 79b89368d..0bb4a7f91 100644 --- a/components/soc/soc/esp32s2/include/soc/system_reg.h +++ b/components/soc/soc/esp32s2/include/soc/system_reg.h @@ -898,6 +898,10 @@ extern "C" { #define DPORT_SOC_CLK_SEL_M ((DPORT_SOC_CLK_SEL_V)<<(DPORT_SOC_CLK_SEL_S)) #define DPORT_SOC_CLK_SEL_V 0x3 #define DPORT_SOC_CLK_SEL_S 10 +#define DPORT_SOC_CLK_SEL_XTL 0 +#define DPORT_SOC_CLK_SEL_PLL 1 +#define DPORT_SOC_CLK_SEL_8M 2 +#define DPORT_SOC_CLK_SEL_APLL 3 /* DPORT_PRE_DIV_CNT : R/W ;bitpos:[9:0] ;default: 10'h1 ; */ /*description: */ #define DPORT_PRE_DIV_CNT 0x000003FF diff --git a/components/soc/soc/esp32s2/include/soc/touch_sensor_caps.h b/components/soc/soc/esp32s2/include/soc/touch_sensor_caps.h index 79f14ef64..61fdb6e1f 100644 --- a/components/soc/soc/esp32s2/include/soc/touch_sensor_caps.h +++ b/components/soc/soc/esp32s2/include/soc/touch_sensor_caps.h @@ -18,19 +18,19 @@ extern "C" { #endif -#define SOC_TOUCH_SENSOR_NUM (15) /*! 15 Touch channels */ -#define SOC_TOUCH_SENSOR_BIT_MASK_MAX (0x7fff)/*! 15 Touch channels */ +#define SOC_TOUCH_SENSOR_NUM (15) /*! 15 Touch channels */ +#define SOC_TOUCH_SENSOR_BIT_MASK_MAX (0x7fff)/*! 15 Touch channels */ -#define SOC_TOUCH_PAD_MEASURE_WAIT (0xFF) /*! (touch threshold + hysteresis), the touch channel be touched. * If (raw data - baseline) < (touch threshold - hysteresis), the touch channel be released. - * Range: 0 ~ 3. The coefficient is 0: 1/8; 1: 3/32; 2: 1/16; 3: 1/32 + * Range: 0 ~ 3. The coefficient is 0: 4/32; 1: 3/32; 2: 2/32; 3: OFF. * * @param hys_thr hysteresis coefficient. */ @@ -611,7 +745,7 @@ static inline void touch_ll_filter_set_hysteresis(uint32_t hys_thr) * Get hysteresis threshold coefficient. hysteresis = hysteresis_thr * touch_threshold. * If (raw data - baseline) > (touch threshold + hysteresis), the touch channel be touched. * If (raw data - baseline) < (touch threshold - hysteresis), the touch channel be released. - * Range: 0 ~ 3. The coefficient is 0: 1/8; 1: 3/32; 2: 1/16; 3: 1/32 + * Range: 0 ~ 3. The coefficient is 0: 4/32; 1: 3/32; 2: 2/32; 3: OFF. * * @param hys_thr hysteresis coefficient. */ @@ -624,7 +758,7 @@ static inline void touch_ll_filter_get_hysteresis(uint32_t *hys_thr) * Set noise threshold coefficient. noise = noise_thr * touch threshold. * If (raw data - baseline) > (noise), the baseline stop updating. * If (raw data - baseline) < (noise), the baseline start updating. - * Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; + * Range: 0 ~ 3. The coefficient is 0: 4/8; 1: 3/8; 2: 2/8; 3: 1; * * @param hys_thr Noise threshold coefficient. */ @@ -637,7 +771,7 @@ static inline void touch_ll_filter_set_noise_thres(uint32_t noise_thr) * Get noise threshold coefficient. noise = noise_thr * touch threshold. * If (raw data - baseline) > (noise), the baseline stop updating. * If (raw data - baseline) < (noise), the baseline start updating. - * Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; + * Range: 0 ~ 3. The coefficient is 0: 4/8; 1: 3/8; 2: 2/8; 3: 1; * * @param noise_thr Noise threshold coefficient. */ @@ -674,7 +808,7 @@ static inline void touch_ll_filter_get_neg_noise_thres(uint32_t *noise_thr) /** * Set the cumulative number of baseline reset processes. such as `n`. If the measured values continue to exceed - * the negative noise threshold for `n` times, the baseline reset to raw data. + * the negative noise threshold for `n+1` times, the baseline reset to raw data. * Range: 0 ~ 15 * * @param reset_cnt The cumulative number of baseline reset processes. @@ -686,7 +820,7 @@ static inline void touch_ll_filter_set_baseline_reset(uint32_t reset_cnt) /** * Get the cumulative number of baseline reset processes. such as `n`. If the measured values continue to exceed - * the negative noise threshold for `n` times, the baseline reset to raw data. + * the negative noise threshold for `n+1` times, the baseline reset to raw data. * Range: 0 ~ 15 * * @param reset_cnt The cumulative number of baseline reset processes. @@ -817,9 +951,9 @@ static inline void touch_ll_denoise_get_grade(touch_pad_denoise_grade_t *grade) * * @param denoise value of denoise. */ -static inline uint32_t touch_ll_denoise_read_data(uint32_t *data) +static inline void touch_ll_denoise_read_data(uint32_t *data) { - return (uint32_t)SENS.sar_touch_status0.touch_denoise_data; + *data = SENS.sar_touch_status0.touch_denoise_data; } /************************ Waterproof register setting ************************/ @@ -950,11 +1084,11 @@ static inline void touch_ll_proximity_get_meas_times(uint32_t *times) static inline void touch_ll_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt) { if (SENS.sar_touch_conf.touch_approach_pad0 == touch_num) { - *cnt = SENS.sar_touch_status16.touch_approach_pad0_cnt; + *cnt = SENS.sar_touch_appr_status.touch_approach_pad0_cnt; } else if (SENS.sar_touch_conf.touch_approach_pad1 == touch_num) { - *cnt = SENS.sar_touch_status16.touch_approach_pad1_cnt; + *cnt = SENS.sar_touch_appr_status.touch_approach_pad1_cnt; } else if (SENS.sar_touch_conf.touch_approach_pad2 == touch_num) { - *cnt = SENS.sar_touch_status16.touch_approach_pad2_cnt; + *cnt = SENS.sar_touch_appr_status.touch_approach_pad2_cnt; } } @@ -1003,7 +1137,7 @@ static inline void touch_ll_sleep_get_channel_num(touch_pad_t *touch_num) * The threshold determines the sensitivity of the touch sensor. * The threshold is the original value of the trigger state minus the baseline value. * - * @note The threshold at sleep is the same as the threshold before sleep. + * @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep. */ static inline void touch_ll_sleep_set_threshold(uint32_t touch_thres) { @@ -1015,7 +1149,7 @@ static inline void touch_ll_sleep_set_threshold(uint32_t touch_thres) * The threshold determines the sensitivity of the touch sensor. * The threshold is the original value of the trigger state minus the baseline value. * - * @note The threshold at sleep is the same as the threshold before sleep. + * @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep. */ static inline void touch_ll_sleep_get_threshold(uint32_t *touch_thres) { @@ -1038,6 +1172,14 @@ static inline void touch_ll_sleep_disable_approach(void) RTCCNTL.touch_slp_thres.touch_slp_approach_en = 0; } +/** + * Get proximity function status for sleep pad. + */ +static inline bool touch_ll_sleep_get_approach_status(void) +{ + return (bool)RTCCNTL.touch_slp_thres.touch_slp_approach_en; +} + /** * Read baseline of touch sensor for sleep pad. * @@ -1045,7 +1187,37 @@ static inline void touch_ll_sleep_disable_approach(void) */ static inline void touch_ll_sleep_read_baseline(uint32_t *baseline) { - *baseline = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_BASELINE); + SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_BASELINE; + *baseline = SENS.sar_touch_slp_status.touch_slp_data; +} + +static inline void touch_ll_sleep_read_smooth(uint32_t *smooth_data) +{ + SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_SMOOTH; + *smooth_data = SENS.sar_touch_slp_status.touch_slp_data; +} + +/* Workaround: Note: sleep pad raw data is not in `sar_touch_slp_status` */ +static inline void touch_ll_sleep_read_data(uint32_t *raw_data) +{ + uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad; + SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_RAW; + *raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data; +} + +static inline void touch_ll_sleep_reset_baseline(void) +{ + RTCCNTL.touch_approach.touch_slp_channel_clr = 1; +} + +/** + * Select touch sensor dbias to save power in sleep mode. + * + * @note If change the dbias, the reading of touch sensor will changed. Users should make sure the threshold. + */ +static inline void touch_ll_sleep_low_power(bool is_low_power) +{ + RTCCNTL.touch_ctrl2.touch_dbias = is_low_power; } /** @@ -1055,7 +1227,7 @@ static inline void touch_ll_sleep_read_baseline(uint32_t *baseline) */ static inline void touch_ll_sleep_read_debounce(uint32_t *debounce) { - *debounce = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_DEBOUNCE); + *debounce = SENS.sar_touch_slp_status.touch_slp_debounce; } /** @@ -1064,7 +1236,7 @@ static inline void touch_ll_sleep_read_debounce(uint32_t *debounce) */ static inline void touch_ll_sleep_read_proximity_cnt(uint32_t *approach_cnt) { - *approach_cnt = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS16_REG, SENS_TOUCH_SLP_APPROACH_CNT); + *approach_cnt = SENS.sar_touch_appr_status.touch_slp_approach_cnt; } /** diff --git a/components/soc/src/esp32s2/touch_sensor_hal.c b/components/soc/src/esp32s2/touch_sensor_hal.c index 9efc1cfc8..3b9de6fcf 100644 --- a/components/soc/src/esp32s2/touch_sensor_hal.c +++ b/components/soc/src/esp32s2/touch_sensor_hal.c @@ -19,7 +19,7 @@ void touch_hal_init(void) { - touch_ll_intr_disable(TOUCH_PAD_INTR_ALL); + touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL); touch_ll_clear_channel_mask(SOC_TOUCH_SENSOR_BIT_MASK_MAX); touch_ll_clear_trigger_status_mask(); touch_ll_set_meas_times(TOUCH_PAD_MEASURE_CYCLE_DEFAULT); @@ -27,14 +27,31 @@ void touch_hal_init(void) touch_ll_set_voltage_high(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD); touch_ll_set_voltage_low(TOUCH_PAD_LOW_VOLTAGE_THRESHOLD); touch_ll_set_voltage_attenuation(TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); - touch_ll_set_inactive_connect(TOUCH_PAD_INACTIVE_CONNECT_DEFAULT); + touch_ll_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); + /* Clear touch channels to initialize the channel value (baseline, raw_data). + * Note: Should call it after enable clock gate. */ + touch_ll_clkgate(true); // Enable clock gate for touch sensor. + touch_ll_filter_reset_baseline(TOUCH_PAD_MAX); + touch_ll_sleep_reset_baseline(); } void touch_hal_deinit(void) { - touch_hal_stop_fsm(); - touch_hal_clear_trigger_status_mask(); - touch_ll_intr_disable(TOUCH_PAD_INTR_ALL); + touch_ll_filter_reset_baseline(TOUCH_PAD_MAX); + touch_ll_sleep_reset_baseline(); + touch_ll_stop_fsm(); + touch_ll_clkgate(false); + touch_ll_clear_channel_mask(SOC_TOUCH_SENSOR_BIT_MASK_MAX); + touch_ll_clear_trigger_status_mask(); + touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL); + touch_ll_timeout_disable(); + touch_ll_waterproof_disable(); + touch_ll_denoise_disable(); + touch_pad_t prox_pad[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {[0 ... (SOC_TOUCH_PROXIMITY_CHANNEL_NUM - 1)] = 0}; + touch_ll_proximity_set_channel_num((const touch_pad_t *)prox_pad); + touch_ll_sleep_set_channel_num(0); + touch_ll_sleep_disable_approach(); + touch_ll_reset(); // Reset the touch sensor FSM. } void touch_hal_filter_set_config(const touch_filter_config_t *filter_info) @@ -46,6 +63,7 @@ void touch_hal_filter_set_config(const touch_filter_config_t *filter_info) touch_ll_filter_set_neg_noise_thres(filter_info->noise_neg_thr); touch_ll_filter_set_baseline_reset(filter_info->neg_noise_limit); touch_ll_filter_set_jitter_step(filter_info->jitter_step); + touch_ll_filter_set_smooth_mode(filter_info->smh_lvl); } void touch_hal_filter_get_config(touch_filter_config_t *filter_info) @@ -57,6 +75,7 @@ void touch_hal_filter_get_config(touch_filter_config_t *filter_info) touch_ll_filter_get_neg_noise_thres(&filter_info->noise_neg_thr); touch_ll_filter_get_baseline_reset(&filter_info->neg_noise_limit); touch_ll_filter_get_jitter_step(&filter_info->jitter_step); + touch_ll_filter_get_smooth_mode(&filter_info->smh_lvl); } void touch_hal_denoise_set_config(const touch_pad_denoise_t *denoise) @@ -95,25 +114,51 @@ void touch_hal_waterproof_enable(void) touch_ll_waterproof_enable(); } -void touch_hal_proximity_set_config(const touch_pad_proximity_t *proximity) +bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled) { - touch_ll_proximity_set_channel_num(proximity->select_pad); - touch_ll_proximity_set_meas_times(proximity->meas_num); -} - -void touch_hal_proximity_get_config(touch_pad_proximity_t *proximity) -{ - touch_ll_proximity_get_channel_num(proximity->select_pad); - touch_ll_proximity_get_meas_times(&proximity->meas_num); -} - -void touch_hal_sleep_channel_config(const touch_pad_sleep_channel_t *slp_config) -{ - touch_ll_sleep_set_channel_num(slp_config->touch_num); - touch_ll_sleep_set_threshold(slp_config->sleep_pad_threshold); - if (slp_config->en_proximity) { - touch_ll_sleep_enable_approach(); + int i = 0; + touch_pad_t ch_num[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {0}; + touch_ll_proximity_get_channel_num(ch_num); + if (enabled) { + for (i = 0; i < SOC_TOUCH_PROXIMITY_CHANNEL_NUM; i++) { + if (ch_num[i] == TOUCH_PAD_NUM0 || ch_num[i] >= TOUCH_PAD_MAX || ch_num[i] == touch_num) { + ch_num[i] = touch_num; + break; + } + } + if (i == SOC_TOUCH_PROXIMITY_CHANNEL_NUM) { + return false; + } } else { - touch_ll_sleep_disable_approach(); + for (i = 0; i < SOC_TOUCH_PROXIMITY_CHANNEL_NUM; i++) { + if (ch_num[i] == touch_num) { + ch_num[i] = TOUCH_PAD_NUM0; + break; + } + } + } + touch_ll_proximity_set_channel_num(ch_num); + return true; +} + +void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable) +{ + if (enable) { + touch_ll_sleep_set_channel_num(pad_num); + touch_ll_sleep_set_threshold(SOC_TOUCH_PAD_THRESHOLD_MAX); + /* Default change touch dbias to self-dbias to save power. + Measuring the sleep pad threshold after `sleep_channel_set_config`. */ + touch_ll_sleep_low_power(true); + touch_ll_sleep_reset_baseline(); + } else { + touch_ll_sleep_set_channel_num(TOUCH_PAD_NUM0); } } + +void touch_hal_sleep_channel_get_config(touch_pad_sleep_channel_t *slp_config) +{ + touch_ll_sleep_get_channel_num(&slp_config->touch_num); + slp_config->en_proximity = touch_ll_sleep_get_approach_status(); +} + + diff --git a/examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c index 37535b70d..af469e5cd 100644 --- a/examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c +++ b/examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c @@ -11,7 +11,6 @@ #include "freertos/task.h" #include "freertos/queue.h" #include "esp_log.h" - #include "driver/touch_pad.h" #include "soc/rtc_periph.h" #include "soc/sens_periph.h" @@ -29,20 +28,21 @@ typedef struct touch_msg { #define TOUCH_BUTTON_NUM 4 #define TOUCH_BUTTON_WATERPROOF_ENABLE 1 #define TOUCH_BUTTON_DENOISE_ENABLE 1 +#define TOUCH_CHANGE_CONFIG 0 static const touch_pad_t button[TOUCH_BUTTON_NUM] = { TOUCH_PAD_NUM7, // 'SELECT' button. TOUCH_PAD_NUM9, // 'MENU' button. TOUCH_PAD_NUM11, // 'BACK' button. TOUCH_PAD_NUM13, // Guard ring for waterproof design. - // if this pad be touched, other pads no response. + // If this pad be touched, other pads no response. }; /* * Touch threshold. The threshold determines the sensitivity of the touch. * This threshold is derived by testing changes in readings from different touch channels. - * If (raw_data - baseline) > baseline * threshold, the pad be actived. - * If (raw_data - baseline) < baseline * threshold, the pad be inactived. + * If (raw_data - baseline) > baseline * threshold, the pad be activated. + * If (raw_data - baseline) < baseline * threshold, the pad be inactivated. */ static const float button_threshold[TOUCH_BUTTON_NUM] = { 0.2, // 20%. @@ -64,9 +64,6 @@ static void touchsensor_interrupt_cb(void *arg) evt.pad_status = touch_pad_get_status(); evt.pad_num = touch_pad_get_current_meas_channel(); - if (evt.intr_mask & TOUCH_PAD_INTR_MASK_DONE) { - touch_pad_filter_read_baseline(evt.pad_num, &evt.pad_val); - } xQueueSendFromISR(que_touch, &evt, &task_awoken); if (task_awoken == pdTRUE) { portYIELD_FROM_ISR(); @@ -81,7 +78,7 @@ static void tp_example_set_thresholds(void) touch_pad_filter_read_baseline(button[i], &touch_value); //set interrupt threshold. touch_pad_set_thresh(button[i], touch_value * button_threshold[i]); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + ESP_LOGI(TAG, "touch pad [%d] base %d, thresh %d", \ button[i], touch_value, (uint32_t)(touch_value * button_threshold[i])); } } @@ -97,10 +94,10 @@ static void touchsensor_filter_set(touch_filter_mode_t mode) .noise_neg_thr = 0, // 50% .neg_noise_limit = 10, // 10 time count. .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, }; touch_pad_filter_set_config(&filter_info); touch_pad_filter_enable(); - touch_pad_filter_reset_baseline(TOUCH_PAD_MAX); ESP_LOGI(TAG, "touch pad filter init"); } @@ -109,7 +106,7 @@ static void tp_example_read_task(void *pvParameter) touch_event_t evt = {0}; static uint8_t guard_mode_flag = 0; /* Wait touch sensor init done */ - vTaskDelay(100 / portTICK_RATE_MS); + vTaskDelay(50 / portTICK_RATE_MS); tp_example_set_thresholds(); while (1) { @@ -121,10 +118,10 @@ static void tp_example_read_task(void *pvParameter) /* if guard pad be touched, other pads no response. */ if (evt.pad_num == button[3]) { guard_mode_flag = 1; - ESP_LOGW(TAG, "TouchSensor [%d] be actived, enter guard mode", evt.pad_num); + ESP_LOGW(TAG, "TouchSensor [%d] be activated, enter guard mode", evt.pad_num); } else { if (guard_mode_flag == 0) { - ESP_LOGI(TAG, "TouchSensor [%d] be actived, status mask 0x%x", evt.pad_num, evt.pad_status); + ESP_LOGI(TAG, "TouchSensor [%d] be inactivated, status mask 0x%x", evt.pad_num, evt.pad_status); } else { ESP_LOGW(TAG, "In guard mode. No response"); } @@ -134,15 +131,20 @@ static void tp_example_read_task(void *pvParameter) /* if guard pad be touched, other pads no response. */ if (evt.pad_num == button[3]) { guard_mode_flag = 0; - ESP_LOGW(TAG, "TouchSensor [%d] be actived, exit guard mode", evt.pad_num); + ESP_LOGW(TAG, "TouchSensor [%d] be activated, exit guard mode", evt.pad_num); } else { if (guard_mode_flag == 0) { - ESP_LOGI(TAG, "TouchSensor [%d] be inactived, status mask 0x%x", evt.pad_num, evt.pad_status); + ESP_LOGI(TAG, "TouchSensor [%d] be inactivated, status mask 0x%x", evt.pad_num, evt.pad_status); } } } - if (evt.intr_mask & TOUCH_PAD_INTR_MASK_DONE) { - ESP_LOGI(TAG, "TouchSensor [%d] measure done, raw data %d", evt.pad_num, evt.pad_val); + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { + ESP_LOGI(TAG, "The touch sensor group measurement is done [%d].", evt.pad_num); + } + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { + /* Add your exception handling in here. */ + ESP_LOGI(TAG, "Touch sensor channel %d measure timeout. Skip this exception channel!!", evt.pad_num); + touch_pad_timeout_resume(); // Point on the next channel to measure. } } } @@ -159,21 +161,24 @@ void app_main(void) for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { touch_pad_config(button[i]); } -#if 0 + +#if TOUCH_CHANGE_CONFIG /* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */ touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT); touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); - touch_pad_set_inactive_connect(TOUCH_PAD_INACTIVE_CONNECT_DEFAULT); + touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT); } #endif + #if TOUCH_BUTTON_DENOISE_ENABLE /* Denoise setting at TouchSensor 0. */ touch_pad_denoise_t denoise = { /* The bits to be cancelled are determined according to the noise level. */ .grade = TOUCH_PAD_DENOISE_BIT4, - .cap_level = TOUCH_PAD_DENOISE_CAP_L7, + /* By adjusting the parameters, the reading of T0 should be approximated to the reading of the measured channel. */ + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, }; touch_pad_denoise_set_config(&denoise); touch_pad_denoise_enable(); @@ -184,8 +189,10 @@ void app_main(void) /* Waterproof function */ touch_pad_waterproof_t waterproof = { .guard_ring_pad = button[3], // If no ring pad, set 0; - /* It depends on the number of the parasitic capacitance of the shield pad. */ - .shield_driver = TOUCH_PAD_SHIELD_DRV_L0, //40pf + /* It depends on the number of the parasitic capacitance of the shield pad. + Based on the touch readings of T14 and T0, estimate the size of the parasitic capacitance on T14 + and set the parameters of the appropriate hardware. */ + .shield_driver = TOUCH_PAD_SHIELD_DRV_L2, }; touch_pad_waterproof_set_config(&waterproof); touch_pad_waterproof_enable(); @@ -193,11 +200,12 @@ void app_main(void) #endif /* Filter setting */ - touchsensor_filter_set(TOUCH_PAD_FILTER_IIR_8); + touchsensor_filter_set(TOUCH_PAD_FILTER_IIR_16); + touch_pad_timeout_set(true, SOC_TOUCH_PAD_THRESHOLD_MAX); /* Register touch interrupt ISR, enable intr type. */ touch_pad_isr_register(touchsensor_interrupt_cb, NULL, TOUCH_PAD_INTR_MASK_ALL); - touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); - // touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_DONE); // Use for debug + /* If you have other touch algorithm, you can get the measured value after the `TOUCH_PAD_INTR_MASK_SCAN_DONE` interrupt is generated. */ + touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE | TOUCH_PAD_INTR_MASK_TIMEOUT); /* Enable touch sensor clock. Work mode is "timer trigger". */ touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); diff --git a/examples/peripherals/touch_pad_read/main/esp32s2/tp_read_main.c b/examples/peripherals/touch_pad_read/main/esp32s2/tp_read_main.c index 57c33b51d..b6c0472ce 100644 --- a/examples/peripherals/touch_pad_read/main/esp32s2/tp_read_main.c +++ b/examples/peripherals/touch_pad_read/main/esp32s2/tp_read_main.c @@ -13,13 +13,14 @@ #include "esp_log.h" #define TOUCH_BUTTON_NUM 14 +#define TOUCH_CHANGE_CONFIG 0 -static const char * TAG = "touch read"; +static const char *TAG = "touch read"; static const touch_pad_t button[TOUCH_BUTTON_NUM] = { TOUCH_PAD_NUM1, TOUCH_PAD_NUM2, TOUCH_PAD_NUM3, - TOUCH_PAD_NUM4, + TOUCH_PAD_NUM4, TOUCH_PAD_NUM5, TOUCH_PAD_NUM6, TOUCH_PAD_NUM7, @@ -39,7 +40,7 @@ static const touch_pad_t button[TOUCH_BUTTON_NUM] = { static void tp_example_read_task(void *pvParameter) { uint32_t touch_value; - + /* Wait touch sensor init done */ vTaskDelay(100 / portTICK_RATE_MS); printf("Touch Sensor read, the output format is: \nTouchpad num:[raw data]\n\n"); @@ -61,20 +62,20 @@ void app_main(void) for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { touch_pad_config(button[i]); } -#if 0 +#if TOUCH_CHANGE_CONFIG /* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */ touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT); touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); - touch_pad_set_inactive_connect(TOUCH_PAD_INACTIVE_CONNECT_DEFAULT); + touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT); } #endif /* Denoise setting at TouchSensor 0. */ touch_pad_denoise_t denoise = { - /* The bits to be cancelled are determined according to the noise level. */ - .grade = TOUCH_PAD_DENOISE_BIT4, - .cap_level = TOUCH_PAD_DENOISE_CAP_L7, + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, }; touch_pad_denoise_set_config(&denoise); touch_pad_denoise_enable(); @@ -83,7 +84,7 @@ void app_main(void) /* Enable touch sensor clock. Work mode is "timer trigger". */ touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); touch_pad_fsm_start(); - + /* Start task to read values by pads. */ xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); } diff --git a/examples/system/deep_sleep/main/deep_sleep_example_main.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c index 295c6146d..d2ffd389a 100644 --- a/examples/system/deep_sleep/main/deep_sleep_example_main.c +++ b/examples/system/deep_sleep/main/deep_sleep_example_main.c @@ -177,41 +177,36 @@ void app_main(void) touch_pad_denoise_t denoise = { /* The bits to be cancelled are determined according to the noise level. */ .grade = TOUCH_PAD_DENOISE_BIT4, - .cap_level = TOUCH_PAD_DENOISE_CAP_L7, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, }; touch_pad_denoise_set_config(&denoise); touch_pad_denoise_enable(); printf("Denoise function init\n"); /* Filter setting */ touch_filter_config_t filter_info = { - .mode = TOUCH_PAD_FILTER_IIR_8, + .mode = TOUCH_PAD_FILTER_IIR_16, .debounce_cnt = 1, // 1 time count. .hysteresis_thr = 3, // 3% .noise_thr = 0, // 50% .noise_neg_thr = 0, // 50% .neg_noise_limit = 10, // 10 time count. .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, }; touch_pad_filter_set_config(&filter_info); touch_pad_filter_enable(); - touch_pad_filter_reset_baseline(TOUCH_PAD_NUM9); printf("touch pad filter init %d\n", TOUCH_PAD_FILTER_IIR_8); /* Set sleep touch pad. */ - touch_pad_sleep_channel_t slp_config = { - .touch_num = TOUCH_PAD_NUM9, - .sleep_pad_threshold = TOUCH_PAD_THRESHOLD_MAX, - .en_proximity = false, - }; - touch_pad_sleep_channel_config(&slp_config); + touch_pad_sleep_channel_enable(TOUCH_PAD_NUM9, true); + touch_pad_sleep_channel_enable_proximity(TOUCH_PAD_NUM9, false); /* Enable touch sensor clock. Work mode is "timer trigger". */ touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); touch_pad_fsm_start(); vTaskDelay(100 / portTICK_RATE_MS); /* read sleep touch pad value */ uint32_t touch_value; - touch_pad_sleep_channel_read_baseline(&touch_value); - slp_config.sleep_pad_threshold = touch_value * 0.1; - touch_pad_sleep_channel_config(&slp_config); //10% + touch_pad_sleep_channel_read_smooth(TOUCH_PAD_NUM9, &touch_value); + touch_pad_sleep_set_threshold(TOUCH_PAD_NUM9, touch_value * 0.1); //10% printf("test init: touch pad [%d] slp %d, thresh %d\n", TOUCH_PAD_NUM9, touch_value, (uint32_t)(touch_value * 0.1)); #endif