alienwalker 1 год назад
Родитель
Сommit
0c31d0282b

+ 1 - 3
components/lcd/luat_lcd.c

@@ -140,9 +140,7 @@ LUAT_WEAK int luat_lcd_init_default(luat_lcd_conf_t* conf) {
         }
     }
     luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-    if (conf->tp_pin_rst != LUAT_GPIO_NONE) {
-        luat_gpio_mode(conf->tp_pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    }
+
     if (conf->pin_pwr != LUAT_GPIO_NONE) {
         luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
     }

+ 0 - 4
components/lcd/luat_lcd.h

@@ -100,10 +100,6 @@ typedef struct luat_lcd_conf {
     uint16_t vbp;
     uint16_t vspw;
     uint16_t vfp;
-    uint8_t tp_driver_id;
-    uint8_t tp_pin_rst;
-    uint8_t tp_pin_irq;
-    uint8_t tp_i2c_id;
     luat_color_t* buff;
     struct luat_lcd_opts* opts;
     luat_spi_device_t* lcd_spi_device;

+ 1 - 116
components/lcd/luat_lcd_jd9261t.c

@@ -4,94 +4,9 @@
 #include "luat_mem.h"
 #include "luat_rtos.h"
 #include "luat_i2c.h"
-#define LUAT_LOG_TAG "jd9261t"
+#define LUAT_LOG_TAG "jd9261t-lcd"
 #include "luat_log.h"
 
-typedef struct
-{
-	luat_lcd_conf_t* lcd;
-	luat_rtos_timer_t scan_timer;
-	uint8_t scan_cnt;
-}jd9261t_tp_ctrl_t;
-
-static jd9261t_tp_ctrl_t jd9261t_tp;
-static void jd9261t_get_tp_point(void *param, uint32_t param_len)
-{
-	uint16_t tp_x, tp_y;
-	int res;
-	uint8_t buff[60];
-	buff[0] = 0x20;
-	buff[1] = 0x01;
-	buff[2] = 0x11;
-	buff[3] = 0x20;
-	res = luat_i2c_send(jd9261t_tp.lcd->tp_i2c_id, 0x68, buff, 4, 1);
-	if (res)
-	{
-		res = luat_i2c_send(jd9261t_tp.lcd->tp_i2c_id, 0x68, buff, 4, 1);
-		if (res)
-		{
-			LLOGE("TP read point failed");
-			return;
-		}
-	}
-	luat_timer_us_delay(15);
-	res = luat_i2c_recv(jd9261t_tp.lcd->tp_i2c_id, 0x68, buff, 60);
-	if (res)
-	{
-		res = luat_i2c_recv(jd9261t_tp.lcd->tp_i2c_id, 0x68, buff, 60);
-		if (res)
-		{
-			LLOGE("TP read point failed");
-			return;
-		}
-	}
-	if (!buff[0]) return;
-
-	for (uint8_t i = 0; i < 10; i++)
-	{
-		if (buff[i * 5 + 3] != 0xff)
-		{
-			//LLOGI("%d, %x %x %x %x", i * 5 + 3, buff[i * 5 + 3], buff[i * 5 + 4], buff[i * 5 + 5], buff[i * 5 + 6]);
-			tp_x = buff[i * 5 + 3];
-			tp_x = (tp_x << 8) | buff[i * 5 + 4];
-			tp_y = buff[i * 5 + 5];
-			tp_y = (tp_y << 8) | buff[i * 5 + 6];
-			if (tp_x < jd9261t_tp.lcd->w && tp_y < jd9261t_tp.lcd->h)
-			{
-				LLOGI("TP point %d x %d y %d", i+1, tp_x, tp_y);
-			}
-			else
-			{
-				break;
-			}
-		}
-		else
-		{
-			break;
-		}
-	}
-}
-
-static LUAT_RT_RET_TYPE jd9261t_scan_once(LUAT_RT_CB_PARAM)
-{
-	jd9261t_tp.scan_cnt++;
-	luat_lcd_run_api_in_service(jd9261t_get_tp_point, jd9261t_tp.lcd, 0);
-	if (jd9261t_tp.scan_cnt > 10)
-	{
-		luat_rtos_timer_stop(jd9261t_tp.scan_timer);
-	}
-}
-
-static int jd9261t_irq_cb(int pin, void* args)
-{
-	if (jd9261t_tp.scan_cnt > 10)
-	{
-		jd9261t_tp.scan_cnt = 0;
-		luat_start_rtos_timer(jd9261t_tp.scan_timer, 20, 1);
-	}
-	return 0;
-}
-
 static int jd9261t_inited_init(luat_lcd_conf_t* conf)
 {
     if (!conf->buff)
@@ -108,7 +23,6 @@ static int jd9261t_inited_init(luat_lcd_conf_t* conf)
 			.hsync_reg = 0x60,
 			.write_1line_cmd = 0xde,
 	};
-	luat_gpio_set(conf->tp_pin_rst, Luat_GPIO_HIGH);
     luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
 //    luat_rtos_task_sleep(5);
 //    luat_gpio_set(conf->tp_pin_rst, Luat_GPIO_HIGH);
@@ -123,35 +37,6 @@ static int jd9261t_inited_init(luat_lcd_conf_t* conf)
     luat_lcd_set_direction(conf,conf->direction);
     luat_rtos_task_sleep(5);
     luat_gpio_set(conf->pin_pwr, Luat_GPIO_HIGH);
-    if (conf->tp_driver_id)
-    {
-    	uint8_t ID[4];
-    	ID[0] = 0x40;
-    	ID[1] = 0x00;
-    	ID[2] = 0x80;
-    	ID[3] = 0x76;
-    	luat_i2c_setup(conf->tp_i2c_id, 200000);
-    	luat_i2c_set_polling_mode(conf->tp_i2c_id, 1);
-    	if (luat_i2c_transfer(conf->tp_i2c_id, 0x68, ID, 4, ID, 2))
-    	{
-    		LLOGE("TP not detect");
-    	}
-    	else
-    	{
-    		LLOGI("TP detect %02x%02x", ID[1], ID[0]);
-    		jd9261t_tp.lcd = conf;
-    		jd9261t_tp.scan_cnt = 100;
-    		jd9261t_tp.scan_timer = luat_create_rtos_timer(jd9261t_scan_once, NULL, NULL);
-    		luat_gpio_t gpio = {0};
-    		gpio.pin = conf->tp_pin_irq;
-    		gpio.mode = LUAT_GPIO_IRQ;
-    		gpio.alt_func = -1;
-    		gpio.pull = LUAT_GPIO_PULLUP;
-    		gpio.irq = LUAT_GPIO_FALLING_IRQ;
-    		gpio.irq_cb = jd9261t_irq_cb;
-    		luat_gpio_setup(&gpio);
-    	}
-    }
     luat_lcd_qspi_auto_flush_on_off(conf, 1);
     return 0;
 }

+ 0 - 25
components/lcd/luat_lib_lcd.c

@@ -146,7 +146,6 @@ static int l_lcd_init(lua_State* L) {
     conf->lcd_cs_pin = LUAT_GPIO_NONE;
     conf->pin_dc = LUAT_GPIO_NONE;
     conf->pin_pwr = LUAT_GPIO_NONE;
-    conf->tp_pin_rst = LUAT_GPIO_NONE;
     conf->interface_mode = LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_I;
     if (lua_type(L, 3) == LUA_TUSERDATA){
         // 如果是SPI Device模式, 就可能出现变量为local, 从而在某个时间点被GC掉的可能性
@@ -217,30 +216,6 @@ static int l_lcd_init(lua_State* L) {
             }
             lua_pop(L, 1);
 
-            lua_pushstring(L, "tp_driver");
-            if (LUA_TNUMBER == lua_gettable(L, 2)) {
-                conf->tp_driver_id = luaL_checkinteger(L, -1);
-            }
-            lua_pop(L, 1);
-
-            lua_pushstring(L, "tp_i2c_id");
-            if (LUA_TNUMBER == lua_gettable(L, 2)) {
-                conf->tp_i2c_id = luaL_checkinteger(L, -1);
-            }
-            lua_pop(L, 1);
-
-            lua_pushstring(L, "tp_pin_rst");
-            if (LUA_TNUMBER == lua_gettable(L, 2)) {
-                conf->tp_pin_rst = luaL_checkinteger(L, -1);
-            }
-            lua_pop(L, 1);
-
-            lua_pushstring(L, "tp_pin_irq");
-            if (LUA_TNUMBER == lua_gettable(L, 2)) {
-                conf->tp_pin_irq = luaL_checkinteger(L, -1);
-            }
-            lua_pop(L, 1);
-
             lua_pushstring(L, "direction");
             if (LUA_TNUMBER == lua_gettable(L, 2)) {
                 conf->direction = luaL_checkinteger(L, -1);

+ 1 - 0
components/tp/luat_lib_tp.c

@@ -24,6 +24,7 @@ typedef struct tp_reg {
 
 static const tp_reg_t tp_regs[] = {
     {"gt911",  &tp_config_gt911},
+	{"jd9261t_inited",  &tp_config_jd9261t_inited},
     {"", NULL}
 };
 

+ 1 - 0
components/tp/luat_tp.h

@@ -57,6 +57,7 @@ typedef enum{
 
 
 extern luat_tp_opts_t tp_config_gt911;
+extern luat_tp_opts_t tp_config_jd9261t_inited;
 
 int luat_tp_init(luat_tp_config_t* luat_tp_config);
 

+ 1 - 1
components/tp/luat_tp_gt911.c

@@ -487,5 +487,5 @@ luat_tp_opts_t tp_config_gt911 = {
     .init = tp_gt911_init,
     .deinit = tp_gt911_deinit,
     .read = tp_gt911_read,
-
+	.read_done = tp_gt911_read_done,
 };

+ 178 - 0
components/tp/luat_tp_jd9261t.c

@@ -0,0 +1,178 @@
+#include "luat_base.h"
+#include "luat_lcd.h"
+#include "luat_gpio.h"
+#include "luat_mem.h"
+#include "luat_rtos.h"
+#include "luat_tp.h"
+#define LUAT_LOG_TAG "jd9261t-tp"
+#include "luat_log.h"
+
+typedef struct
+{
+	luat_tp_config_t* config;
+	luat_rtos_timer_t scan_timer;
+	uint8_t is_inited;
+	uint8_t scan_cnt;
+	uint8_t scan_time;
+	uint8_t is_pressed;
+}jd9261t_tp_ctrl_t;
+
+static jd9261t_tp_ctrl_t jd9261t_tp;
+
+static int tp_jd9261t_read(luat_tp_config_t* luat_tp_config, luat_tp_data_t *luat_tp_data)
+{
+	uint16_t tp_x, tp_y;
+	int res;
+	uint8_t pressed = 0;
+	uint8_t buff[60];
+	buff[0] = 0x20;
+	buff[1] = 0x01;
+	buff[2] = 0x11;
+	buff[3] = 0x20;
+	res = luat_i2c_send(luat_tp_config->i2c_id, 0x68, buff, 4, 1);
+	if (res)
+	{
+		res = luat_i2c_send(luat_tp_config->i2c_id, 0x68, buff, 4, 1);
+		if (res)
+		{
+			LLOGE("TP read point failed");
+			return -1;
+		}
+	}
+	luat_timer_us_delay(15);
+	res = luat_i2c_recv(luat_tp_config->i2c_id, 0x68, buff, 60);
+	if (res)
+	{
+		res = luat_i2c_recv(luat_tp_config->i2c_id, 0x68, buff, 60);
+		if (res)
+		{
+			LLOGE("TP read point failed");
+			return -1;
+		}
+	}
+	if (!buff[0]) return -1;
+	memset(luat_tp_data, 0, sizeof(luat_tp_data_t) * LUAT_TP_TOUCH_MAX);
+	for (uint8_t i = 0; i < 10; i++)
+	{
+		if (buff[i * 5 + 3] != 0xff)
+		{
+			//LLOGI("%d, %x %x %x %x", i * 5 + 3, buff[i * 5 + 3], buff[i * 5 + 4], buff[i * 5 + 5], buff[i * 5 + 6]);
+			tp_x = buff[i * 5 + 3];
+			tp_x = (tp_x << 8) | buff[i * 5 + 4];
+			tp_y = buff[i * 5 + 5];
+			tp_y = (tp_y << 8) | buff[i * 5 + 6];
+			if (tp_x < luat_tp_config->w && tp_y < luat_tp_config->h)
+			{
+				LLOGI("TP point %d x %d y %d", i+1, tp_x, tp_y);
+				luat_tp_data[pressed].event = TP_EVENT_TYPE_DOWN;
+				luat_tp_data[pressed].x_coordinate = tp_x;
+				luat_tp_data[pressed].y_coordinate = tp_y;
+				pressed++;
+				if (pressed >= LUAT_TP_TOUCH_MAX)
+				{
+					return pressed;
+				}
+			}
+			else
+			{
+				return pressed;
+			}
+		}
+		else
+		{
+			return pressed;
+		}
+	}
+	return pressed;
+}
+
+static LUAT_RT_RET_TYPE jd9261t_scan_once(LUAT_RT_CB_PARAM)
+{
+	jd9261t_tp.scan_cnt++;
+    luat_tp_config_t* luat_tp_config = (luat_tp_config_t*)param;
+    luat_rtos_message_send(luat_tp_config->task_handle, 1, luat_tp_config);
+	if (jd9261t_tp.scan_cnt > 10)
+	{
+		luat_rtos_timer_stop(jd9261t_tp.scan_timer);
+	}
+}
+
+static int jd9261t_irq_cb(int pin, void* args)
+{
+	if (jd9261t_tp.scan_cnt > 10)
+	{
+		jd9261t_tp.scan_cnt = 0;
+		luat_start_rtos_timer(jd9261t_tp.scan_timer, jd9261t_tp.scan_time, 1);
+	}
+	return 0;
+}
+
+static int tp_jd9261t_inited_init(luat_tp_config_t* luat_tp_config)
+{
+	if (jd9261t_tp.is_inited) return -1;
+	uint8_t ID[4];
+	ID[0] = 0x40;
+	ID[1] = 0x00;
+	ID[2] = 0x80;
+	ID[3] = 0x76;
+    if (luat_tp_config->soft_i2c != NULL){
+        i2c_soft_setup(luat_tp_config->soft_i2c);
+    }else{
+        luat_i2c_setup(luat_tp_config->i2c_id, I2C_SPEED_SLOW);
+    }
+
+	if (luat_i2c_transfer(luat_tp_config->i2c_id, 0x68, ID, 4, ID, 2))
+	{
+		LLOGE("TP not detect");
+	}
+	else
+	{
+		if (luat_tp_config->refresh_rate < 10)
+		{
+			luat_tp_config->refresh_rate = 10;
+		}
+		if (luat_tp_config->refresh_rate > 50)
+		{
+			luat_tp_config->refresh_rate = 50;
+		}
+		jd9261t_tp.scan_time = (1000 / luat_tp_config->refresh_rate);
+		LLOGI("TP detect %02x%02x, refresh time %dms", ID[1], ID[0], jd9261t_tp.scan_time);
+		jd9261t_tp.config = luat_tp_config;
+		jd9261t_tp.scan_cnt = 100;
+		jd9261t_tp.scan_timer = luat_create_rtos_timer(jd9261t_scan_once, NULL, NULL);
+		luat_gpio_t gpio = {0};
+		gpio.pin = luat_tp_config->pin_int;
+		gpio.mode = LUAT_GPIO_IRQ;
+		gpio.alt_func = -1;
+		gpio.pull = (luat_tp_config->int_type == LUAT_GPIO_FALLING_IRQ)?LUAT_GPIO_PULLUP:LUAT_GPIO_PULLDOWN;
+		gpio.irq = luat_tp_config->int_type;
+		gpio.irq_cb = jd9261t_irq_cb;
+		luat_gpio_setup(&gpio);
+		jd9261t_tp.is_inited = 1;
+	}
+    return 0;
+}
+
+static int tp_jd9261t_deinit(luat_tp_config_t* luat_tp_config){
+	jd9261t_tp.is_inited = 0;
+    if (luat_tp_config->pin_int != LUAT_GPIO_NONE){
+        luat_gpio_close(luat_tp_config->pin_int);
+    }
+    if (luat_tp_config->pin_rst != LUAT_GPIO_NONE){
+        luat_gpio_close(luat_tp_config->pin_rst);
+    }
+    return 0;
+}
+
+static void tp_jd9261t_read_done(luat_tp_config_t * luat_tp_config)
+{
+
+}
+
+luat_tp_opts_t tp_config_jd9261t_inited = {
+    .name = "jd9261t_inited",
+    .init = tp_jd9261t_inited_init,
+    .deinit = tp_jd9261t_deinit,
+    .read = tp_jd9261t_read,
+	.read_done = tp_jd9261t_read_done,
+};