Overwrote the old indev driver to make the touch ic work with lvgl. Code is dirty, needs to be cleaned.

This commit is contained in:
Th3maz1ng 2023-01-01 19:02:43 +01:00
parent b5fc007404
commit b088e585c5

View File

@ -11,6 +11,7 @@
*********************/ *********************/
#include "lv_port_indev.h" #include "lv_port_indev.h"
#include "touchpad.h" #include "touchpad.h"
#include "i2c.h"
/********************* /*********************
* DEFINES * DEFINES
@ -67,6 +68,18 @@ lv_indev_t * indev_touchpad;
* GLOBAL FUNCTIONS * 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) void lv_port_indev_init(void)
{ {
/** /**
@ -88,7 +101,10 @@ void lv_port_indev_init(void)
* -----------------*/ * -----------------*/
/*Initialize your touchpad if you have*/ /*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*/ /*Register a touchpad input device*/
lv_indev_drv_init(&indev_drv); 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*/ /*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_x = 0;
static lv_coord_t last_y = 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()) { if(touchpad_is_pressed()) {
touchpad_get_xy(&last_x, &last_y); touchpad_get_xy(&last_x, &last_y);
data->state = LV_INDEV_STATE_PR; 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; data->state = LV_INDEV_STATE_REL;
} }
/*Set the last pressed coordinates*/ // Set the last pressed coordinates
data->point.x = last_x; data->point.x = 240-last_y;
data->point.y = 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*/ /*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(); bool val = bsp_touchpad_is_pressed();
// printf("---> %d\n",val); // printf("---> %d\n",val);
return val; return val;
}*/
static bool touchpad_is_pressed(void)
{
return action == 2;
} }
/*Get the x and y coordinates if the touchpad is pressed*/ /*Get the x and y coordinates if the touchpad is pressed*/
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y) static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
{ {
/*Your code comes here*/ //Your code comes here
// (*x) = ; // (*x) = ;
// (*y) = ; // (*y) = ;
bsp_touchpad_get_xy(x, y); bsp_touchpad_get_xy(x, y);
// printf("---> x:%d y:%d\n", (*x), (*y)); // printf("---> x:%d y:%d\n", (*x), (*y));
} }
/*static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
{
}*/
// /*------------------ // /*------------------
// * Mouse // * Mouse
// * -----------------*/ // * -----------------*/