添加TP超时重置操作 1453/2 1453/head
authorpenglei <1624952103@qq.com>
Sat, 23 Nov 2024 11:29:11 +0000 (19:29 +0800)
committerpenglei <1624952103@qq.com>
Sat, 23 Nov 2024 11:29:11 +0000 (19:29 +0800)
code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.c
code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.h
code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_touch1.c

index 0fcc4f2..7a47535 100644 (file)
@@ -26,6 +26,10 @@ touch_callback g_ft6x46_callback = NULL;
 
 static uint8_t g_tp_recv_buf[FT6X46_INPUT_SIZE] = {0};
 
+osTimerId_t g_ft6x46_timer = NULL;
+
+static bool g_ft6x46_timer_is_running = false;
+
 static void ft6x46_gpio_isr_handle(pin_t pin, uintptr_t param)
 {
     unused(pin);
@@ -314,6 +318,25 @@ ext_errno tp_ft6x46_i2c_data_write_reg(uint8_t addr, uint8_t val)
     return tp_ft6x46_i2c_data_write(addr, &val, 1);
 }
 
+void ft6x46_check_error(void)
+{
+    uint8_t data_buf[3] = {0};
+    uint8_t cnt = 0;
+
+    tp_i2c_data_read(0x91, &data_buf[0], 1);
+    LOS_Mdelay(1);
+    tp_i2c_data_read(0x91, &data_buf[1], 1);
+    LOS_Mdelay(1);
+    tp_i2c_data_read(0x91, &data_buf[2], 1);
+    LOS_Mdelay(1);
+
+    if(data_buf[0] == data_buf[1] && data_buf[1] == data_buf[2])
+    {
+        // printf("ft6x46_check_error !!!! 0x%x \n",data_buf[0]);
+        ft6x46_resume_reset();
+    }
+
+}
 
 ext_errno ft6x46_host_peripheral_init(ft6x46_ctrl_attr *attr)
 {
@@ -347,6 +370,9 @@ ext_errno ft6x46_host_peripheral_init(ft6x46_ctrl_attr *attr)
         g_ctrl_attr.i2c_id, g_ctrl_attr.i2c_speed, FT6X46_I2C_ADDR);
     g_host_dev_init_flag = true;
 
+
+    g_ft6x46_timer = osTimerNew((osTimerFunc_t)ft6x46_check_error, osTimerPeriodic, NULL, NULL);
+
     return EXT_ERR_SUCCESS;
 }
 
@@ -391,7 +417,30 @@ void ft6x46_resume_reset(void)
     osDelay(10);
     uapi_gpio_set_val(FT6X46_RESET_GPIO, GPIO_LEVEL_HIGH);
     /* delay 100ms */
-    osDelay(200);
+    osDelay(100);
     // uapi_gpio_set_dir(FT6X46_RESET_GPIO, GPIO_DIRECTION_INPUT);
 }
 
+
+void ft6x46_check_error_timer_start(uint32_t rtc_ms)
+{
+    if (g_ft6x46_timer == NULL)
+        return;
+    if (g_ft6x46_timer_is_running)
+        osTimerStop(g_ft6x46_timer);
+    if (g_ft6x46_timer_is_running == true)
+        osTimerStart(g_ft6x46_timer, rtc_ms);
+    g_ft6x46_timer_is_running = true;
+}
+
+void ft6x46_check_error_timer_stop(void)
+{
+    if (g_ft6x46_timer == NULL)
+        return;
+    if (g_ft6x46_timer_is_running)
+    {
+        osTimerStop(g_ft6x46_timer);
+        g_ft6x46_timer_is_running = false;
+    }
+
+}
index 24ef8f4..3403bb5 100644 (file)
@@ -66,4 +66,7 @@ ext_errno tp_ft6x46_i2c_data_read(uint8_t reg_addr, uint8_t *data_buf, uint32_t
 ext_errno tp_ft6x46_i2c_data_write(uint8_t reg_addr, uint8_t *data_buf, uint16_t data_len);
 ext_errno tp_ft6x46_i2c_data_write_reg(uint8_t addr, uint8_t val);
 
+void ft6x46_check_error_timer_start(uint32_t rtc_ms);
+void ft6x46_check_error_timer_stop(void);
+
 #endif
index abd5f0b..aa6f91c 100644 (file)
@@ -345,16 +345,18 @@ ext_errno ft6x46_irq_callback(uint8_t *data_buf, uint8_t data_len)
         return ERRCODE_FAIL;
     }
 
-    if (fts_touch_process() != ERRCODE_SUCC)
-    {
-        fail_count ++ ;
-    }else{
-        fail_count = 0;
-    }
-    if (fail_count%50 == 49){
-        tp_print("TOUCH:ft6x46_irq_callback fail to reset touch ");
-        hal_custom_resume_touch();                
-    }
+    fts_touch_process();
+
+    // if (fts_touch_process() != ERRCODE_SUCC)
+    // {
+    //     fail_count ++ ;
+    // }else{
+    //     fail_count = 0;
+    // }
+    // if (fail_count%50 == 49){
+    //     tp_print("TOUCH:ft6x46_irq_callback fail to reset touch ");
+    //     hal_custom_resume_touch();                
+    // }
 
     mem_ret = memcpy_s(data_buf, sizeof(input_event_info), &(g_ft6x46_drv.touch_msg), sizeof(input_event_info));
     if (mem_ret != EOK) {
@@ -686,6 +688,8 @@ ext_errno ft6x46_suspend(void)
     ft6x46_set_irq_mode(FT6X46_IRQ_DISABLE, FT6X46_INT_MASK);
     g_ft6x46_drv.work_status = FT6X46_WORK_SLEEP;
 
+    ft6x46_check_error_timer_stop();
+
     return EXT_ERR_SUCCESS;
 }
 
@@ -756,6 +760,8 @@ ext_errno ft6x46_resume(void)
     /* Enable Irq */
     ft6x46_set_irq_mode(FT6X46_IRQ_ENABLE, FT6X46_INT_MASK);
 
+    ft6x46_check_error_timer_start(1000);
+
     return EXT_ERR_SUCCESS;
 
 resume_exit: