Cleaned the lv_port_indev c file to now use the CST816D chip driver
This commit is contained in:
parent
a5407e8de9
commit
2c854e2535
123
src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c
Normal file
123
src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/**
|
||||||
|
* @file lv_port_indev_templ.c
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/
|
||||||
|
#if 1
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* INCLUDES
|
||||||
|
*********************/
|
||||||
|
#include "lv_port_indev.h"
|
||||||
|
#include "wm_gpio.h"
|
||||||
|
#include "app_config.h"
|
||||||
|
#include "CST816D.h"
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* DEFINES
|
||||||
|
*********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* TYPEDEFS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* STATIC PROTOTYPES
|
||||||
|
**********************/
|
||||||
|
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* STATIC VARIABLES
|
||||||
|
**********************/
|
||||||
|
static lv_indev_t * indev_touchpad;
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* MACROS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* LOCAL FUNCTIONS
|
||||||
|
**********************/
|
||||||
|
static void touch_panel_isr(void *arg)
|
||||||
|
{
|
||||||
|
CST816D_Touch_Data_t *p = arg;
|
||||||
|
tls_clr_gpio_irq_status(LCD_TOUCH_PANEL_IRQ);
|
||||||
|
CST816D_read_touch_event(p);
|
||||||
|
}
|
||||||
|
/**********************
|
||||||
|
* GLOBAL FUNCTIONS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
void lv_port_indev_init(void)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Here you will find example implementation of input devices supported by LittelvGL:
|
||||||
|
* - Touchpad
|
||||||
|
* - Mouse (with cursor support)
|
||||||
|
* - Keypad (supports GUI usage only with key)
|
||||||
|
* - Encoder (supports GUI usage only with: left, right, push)
|
||||||
|
* - Button (external buttons to press points on the screen)
|
||||||
|
*
|
||||||
|
* The `..._read()` function are only examples.
|
||||||
|
* You should shape them according to your hardware
|
||||||
|
*/
|
||||||
|
|
||||||
|
static lv_indev_drv_t indev_drv;
|
||||||
|
static CST816D_Touch_Data_t CST816D_Touch_Data;
|
||||||
|
|
||||||
|
/*------------------
|
||||||
|
* Touchpad
|
||||||
|
* -----------------*/
|
||||||
|
|
||||||
|
/*Initialize your touchpad if you have*/
|
||||||
|
// Let's configure the needed interrupt pin to detect and read touch screen events
|
||||||
|
tls_gpio_cfg(LCD_TOUCH_PANEL_IRQ, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH);
|
||||||
|
tls_gpio_isr_register(LCD_TOUCH_PANEL_IRQ, &(touch_panel_isr), &CST816D_Touch_Data);
|
||||||
|
tls_gpio_irq_enable(LCD_TOUCH_PANEL_IRQ, WM_GPIO_IRQ_TRIG_FALLING_EDGE);
|
||||||
|
|
||||||
|
memset(&CST816D_Touch_Data, 0, sizeof CST816D_Touch_Data);
|
||||||
|
|
||||||
|
/*Register a touchpad input device*/
|
||||||
|
lv_indev_drv_init(&indev_drv);
|
||||||
|
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||||
|
indev_drv.read_cb = touchpad_read;
|
||||||
|
indev_drv.user_data = &CST816D_Touch_Data;
|
||||||
|
indev_touchpad = lv_indev_drv_register(&indev_drv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* STATIC FUNCTIONS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/*------------------
|
||||||
|
* Touchpad
|
||||||
|
* -----------------*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
CST816D_Touch_Data_t *p = indev_drv->user_data;
|
||||||
|
|
||||||
|
// Save the pressed coordinates and the state
|
||||||
|
if(p->isValid && p->event == CST816D_Event_Pressed) {
|
||||||
|
last_x = p->touch_x;
|
||||||
|
last_y = p->touch_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /*Enable this file at the top*/
|
||||||
|
|
||||||
|
/*This dummy typedef exists purely to silence -Wpedantic.*/
|
||||||
|
typedef int keep_pedantic_happy;
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user