Просмотр исходного кода

fix:修正触屏库cst820型号名

Dozingfiretruck 8 месяцев назад
Родитель
Сommit
218eed908f
3 измененных файлов с 65 добавлено и 72 удалено
  1. 2 1
      components/tp/luat_lib_tp.c
  2. 2 1
      components/tp/luat_tp.h
  3. 61 70
      components/tp/luat_tp_cst820.c

+ 2 - 1
components/tp/luat_lib_tp.c

@@ -32,7 +32,8 @@ static const tp_reg_t tp_regs[] = {
     {"jd9261t",  &tp_config_jd9261t},
 	{"jd9261t_inited",  &tp_config_jd9261t_inited},
 	{"ft3x68", &tp_config_ft3x68},
-    {"cts820", &tp_config_cts820},
+    {"cst820", &tp_config_cst820},
+    // {"cst9220", &tp_config_cst820},
     {"", NULL}
 };
 

+ 2 - 1
components/tp/luat_tp.h

@@ -68,7 +68,8 @@ extern luat_tp_opts_t tp_config_gt9157;
 extern luat_tp_opts_t tp_config_jd9261t;
 extern luat_tp_opts_t tp_config_jd9261t_inited;
 extern luat_tp_opts_t tp_config_ft3x68;
-extern luat_tp_opts_t tp_config_cts820;
+extern luat_tp_opts_t tp_config_cst820;
+// extern luat_tp_opts_t tp_config_cst9220;
 
 int luat_tp_init(luat_tp_config_t* luat_tp_config);
 

+ 61 - 70
components/tp/luat_tp_cst820.c

@@ -5,22 +5,21 @@
 #include "luat_rtos.h"
 #include "luat_tp_reg.h"
 
-#define LUAT_LOG_TAG "cts820"
+#define LUAT_LOG_TAG "cst820"
 #include "luat_log.h"
 
-#define CTS820_ADDRESS               (0x15)
-#define CTS820_CHIP_ID_CODE          (0xB7)
-#define CTS820_CHIP_ID               (0xA7)
-#define CTS820_STATUS                (0x02)
-#define CTS820_POINT1_REG            (0x03)
+#define CST820_ADDRESS               (0x15)
+#define CST820_CHIP_ID_CODE          (0xB7)
+#define CST820_CHIP_ID               (0xA7)
+#define CST820_STATUS                (0x02)
+#define CST820_POINT1_REG            (0x03)
 
-#define CTS820_CONFIG_SIZE           (CTS820_CONFIG_FRESH - CTS820_CONFIG_REG + 1)
-#define CTS820_POINT_INFO_NUM        (4)
-#define CTS820_TOUCH_NUMBER_MIN      (1)
-#define CTS820_TOUCH_NUMBER_MAX      (2)
+#define CST820_POINT_INFO_NUM        (4)
+#define CST820_TOUCH_NUMBER_MIN      (1)
+#define CST820_TOUCH_NUMBER_MAX      (2)
 
-#define CTS820_REFRESH_RATE_MIN      (5)
-#define CTS820_REFRESH_RATE_MAX      (20)
+#define CST820_REFRESH_RATE_MIN      (5)
+#define CST820_REFRESH_RATE_MAX      (20)
 
 typedef struct luat_touch_info{
     union{
@@ -41,22 +40,23 @@ typedef struct luat_touch_info{
     };
 }luat_tp_info_t;
 
-static uint8_t cts820_init_state = 0;
+static uint8_t cst820_init_state = 0;
 
-int tp_cts820_clear_status(luat_tp_config_t* luat_tp_config){
-	if (tp_i2c_write_reg16(luat_tp_config, CTS820_STATUS, (uint8_t[]){0x00}, 1)){
+int tp_cst820_clear_status(luat_tp_config_t* luat_tp_config){
+	if (tp_i2c_write_reg16(luat_tp_config, CST820_STATUS, (uint8_t[]){0x00}, 1)){
 		LLOGE("write status reg fail!");
 		return -1;
 	}
 	return 0;
 }
 
-static int tp_cts820_detect(luat_tp_config_t* luat_tp_config){
+static int tp_cst820_detect(luat_tp_config_t* luat_tp_config){
     uint8_t chip_id = 0;
-    luat_tp_config->address = CTS820_ADDRESS;
-    tp_i2c_read_reg8(luat_tp_config, CTS820_CHIP_ID, &chip_id, 1, 0);
-    if (chip_id == CTS820_CHIP_ID_CODE){
-        LLOGI("TP find device CTS820 ,address:0x%02X",luat_tp_config->address);
+    luat_tp_config->address = CST820_ADDRESS;
+    tp_i2c_read_reg8(luat_tp_config, CST820_CHIP_ID, &chip_id, 1, 0);
+    LLOGD("chip_id:0x%02X", chip_id);
+    if (chip_id == CST820_CHIP_ID_CODE){
+        LLOGI("TP find device CST820 ,address:0x%02X",luat_tp_config->address);
         return 0;
     }else{
         return -1;
@@ -65,7 +65,7 @@ static int tp_cts820_detect(luat_tp_config_t* luat_tp_config){
 
 
 static int luat_tp_irq_cb(int pin, void *args){
-    if (cts820_init_state == 0){
+    if (cst820_init_state == 0){
         return -1;
     }
     luat_tp_config_t* luat_tp_config = (luat_tp_config_t*)args;
@@ -74,7 +74,7 @@ static int luat_tp_irq_cb(int pin, void *args){
     return 0;
 }
 
-static int tp_cts820_hw_reset(luat_tp_config_t* luat_tp_config){
+static int tp_cst820_hw_reset(luat_tp_config_t* luat_tp_config){
     if (luat_tp_config->pin_rst != LUAT_GPIO_NONE){
         luat_gpio_set(luat_tp_config->pin_rst, Luat_GPIO_LOW);
         luat_rtos_task_sleep(10);
@@ -84,21 +84,21 @@ static int tp_cts820_hw_reset(luat_tp_config_t* luat_tp_config){
     return 0;
 }
 
-static int tp_cts820_gpio_init(luat_tp_config_t* luat_tp_config){
+static int tp_cst820_gpio_init(luat_tp_config_t* luat_tp_config){
     luat_gpio_mode(luat_tp_config->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
     luat_gpio_mode(luat_tp_config->pin_int, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
     luat_gpio_set(luat_tp_config->pin_rst, Luat_GPIO_HIGH);
     luat_gpio_set(luat_tp_config->pin_int, Luat_GPIO_HIGH);
-    tp_cts820_hw_reset(luat_tp_config);
+    tp_cst820_hw_reset(luat_tp_config);
     return 0;
 }
 
-static int tp_cts820_init(luat_tp_config_t* luat_tp_config){
+static int tp_cst820_init(luat_tp_config_t* luat_tp_config){
     int ret = 0;
     luat_rtos_task_sleep(100);
-    tp_cts820_gpio_init(luat_tp_config);
+    tp_cst820_gpio_init(luat_tp_config);
     luat_rtos_task_sleep(10);
-    ret = tp_cts820_detect(luat_tp_config);
+    ret = tp_cst820_detect(luat_tp_config);
     if (ret){
         LLOGE("tp detect fail!");
         return ret;
@@ -116,13 +116,13 @@ static int tp_cts820_init(luat_tp_config_t* luat_tp_config){
     gpio.irq_args = luat_tp_config;
     luat_gpio_setup(&gpio);
 
-    cts820_init_state = 1;
+    cst820_init_state = 1;
     return ret;
 
 }
 
-static int tp_cts820_deinit(luat_tp_config_t* luat_tp_config){
-    cts820_init_state = 0;
+static int tp_cst820_deinit(luat_tp_config_t* luat_tp_config){
+    cst820_init_state = 0;
     if (luat_tp_config->pin_int != LUAT_GPIO_NONE){
         luat_gpio_close(luat_tp_config->pin_int);
     }
@@ -132,11 +132,11 @@ static int tp_cts820_deinit(luat_tp_config_t* luat_tp_config){
     return 0;
 }
 
-static void tp_cts820_read_done(luat_tp_config_t * luat_tp_config){
+static void tp_cst820_read_done(luat_tp_config_t * luat_tp_config){
 	luat_tp_irq_enable(luat_tp_config, 1);
 }
 
-// cts820 get tp info.
+// cst820 get tp info.
 typedef struct {
     uint8_t x_h : 4;
     uint8_t : 4;
@@ -146,14 +146,14 @@ typedef struct {
     uint8_t y_l;
 } point_data_t;
 
-static int16_t pre_x[CTS820_TOUCH_NUMBER_MAX] = {-1, -1};
-static int16_t pre_y[CTS820_TOUCH_NUMBER_MAX] = {-1, -1};
-static int16_t pre_w[CTS820_TOUCH_NUMBER_MAX] = {-1, -1};
-static uint8_t s_tp_down[CTS820_TOUCH_NUMBER_MAX];
+static int16_t pre_x[CST820_TOUCH_NUMBER_MAX] = {-1, -1};
+static int16_t pre_y[CST820_TOUCH_NUMBER_MAX] = {-1, -1};
+static int16_t pre_w[CST820_TOUCH_NUMBER_MAX] = {-1, -1};
+static uint8_t s_tp_down[CST820_TOUCH_NUMBER_MAX];
 
-static uint8_t read_buff[CTS820_POINT_INFO_NUM * CTS820_TOUCH_NUMBER_MAX];
+static uint8_t read_buff[CST820_POINT_INFO_NUM * CST820_TOUCH_NUMBER_MAX];
 
-void cts820_touch_up(void *buf, int8_t id){
+void cst820_touch_up(void *buf, int8_t id){
 	luat_tp_data_t *read_data = (luat_tp_data_t *)buf;
 
 	if(s_tp_down[id] == 1){
@@ -174,7 +174,7 @@ void cts820_touch_up(void *buf, int8_t id){
 	pre_w[id] = -1;
 }
 
-void cts820_touch_down(void *buf, int8_t id, int16_t x, int16_t y, int16_t w){
+void cst820_touch_down(void *buf, int8_t id, int16_t x, int16_t y, int16_t w){
 	luat_tp_data_t *read_data = (luat_tp_data_t *)buf;
 
 	if (s_tp_down[id] == 1){
@@ -195,7 +195,7 @@ void cts820_touch_down(void *buf, int8_t id, int16_t x, int16_t y, int16_t w){
 	pre_w[id] = w;
 }
 
-void cts820_read_point(uint8_t *input_buff, void *buf, uint8_t touch_num){
+void cst820_read_point(uint8_t *input_buff, void *buf, uint8_t touch_num){
 	uint8_t *read_buf = input_buff;
 	uint8_t read_index;
 	int8_t read_id = 0;
@@ -204,14 +204,14 @@ void cts820_read_point(uint8_t *input_buff, void *buf, uint8_t touch_num){
 	int16_t input_w = 0;
 
 	static uint8_t pre_touch = 0;
-	static int8_t pre_id[CTS820_TOUCH_NUMBER_MAX] = {0};
+	static int8_t pre_id[CST820_TOUCH_NUMBER_MAX] = {0};
 
 	if (pre_touch > touch_num){                                       /* point up */
 		for (read_index = 0; read_index < pre_touch; read_index++){
 			uint8_t j;
 			for (j = 0; j < touch_num; j++){                          /* this time touch num */
 				read_id = j;
-				if (read_id >= CTS820_POINT_INFO_NUM){
+				if (read_id >= CST820_POINT_INFO_NUM){
 					LLOGE("%s, touch ID %d is out range!\r\n", __func__, read_id);
 					return;
 				}
@@ -221,7 +221,7 @@ void cts820_read_point(uint8_t *input_buff, void *buf, uint8_t touch_num){
 				if (j >= touch_num - 1){
 					uint8_t up_id;
 					up_id = pre_id[read_index];
-					cts820_touch_up(buf, up_id);
+					cst820_touch_up(buf, up_id);
 				}
 			}
 		}
@@ -229,9 +229,9 @@ void cts820_read_point(uint8_t *input_buff, void *buf, uint8_t touch_num){
 	if (touch_num){                                                 /* point down */
 		uint8_t off_set;
 		for (read_index = 0; read_index < touch_num; read_index++){
-			off_set = read_index * CTS820_POINT_INFO_NUM;
+			off_set = read_index * CST820_POINT_INFO_NUM;
 			read_id = read_index;
-			if (read_id >= CTS820_POINT_INFO_NUM){
+			if (read_id >= CST820_POINT_INFO_NUM){
 				LLOGE("%s, touch ID %d is out range!\r\n", __func__, read_id);
 				return;
 			}
@@ -239,30 +239,21 @@ void cts820_read_point(uint8_t *input_buff, void *buf, uint8_t touch_num){
             point_data_t* point_buff = &read_buf[off_set];
 			input_x = point_buff->x_h << 8 | point_buff->x_l;	/* x */
 			input_y = point_buff->y_h << 8 | point_buff->y_l;	/* y */
-			cts820_touch_down(buf, read_id, input_x, input_y, input_w);
+			cst820_touch_down(buf, read_id, input_x, input_y, input_w);
 		}
 	}else if (pre_touch){
 		for(read_index = 0; read_index < pre_touch; read_index++){
-			cts820_touch_up(buf, pre_id[read_index]);
+			cst820_touch_up(buf, pre_id[read_index]);
 		}
 	}
 	pre_touch = touch_num;
 }
 
-int tp_cts820_read_status(luat_tp_config_t* luat_tp_config, uint8_t *status){
-	if (tp_i2c_read_reg16(luat_tp_config, CTS820_STATUS, status, 1, 1)){
-		LLOGE("read status reg fail!\r\n");
-		return -1;
-	}
-	// LLOGD("status=0x%02X\r\n", *status); // 调试需要看!!!
-	return 0;
-}
-
-static int tp_cts820_read(luat_tp_config_t* luat_tp_config, luat_tp_data_t *luat_tp_data){
+static int tp_cst820_read(luat_tp_config_t* luat_tp_config, luat_tp_data_t *luat_tp_data){
     uint8_t touch_num=0, point_status=0;
-    tp_i2c_read_reg8(luat_tp_config, CTS820_STATUS, &touch_num, 1, 0);
+    tp_i2c_read_reg8(luat_tp_config, CST820_STATUS, &touch_num, 1, 0);
     
-    // tp_cts820_read_status(luat_tp_config, &point_status);
+    // tp_cst820_read_status(luat_tp_config, &point_status);
     // if (point_status == 0){           /* no data */
     //     goto exit_;
     // }
@@ -271,30 +262,30 @@ static int tp_cts820_read(luat_tp_config_t* luat_tp_config, luat_tp_data_t *luat
     // }
     // touch_num = point_status & 0x0F;  /* get point num */
     // LLOGD("touch_num = %d",touch_num);
-    if (touch_num > CTS820_TOUCH_NUMBER_MAX) {/* point num is not correct */
+    if (touch_num > CST820_TOUCH_NUMBER_MAX) {/* point num is not correct */
         touch_num = 0;
         goto exit_;
     }
     
-    // LLOGD("tp_cts820_read touch_num:%d",touch_num);
+    // LLOGD("tp_cst820_read touch_num:%d",touch_num);
 
     memset(read_buff, 0x00, sizeof(read_buff));
     
     if (touch_num){
-        tp_i2c_read_reg8(luat_tp_config, CTS820_POINT1_REG, read_buff, touch_num * CTS820_POINT_INFO_NUM, 0);
+        tp_i2c_read_reg8(luat_tp_config, CST820_POINT1_REG, read_buff, touch_num * CST820_POINT_INFO_NUM, 0);
     }
 
-    cts820_read_point(read_buff, luat_tp_data, touch_num);
+    cst820_read_point(read_buff, luat_tp_data, touch_num);
     
 exit_:
-    // tp_cts820_clear_status(luat_tp_config);
+    // tp_cst820_clear_status(luat_tp_config);
     return touch_num;
 }
 
-luat_tp_opts_t tp_config_cts820 = {
-    .name = "cts820",
-    .init = tp_cts820_init,
-    .deinit = tp_cts820_deinit,
-    .read = tp_cts820_read,
-	.read_done = tp_cts820_read_done,
+luat_tp_opts_t tp_config_cst820 = {
+    .name = "cst820",
+    .init = tp_cst820_init,
+    .deinit = tp_cst820_deinit,
+    .read = tp_cst820_read,
+	.read_done = tp_cst820_read_done,
 };