feat(touch): support runtime re-configuration

This commit is contained in:
laokaiyao 2025-02-07 16:40:05 +08:00
parent 0902e70e94
commit aa791ead44
6 changed files with 51 additions and 38 deletions

View File

@ -22,4 +22,13 @@ menu "ESP-Driver:Touch Sensor Configurations"
Whether to enable the debug log message for touch driver. Whether to enable the debug log message for touch driver.
Note that, this option only controls the touch driver log, won't affect other drivers. Note that, this option only controls the touch driver log, won't affect other drivers.
config TOUCH_SKIP_FSM_CHECK
bool "Skip the FSM check"
default n
help
If skipped the FSM check, the driver will allow to re-configure the touch sensor during the runtime.
It is mainly used to tune the parameters in the runtime to find a proper set of touch parameters.
CAUTION: Not suggest to enable this option in the final product, it might cause false triggering
which is not safe in the actual environment.
endmenu # Touch Sensor Configuration endmenu # Touch Sensor Configuration

View File

@ -102,7 +102,7 @@ esp_err_t touch_sensor_del_controller(touch_sensor_handle_t sens_handle)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
// Take the semaphore to make sure the touch has stopped // Take the semaphore to make sure the touch has stopped
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not disabled"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not disabled");
FOR_EACH_TOUCH_CHANNEL(i) { FOR_EACH_TOUCH_CHANNEL(i) {
ESP_GOTO_ON_FALSE(!sens_handle->ch[i], ESP_ERR_INVALID_STATE, err, TAG, "There are still some touch channels not deleted"); ESP_GOTO_ON_FALSE(!sens_handle->ch[i], ESP_ERR_INVALID_STATE, err, TAG, "There are still some touch channels not deleted");
} }
@ -141,7 +141,7 @@ esp_err_t touch_sensor_new_channel(touch_sensor_handle_t sens_handle, int chan_i
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err2, TAG, "Please disable the touch sensor first"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err2, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->ch[chan_id], ESP_ERR_INVALID_STATE, err2, TAG, "The channel %d has been registered", chan_id); ESP_GOTO_ON_FALSE(!sens_handle->ch[chan_id], ESP_ERR_INVALID_STATE, err2, TAG, "The channel %d has been registered", chan_id);
sens_handle->ch[chan_id] = (touch_channel_handle_t)heap_caps_calloc(1, sizeof(struct touch_channel_s), TOUCH_MEM_ALLOC_CAPS); sens_handle->ch[chan_id] = (touch_channel_handle_t)heap_caps_calloc(1, sizeof(struct touch_channel_s), TOUCH_MEM_ALLOC_CAPS);
@ -179,8 +179,8 @@ esp_err_t touch_sensor_del_channel(touch_channel_handle_t chan_handle)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
touch_sensor_handle_t sens_handle = chan_handle->base; touch_sensor_handle_t sens_handle = chan_handle->base;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
#if SOC_TOUCH_SUPPORT_WATERPROOF #if SOC_TOUCH_SUPPORT_WATERPROOF
if (sens_handle->shield_chan == chan_handle) { if (sens_handle->shield_chan == chan_handle) {
ESP_GOTO_ON_ERROR(touch_sensor_config_waterproof(sens_handle, NULL), err, TAG, "Failed to disable waterproof on this channel"); ESP_GOTO_ON_ERROR(touch_sensor_config_waterproof(sens_handle, NULL), err, TAG, "Failed to disable waterproof on this channel");
@ -224,7 +224,7 @@ esp_err_t touch_sensor_reconfig_controller(touch_sensor_handle_t sens_handle, co
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_ERROR(touch_priv_config_controller(sens_handle, sens_cfg), err, TAG, "Configure touch controller failed"); ESP_GOTO_ON_ERROR(touch_priv_config_controller(sens_handle, sens_cfg), err, TAG, "Configure touch controller failed");
@ -240,7 +240,7 @@ esp_err_t touch_sensor_enable(touch_sensor_handle_t sens_handle)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has already enabled"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has already enabled");
ESP_GOTO_ON_FALSE(sens_handle->sample_cfg_num, ESP_ERR_INVALID_STATE, err, TAG, "No sample configuration was added to the touch controller"); ESP_GOTO_ON_FALSE(sens_handle->sample_cfg_num, ESP_ERR_INVALID_STATE, err, TAG, "No sample configuration was added to the touch controller");
sens_handle->is_enabled = true; sens_handle->is_enabled = true;
@ -270,7 +270,7 @@ esp_err_t touch_sensor_disable(touch_sensor_handle_t sens_handle)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not enabled"); TOUCH_GOTO_ON_FALSE_FSM(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not enabled");
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_interrupt_disable(TOUCH_LL_INTR_MASK_ALL); touch_ll_interrupt_disable(TOUCH_LL_INTR_MASK_ALL);
@ -278,7 +278,7 @@ esp_err_t touch_sensor_disable(touch_sensor_handle_t sens_handle)
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->is_enabled = false; sens_handle->is_enabled = false;
err: TOUCH_FSM_ERR_TAG(err)
xSemaphoreGiveRecursive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@ -291,7 +291,7 @@ esp_err_t touch_sensor_reconfig_channel(touch_channel_handle_t chan_handle, cons
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
touch_sensor_handle_t sens_handle = chan_handle->base; touch_sensor_handle_t sens_handle = chan_handle->base;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_ERROR(touch_priv_config_channel(chan_handle, chan_cfg), err, TAG, "Configure touch channel failed"); ESP_GOTO_ON_ERROR(touch_priv_config_channel(chan_handle, chan_cfg), err, TAG, "Configure touch channel failed");
@ -305,9 +305,9 @@ esp_err_t touch_sensor_start_continuous_scanning(touch_sensor_handle_t sens_hand
TOUCH_NULL_POINTER_CHECK_ISR(sens_handle); TOUCH_NULL_POINTER_CHECK_ISR(sens_handle);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
TOUCH_GOTO_ON_FALSE_FSM_ISR(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please enable the touch sensor first");
TOUCH_GOTO_ON_FALSE_FSM_ISR(!sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Continuous scanning has started already");
ESP_GOTO_ON_FALSE_ISR(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please enable the touch sensor first");
ESP_GOTO_ON_FALSE_ISR(!sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Continuous scanning has started already");
#if SOC_TOUCH_SENSOR_VERSION == 1 #if SOC_TOUCH_SENSOR_VERSION == 1
if (sens_handle->sw_filter_timer) { if (sens_handle->sw_filter_timer) {
ESP_GOTO_ON_ERROR_ISR(esp_timer_start_periodic(sens_handle->sw_filter_timer, sens_handle->timer_interval_ms * 1000), ESP_GOTO_ON_ERROR_ISR(esp_timer_start_periodic(sens_handle->sw_filter_timer, sens_handle->timer_interval_ms * 1000),
@ -319,8 +319,9 @@ esp_err_t touch_sensor_start_continuous_scanning(touch_sensor_handle_t sens_hand
touch_ll_enable_fsm_timer(true); touch_ll_enable_fsm_timer(true);
touch_ll_start_fsm_repeated_timer(); touch_ll_start_fsm_repeated_timer();
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
#if !CONFIG_TOUCH_SKIP_FSM_CHECK || SOC_TOUCH_SENSOR_VERSION == 1
err: err:
#endif
return ret; return ret;
} }
@ -329,8 +330,8 @@ esp_err_t touch_sensor_stop_continuous_scanning(touch_sensor_handle_t sens_handl
TOUCH_NULL_POINTER_CHECK_ISR(sens_handle); TOUCH_NULL_POINTER_CHECK_ISR(sens_handle);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
TOUCH_GOTO_ON_FALSE_FSM_ISR(sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Continuous scanning not started yet");
ESP_GOTO_ON_FALSE_ISR(sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Continuous scanning not started yet");
#if SOC_TOUCH_SENSOR_VERSION == 1 #if SOC_TOUCH_SENSOR_VERSION == 1
if (sens_handle->sw_filter_timer) { if (sens_handle->sw_filter_timer) {
ESP_GOTO_ON_ERROR(esp_timer_stop(sens_handle->sw_filter_timer), err, TAG, "Failed to stop the timer"); ESP_GOTO_ON_ERROR(esp_timer_stop(sens_handle->sw_filter_timer), err, TAG, "Failed to stop the timer");
@ -341,8 +342,9 @@ esp_err_t touch_sensor_stop_continuous_scanning(touch_sensor_handle_t sens_handl
touch_ll_enable_fsm_timer(false); touch_ll_enable_fsm_timer(false);
sens_handle->is_started = false; sens_handle->is_started = false;
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
#if !CONFIG_TOUCH_SKIP_FSM_CHECK || SOC_TOUCH_SENSOR_VERSION == 1
err: err:
#endif
return ret; return ret;
} }
@ -351,8 +353,8 @@ esp_err_t touch_sensor_trigger_oneshot_scanning(touch_sensor_handle_t sens_handl
TOUCH_NULL_POINTER_CHECK(sens_handle); TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
ESP_GOTO_ON_FALSE(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please enable the touch sensor first"); TOUCH_GOTO_ON_FALSE_FSM(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please enable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Failed to trigger oneshot scanning because scanning has started"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Failed to trigger oneshot scanning because scanning has started");
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->is_started = true; sens_handle->is_started = true;
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
@ -428,13 +430,11 @@ esp_err_t touch_sensor_register_callbacks(touch_sensor_handle_t sens_handle, con
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
memcpy(&sens_handle->cbs, callbacks, sizeof(touch_event_callbacks_t)); memcpy(&sens_handle->cbs, callbacks, sizeof(touch_event_callbacks_t));
sens_handle->user_ctx = user_ctx; sens_handle->user_ctx = user_ctx;
err: TOUCH_FSM_ERR_TAG(err)
xSemaphoreGiveRecursive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }

View File

@ -48,6 +48,17 @@ extern "C" {
#define TOUCH_INTR_ALLOC_FLAGS (_TOUCH_INTR_ALLOC_FLAGS | ESP_INTR_FLAG_SHARED) #define TOUCH_INTR_ALLOC_FLAGS (_TOUCH_INTR_ALLOC_FLAGS | ESP_INTR_FLAG_SHARED)
#endif #endif
/* Debug caps */
#if CONFIG_TOUCH_SKIP_FSM_CHECK
#define TOUCH_GOTO_ON_FALSE_FSM(...)
#define TOUCH_GOTO_ON_FALSE_FSM_ISR(...)
#define TOUCH_FSM_ERR_TAG(err_tag)
#else
#define TOUCH_GOTO_ON_FALSE_FSM(...) ESP_GOTO_ON_FALSE(__VA_ARGS__)
#define TOUCH_GOTO_ON_FALSE_FSM_ISR(...) ESP_GOTO_ON_FALSE_ISR(__VA_ARGS__)
#define TOUCH_FSM_ERR_TAG(err_tag) err_tag:
#endif
/* DMA caps */ /* DMA caps */
#define TOUCH_DMA_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA) #define TOUCH_DMA_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)

View File

@ -279,7 +279,7 @@ esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, co
touch_hal_config_t *hal_cfg_ptr = NULL; touch_hal_config_t *hal_cfg_ptr = NULL;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (sleep_cfg) { if (sleep_cfg) {
ESP_GOTO_ON_FALSE(sleep_cfg->slp_wakeup_lvl == TOUCH_LIGHT_SLEEP_WAKEUP || sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP, ESP_GOTO_ON_FALSE(sleep_cfg->slp_wakeup_lvl == TOUCH_LIGHT_SLEEP_WAKEUP || sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP,

View File

@ -316,7 +316,7 @@ esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, co
esp_sleep_pd_option_t slp_opt = ESP_PD_OPTION_AUTO; esp_sleep_pd_option_t slp_opt = ESP_PD_OPTION_AUTO;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (sleep_cfg) { if (sleep_cfg) {
ESP_GOTO_ON_FALSE(sleep_cfg->slp_wakeup_lvl == TOUCH_LIGHT_SLEEP_WAKEUP || sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP, ESP_GOTO_ON_FALSE(sleep_cfg->slp_wakeup_lvl == TOUCH_LIGHT_SLEEP_WAKEUP || sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP,
@ -397,8 +397,7 @@ esp_err_t touch_sensor_config_waterproof(touch_sensor_handle_t sens_handle, cons
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (wp_cfg) { if (wp_cfg) {
ESP_GOTO_ON_FALSE(wp_cfg->shield_chan && wp_cfg->shield_chan->id == 14, ESP_ERR_INVALID_ARG, err, TAG, "Shield channel must be channel 14"); ESP_GOTO_ON_FALSE(wp_cfg->shield_chan && wp_cfg->shield_chan->id == 14, ESP_ERR_INVALID_ARG, err, TAG, "Shield channel must be channel 14");
@ -436,9 +435,7 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
/* Reset proximity sensing part of all channels */ /* Reset proximity sensing part of all channels */
@ -469,7 +466,7 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
} }
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
err: TOUCH_FSM_ERR_TAG(err)
xSemaphoreGiveRecursive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@ -479,8 +476,7 @@ esp_err_t touch_sensor_config_denoise_channel(touch_sensor_handle_t sens_handle,
TOUCH_NULL_POINTER_CHECK(sens_handle); TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (denoise_cfg) { if (denoise_cfg) {
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
@ -499,7 +495,7 @@ esp_err_t touch_sensor_config_denoise_channel(touch_sensor_handle_t sens_handle,
touch_ll_denoise_enable(false); touch_ll_denoise_enable(false);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
} }
err: TOUCH_FSM_ERR_TAG(err)
xSemaphoreGiveRecursive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }

View File

@ -330,7 +330,7 @@ esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, co
esp_sleep_pd_option_t slp_opt = ESP_PD_OPTION_AUTO; esp_sleep_pd_option_t slp_opt = ESP_PD_OPTION_AUTO;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (sleep_cfg) { if (sleep_cfg) {
ESP_GOTO_ON_FALSE(sleep_cfg->slp_wakeup_lvl == TOUCH_LIGHT_SLEEP_WAKEUP || sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP, ESP_GOTO_ON_FALSE(sleep_cfg->slp_wakeup_lvl == TOUCH_LIGHT_SLEEP_WAKEUP || sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP,
@ -420,8 +420,7 @@ esp_err_t touch_sensor_config_waterproof(touch_sensor_handle_t sens_handle, cons
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (wp_cfg) { if (wp_cfg) {
// Check the validation of the waterproof configuration // Check the validation of the waterproof configuration
@ -453,7 +452,7 @@ esp_err_t touch_sensor_config_waterproof(touch_sensor_handle_t sens_handle, cons
sens_handle->waterproof_en = false; sens_handle->waterproof_en = false;
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
} }
err: TOUCH_FSM_ERR_TAG(err)
xSemaphoreGiveRecursive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@ -464,9 +463,7 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
/* Reset proximity sensing part of all channels */ /* Reset proximity sensing part of all channels */
@ -503,7 +500,7 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
} }
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
err: TOUCH_FSM_ERR_TAG(err)
xSemaphoreGiveRecursive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }