From b088e585c506912ec025865fd36650daf317c938 Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sun, 1 Jan 2023 19:02:43 +0100 Subject: [PATCH] Overwrote the old indev driver to make the touch ic work with lvgl. Code is dirty, needs to be cleaned. --- src/W800 SDK v1.00.08/app/gfx/lv_port_indev.c | 64 ++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/src/W800 SDK v1.00.08/app/gfx/lv_port_indev.c b/src/W800 SDK v1.00.08/app/gfx/lv_port_indev.c index d3f357d..77d4f51 100644 --- a/src/W800 SDK v1.00.08/app/gfx/lv_port_indev.c +++ b/src/W800 SDK v1.00.08/app/gfx/lv_port_indev.c @@ -11,6 +11,7 @@ *********************/ #include "lv_port_indev.h" #include "touchpad.h" +#include "i2c.h" /********************* * DEFINES @@ -67,6 +68,18 @@ lv_indev_t * indev_touchpad; * GLOBAL FUNCTIONS **********************/ +uint16_t x = 0, y = 0, action = 0; + +static void touch_screen_isr(void *arg) +{ + tls_clr_gpio_irq_status(WM_IO_PB_00); + uint8_t tc_data[9]; + i2c_read(0x15, 0x00, tc_data, sizeof tc_data); + x = ((tc_data[3] & 0x0f) << 8) | tc_data[4]; + y = ((tc_data[5] & 0x0f) << 8) | tc_data[6]; + action = tc_data[3] >> 6; +} + void lv_port_indev_init(void) { /** @@ -88,7 +101,10 @@ void lv_port_indev_init(void) * -----------------*/ /*Initialize your touchpad if you have*/ - touchpad_init(); + //touchpad_init(); + tls_gpio_cfg(WM_IO_PB_00, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH); + tls_gpio_isr_register(WM_IO_PB_00, &(touch_screen_isr), NULL); + tls_gpio_irq_enable(WM_IO_PB_00, WM_GPIO_IRQ_TRIG_FALLING_EDGE); /*Register a touchpad input device*/ lv_indev_drv_init(&indev_drv); @@ -187,12 +203,12 @@ static void touchpad_init(void) } /*Will be called by the library to read the touchpad*/ -static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +/*static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { static lv_coord_t last_x = 0; static lv_coord_t last_y = 0; - /*Save the pressed coordinates and the state*/ + // Save the pressed coordinates and the state if(touchpad_is_pressed()) { touchpad_get_xy(&last_x, &last_y); data->state = LV_INDEV_STATE_PR; @@ -201,30 +217,60 @@ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) data->state = LV_INDEV_STATE_REL; } - /*Set the last pressed coordinates*/ - data->point.x = last_x; - data->point.y = last_y; + // Set the last pressed coordinates + data->point.x = 240-last_y; + data->point.y = last_x; +}*/ + +static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +{ + static lv_coord_t last_x = 0; + static lv_coord_t last_y = 0; + + // Save the pressed coordinates and the state + if(touchpad_is_pressed()) { + last_x = x; + last_y = y; + data->state = LV_INDEV_STATE_PR; + } + else { + data->state = LV_INDEV_STATE_REL; + } + + // Set the last pressed coordinates + data->point.x = 239-last_x; + data->point.y = 239-last_y; } /*Return true is the touchpad is pressed*/ -static bool touchpad_is_pressed(void) +/*static bool touchpad_is_pressed(void) { - /*Your code comes here*/ + // Your code comes here bool val = bsp_touchpad_is_pressed(); // printf("---> %d\n",val); return val; +}*/ + +static bool touchpad_is_pressed(void) +{ + return action == 2; } /*Get the x and y coordinates if the touchpad is pressed*/ static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y) { - /*Your code comes here*/ + //Your code comes here // (*x) = ; // (*y) = ; bsp_touchpad_get_xy(x, y); // printf("---> x:%d y:%d\n", (*x), (*y)); } +/*static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y) +{ + +}*/ + // /*------------------ // * Mouse // * -----------------*/