]> granicus.if.org Git - esp-idf/commitdiff
fix(touch): add_mutex_for_some_touchpad_apis
authorfuzhibo <fuzhibo@espressif.com>
Thu, 5 Jul 2018 09:29:48 +0000 (17:29 +0800)
committerfuzhibo <fuzhibo@espressif.com>
Wed, 1 Aug 2018 10:06:21 +0000 (18:06 +0800)
components/driver/include/driver/touch_pad.h
components/driver/rtc_module.c

index 643b07befea1691e89090422875bd2c2d3433d6b..c59bc256f44d768fed48e4ded05c763c344d93d7 100644 (file)
@@ -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
index 7c8f5ae69d00b76470f6631212af32ec7c131e72..19aa245e22db6f2de1e420e22e575e20e8874429 100644 (file)
@@ -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,14 +825,17 @@ 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();
     }
+    xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
     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();
+    xSemaphoreGive(rtc_touch_mux);
     vSemaphoreDelete(rtc_touch_mux);
     rtc_touch_mux = NULL;
     return ESP_OK;
@@ -972,7 +975,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 +991,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) {