From 6ee884c861a81db5e365e18258388f1a26e95c7b Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Thu, 5 Jul 2018 17:29:48 +0800 Subject: [PATCH] fix(touch): add_mutex_for_some_touchpad_apis --- components/driver/include/driver/touch_pad.h | 1 + components/driver/rtc_module.c | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/driver/include/driver/touch_pad.h b/components/driver/include/driver/touch_pad.h index 643b07befe..c59bc256f4 100644 --- a/components/driver/include/driver/touch_pad.h +++ b/components/driver/include/driver/touch_pad.h @@ -122,6 +122,7 @@ esp_err_t touch_pad_init(); /** * @brief Un-install touch pad driver. + * @note After this function is called, other touch functions are prohibited from being called. * @return * - ESP_OK Success * - ESP_FAIL Touch pad driver not initialized diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 333f50cc11..4c450bbb7a 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -476,7 +476,7 @@ static void touch_pad_filter_cb(void *arg) { static uint32_t s_filtered_temp[TOUCH_PAD_MAX] = {0}; - if (s_touch_pad_filter == NULL) { + if (s_touch_pad_filter == NULL || rtc_touch_mux == NULL) { return; } uint16_t val = 0; @@ -825,15 +825,15 @@ esp_err_t touch_pad_init() esp_err_t touch_pad_deinit() { - if (rtc_touch_mux == NULL) { - return ESP_FAIL; + RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + if (s_touch_pad_filter != NULL) { + touch_pad_filter_stop(); + touch_pad_filter_delete(); } s_touch_pad_init_bit = 0x0000; - touch_pad_filter_delete(); touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW); touch_pad_clear_status(); touch_pad_intr_disable(); - vSemaphoreDelete(rtc_touch_mux); rtc_touch_mux = NULL; return ESP_OK; } @@ -972,7 +972,7 @@ esp_err_t touch_pad_filter_start(uint32_t filter_period_ms) esp_err_t touch_pad_filter_stop() { RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); - + RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); esp_err_t ret = ESP_OK; xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); if (s_touch_pad_filter != NULL) { @@ -988,6 +988,7 @@ esp_err_t touch_pad_filter_stop() esp_err_t touch_pad_filter_delete() { RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); + RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); if (s_touch_pad_filter != NULL) { if (s_touch_pad_filter->timer != NULL) {