From 75c616b8a4dcbb4101cfab7e83a1bc551002122a Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Sat, 23 Nov 2024 19:29:11 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0TP=E8=B6=85=E6=97=B6=E9=87=8D?= =?utf8?q?=E7=BD=AE=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../touch/ft6x46_touch/ft6x46_ctrl.c | 51 ++++++++++++++++++- .../touch/ft6x46_touch/ft6x46_ctrl.h | 3 ++ .../touch/ft6x46_touch/ft6x46_touch1.c | 26 ++++++---- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.c b/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.c index 0fcc4f219..7a4753583 100644 --- a/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.c +++ b/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.c @@ -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; + } + +} diff --git a/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.h b/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.h index 24ef8f419..3403bb558 100644 --- a/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.h +++ b/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_ctrl.h @@ -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 diff --git a/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_touch1.c b/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_touch1.c index abd5f0b6a..aa6f91c5d 100644 --- a/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_touch1.c +++ b/code/sdk/drivers/peripheral/touch/ft6x46_touch/ft6x46_touch1.c @@ -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: -- 2.17.1