2025-06-20 11:24:14 +08:00
|
|
|
/**
|
|
|
|
|
* @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 "lcd.h"
|
|
|
|
|
#include "gt911.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void touchpad_init(void);
|
2025-12-04 21:06:43 +08:00
|
|
|
static void touchpad_read(lv_indev_t * indev, lv_indev_data_t * data);
|
2025-06-20 11:24:14 +08:00
|
|
|
static bool touchpad_is_pressed(void);
|
2025-12-04 21:06:43 +08:00
|
|
|
static void touchpad_get_xy(int32_t * x, int32_t * y);
|
2025-06-20 11:24:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lv_indev_t * indev_touchpad;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void lv_port_indev_init(void)
|
|
|
|
|
{
|
2025-12-04 21:06:43 +08:00
|
|
|
touchpad_init();
|
2025-06-20 11:24:14 +08:00
|
|
|
|
|
|
|
|
/*Register a touchpad input device*/
|
2025-12-04 21:06:43 +08:00
|
|
|
indev_touchpad = lv_indev_create();
|
|
|
|
|
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
|
|
|
|
|
lv_indev_set_read_cb(indev_touchpad, touchpad_read);
|
2025-06-20 11:24:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
|
|
/*------------------
|
|
|
|
|
* Touchpad
|
|
|
|
|
* -----------------*/
|
|
|
|
|
|
|
|
|
|
/*Initialize your touchpad*/
|
|
|
|
|
static void touchpad_init(void)
|
|
|
|
|
{
|
|
|
|
|
/*Your code comes here*/
|
|
|
|
|
GT911_Init(0xBA);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*Will be called by the library to read the touchpad*/
|
2025-12-04 21:06:43 +08:00
|
|
|
static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
|
2025-06-20 11:24:14 +08:00
|
|
|
{
|
|
|
|
|
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()) {
|
|
|
|
|
touchpad_get_xy(&last_x, &last_y);
|
|
|
|
|
data->state = LV_INDEV_STATE_PR;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
data->state = LV_INDEV_STATE_REL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*Set the last pressed coordinates*/
|
|
|
|
|
data->point.x = last_x;
|
|
|
|
|
data->point.y = last_y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*Return true is the touchpad is pressed*/
|
|
|
|
|
static bool touchpad_is_pressed(void)
|
|
|
|
|
{
|
|
|
|
|
/*Your code comes here*/
|
|
|
|
|
|
|
|
|
|
if(GT911_Scanf() != 0)//ÌîдÊÇ·ñ±»°´Ïµĺ¯Êý
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*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*/
|
|
|
|
|
|
|
|
|
|
uint16_t m_x,m_y;
|
|
|
|
|
|
|
|
|
|
GT911_getPos(&m_x,&m_y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(*x) = m_x;
|
|
|
|
|
(*y) = m_y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else /*Enable this file at the top*/
|
|
|
|
|
|
|
|
|
|
/*This dummy typedef exists purely to silence -Wpedantic.*/
|
|
|
|
|
typedef int keep_pedantic_happy;
|
|
|
|
|
#endif
|