|
|
@ -11,7 +11,11 @@ |
|
|
*********************/ |
|
|
*********************/ |
|
|
#include "lv_port_indev.h" |
|
|
#include "lv_port_indev.h" |
|
|
#include "../../lvgl.h" |
|
|
#include "../../lvgl.h" |
|
|
|
|
|
#include "ft5426.h" |
|
|
|
|
|
|
|
|
|
|
|
#define DBG_TAG "LVGL_DEV" |
|
|
|
|
|
#define DBG_LVL DBG_LOG |
|
|
|
|
|
#include <rtdbg.h> |
|
|
/*********************
|
|
|
/*********************
|
|
|
* DEFINES |
|
|
* DEFINES |
|
|
*********************/ |
|
|
*********************/ |
|
|
@ -29,18 +33,18 @@ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); |
|
|
static bool touchpad_is_pressed(void); |
|
|
static bool touchpad_is_pressed(void); |
|
|
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); |
|
|
|
|
|
|
|
|
static void mouse_init(void); |
|
|
//static void mouse_init(void);
|
|
|
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); |
|
|
//static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
|
|
static bool mouse_is_pressed(void); |
|
|
//static bool mouse_is_pressed(void);
|
|
|
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y); |
|
|
//static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
|
|
|
|
|
|
|
|
|
static void keypad_init(void); |
|
|
//static void keypad_init(void);
|
|
|
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); |
|
|
//static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
|
|
static uint32_t keypad_get_key(void); |
|
|
//static uint32_t keypad_get_key(void);
|
|
|
|
|
|
|
|
|
static void encoder_init(void); |
|
|
//static void encoder_init(void);
|
|
|
static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); |
|
|
//static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
|
|
static void encoder_handler(void); |
|
|
//static void encoder_handler(void);
|
|
|
|
|
|
|
|
|
static void button_init(void); |
|
|
static void button_init(void); |
|
|
static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); |
|
|
static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); |
|
|
@ -51,13 +55,13 @@ static bool button_is_pressed(uint8_t id); |
|
|
* STATIC VARIABLES |
|
|
* STATIC VARIABLES |
|
|
**********************/ |
|
|
**********************/ |
|
|
lv_indev_t * indev_touchpad; |
|
|
lv_indev_t * indev_touchpad; |
|
|
lv_indev_t * indev_mouse; |
|
|
//lv_indev_t * indev_mouse;
|
|
|
lv_indev_t * indev_keypad; |
|
|
//lv_indev_t * indev_keypad;
|
|
|
lv_indev_t * indev_encoder; |
|
|
//lv_indev_t * indev_encoder;
|
|
|
lv_indev_t * indev_button; |
|
|
lv_indev_t * indev_button; |
|
|
|
|
|
|
|
|
static int32_t encoder_diff; |
|
|
//static int32_t encoder_diff;
|
|
|
static lv_indev_state_t encoder_state; |
|
|
//static lv_indev_state_t encoder_state;
|
|
|
|
|
|
|
|
|
/**********************
|
|
|
/**********************
|
|
|
* MACROS |
|
|
* MACROS |
|
|
@ -81,7 +85,7 @@ void lv_port_indev_init(void) |
|
|
* You should shape them according to your hardware |
|
|
* You should shape them according to your hardware |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
static lv_indev_drv_t indev_drv; |
|
|
static lv_indev_drv_t indev_touch_drv ,indev_button_drv; |
|
|
|
|
|
|
|
|
/*------------------
|
|
|
/*------------------
|
|
|
* Touchpad |
|
|
* Touchpad |
|
|
@ -91,41 +95,41 @@ void lv_port_indev_init(void) |
|
|
touchpad_init(); |
|
|
touchpad_init(); |
|
|
|
|
|
|
|
|
/*Register a touchpad input device*/ |
|
|
/*Register a touchpad input device*/ |
|
|
lv_indev_drv_init(&indev_drv); |
|
|
lv_indev_drv_init(&indev_touch_drv); |
|
|
indev_drv.type = LV_INDEV_TYPE_POINTER; |
|
|
indev_touch_drv.type = LV_INDEV_TYPE_POINTER; |
|
|
indev_drv.read_cb = touchpad_read; |
|
|
indev_touch_drv.read_cb = touchpad_read; |
|
|
indev_touchpad = lv_indev_drv_register(&indev_drv); |
|
|
indev_touchpad = lv_indev_drv_register(&indev_touch_drv); |
|
|
|
|
|
|
|
|
/*------------------
|
|
|
/*------------------
|
|
|
* Mouse |
|
|
* Mouse |
|
|
* -----------------*/ |
|
|
* -----------------*/ |
|
|
|
|
|
|
|
|
/*Initialize your mouse if you have*/ |
|
|
/*Initialize your mouse if you have*/ |
|
|
mouse_init(); |
|
|
//mouse_init();
|
|
|
|
|
|
|
|
|
/*Register a mouse input device*/ |
|
|
/*Register a mouse input device*/ |
|
|
lv_indev_drv_init(&indev_drv); |
|
|
//lv_indev_drv_init(&indev_drv);
|
|
|
indev_drv.type = LV_INDEV_TYPE_POINTER; |
|
|
//indev_drv.type = LV_INDEV_TYPE_POINTER;
|
|
|
indev_drv.read_cb = mouse_read; |
|
|
//indev_drv.read_cb = mouse_read;
|
|
|
indev_mouse = lv_indev_drv_register(&indev_drv); |
|
|
//indev_mouse = lv_indev_drv_register(&indev_drv);
|
|
|
|
|
|
|
|
|
/*Set cursor. For simplicity set a HOME symbol now.*/ |
|
|
/*Set cursor. For simplicity set a HOME symbol now.*/ |
|
|
lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act()); |
|
|
//lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act());
|
|
|
lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME); |
|
|
//lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
|
|
|
lv_indev_set_cursor(indev_mouse, mouse_cursor); |
|
|
//lv_indev_set_cursor(indev_mouse, mouse_cursor);
|
|
|
|
|
|
|
|
|
/*------------------
|
|
|
/*------------------
|
|
|
* Keypad |
|
|
* Keypad |
|
|
* -----------------*/ |
|
|
* -----------------*/ |
|
|
|
|
|
|
|
|
/*Initialize your keypad or keyboard if you have*/ |
|
|
/*Initialize your keypad or keyboard if you have*/ |
|
|
keypad_init(); |
|
|
//keypad_init();
|
|
|
|
|
|
|
|
|
/*Register a keypad input device*/ |
|
|
/*Register a keypad input device*/ |
|
|
lv_indev_drv_init(&indev_drv); |
|
|
//lv_indev_drv_init(&indev_drv);
|
|
|
indev_drv.type = LV_INDEV_TYPE_KEYPAD; |
|
|
//indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
|
|
indev_drv.read_cb = keypad_read; |
|
|
//indev_drv.read_cb = keypad_read;
|
|
|
indev_keypad = lv_indev_drv_register(&indev_drv); |
|
|
//indev_keypad = lv_indev_drv_register(&indev_drv);
|
|
|
|
|
|
|
|
|
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
|
|
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
|
|
*add objects to the group with `lv_group_add_obj(group, obj)` |
|
|
*add objects to the group with `lv_group_add_obj(group, obj)` |
|
|
@ -137,13 +141,13 @@ void lv_port_indev_init(void) |
|
|
* -----------------*/ |
|
|
* -----------------*/ |
|
|
|
|
|
|
|
|
/*Initialize your encoder if you have*/ |
|
|
/*Initialize your encoder if you have*/ |
|
|
encoder_init(); |
|
|
//encoder_init();
|
|
|
|
|
|
|
|
|
/*Register a encoder input device*/ |
|
|
/*Register a encoder input device*/ |
|
|
lv_indev_drv_init(&indev_drv); |
|
|
//lv_indev_drv_init(&indev_drv);
|
|
|
indev_drv.type = LV_INDEV_TYPE_ENCODER; |
|
|
//indev_drv.type = LV_INDEV_TYPE_ENCODER;
|
|
|
indev_drv.read_cb = encoder_read; |
|
|
//indev_drv.read_cb = encoder_read;
|
|
|
indev_encoder = lv_indev_drv_register(&indev_drv); |
|
|
//indev_encoder = lv_indev_drv_register(&indev_drv);
|
|
|
|
|
|
|
|
|
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
|
|
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
|
|
*add objects to the group with `lv_group_add_obj(group, obj)` |
|
|
*add objects to the group with `lv_group_add_obj(group, obj)` |
|
|
@ -158,10 +162,10 @@ void lv_port_indev_init(void) |
|
|
button_init(); |
|
|
button_init(); |
|
|
|
|
|
|
|
|
/*Register a button input device*/ |
|
|
/*Register a button input device*/ |
|
|
lv_indev_drv_init(&indev_drv); |
|
|
lv_indev_drv_init(&indev_button_drv); |
|
|
indev_drv.type = LV_INDEV_TYPE_BUTTON; |
|
|
indev_button_drv.type = LV_INDEV_TYPE_BUTTON; |
|
|
indev_drv.read_cb = button_read; |
|
|
indev_button_drv.read_cb = button_read; |
|
|
indev_button = lv_indev_drv_register(&indev_drv); |
|
|
indev_button = lv_indev_drv_register(&indev_button_drv); |
|
|
|
|
|
|
|
|
/*Assign buttons to points on the screen*/ |
|
|
/*Assign buttons to points on the screen*/ |
|
|
static const lv_point_t btn_points[2] = { |
|
|
static const lv_point_t btn_points[2] = { |
|
|
@ -180,6 +184,42 @@ void lv_port_indev_init(void) |
|
|
* -----------------*/ |
|
|
* -----------------*/ |
|
|
|
|
|
|
|
|
/*Initialize your touchpad*/ |
|
|
/*Initialize your touchpad*/ |
|
|
|
|
|
struct rt_touch_data *read_data; |
|
|
|
|
|
rt_device_t touch; |
|
|
|
|
|
|
|
|
|
|
|
void touchpad_thread_entry(void *parameter) |
|
|
|
|
|
{ |
|
|
|
|
|
read_data = (struct rt_touch_data *)rt_calloc(1, sizeof(struct rt_touch_data)); |
|
|
|
|
|
|
|
|
|
|
|
while(1) |
|
|
|
|
|
{ |
|
|
|
|
|
rt_device_read(touch, 0, read_data, 1); |
|
|
|
|
|
|
|
|
|
|
|
rt_thread_delay(10); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int touchpad_example(void) |
|
|
|
|
|
{ |
|
|
|
|
|
struct rt_touch_config cfg; |
|
|
|
|
|
|
|
|
|
|
|
cfg.dev_name = "i2c1"; |
|
|
|
|
|
rt_hw_ft5426_init("touch", &cfg); |
|
|
|
|
|
touch = rt_device_find("touch"); |
|
|
|
|
|
rt_device_open(touch, RT_DEVICE_FLAG_RDONLY); |
|
|
|
|
|
|
|
|
|
|
|
rt_thread_t touchpad_thread = rt_thread_create("touch", touchpad_thread_entry, RT_NULL, 800, 10, 20); |
|
|
|
|
|
if (touchpad_thread == RT_NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
LOG_D("create touchpad thread err"); |
|
|
|
|
|
return -RT_ENOMEM; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rt_thread_startup(touchpad_thread); |
|
|
|
|
|
return RT_EOK; |
|
|
|
|
|
} |
|
|
|
|
|
INIT_APP_EXPORT(touchpad_example); |
|
|
|
|
|
|
|
|
static void touchpad_init(void) |
|
|
static void touchpad_init(void) |
|
|
{ |
|
|
{ |
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
@ -194,15 +234,16 @@ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) |
|
|
/*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); |
|
|
|
|
|
|
|
|
|
|
|
/*Set the last pressed coordinates*/ |
|
|
|
|
|
data->point.x = last_y; |
|
|
|
|
|
data->point.y = last_x; |
|
|
|
|
|
|
|
|
data->state = LV_INDEV_STATE_PR; |
|
|
data->state = LV_INDEV_STATE_PR; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
data->state = LV_INDEV_STATE_REL; |
|
|
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*/ |
|
|
/*Return true is the touchpad is pressed*/ |
|
|
@ -210,6 +251,9 @@ static bool touchpad_is_pressed(void) |
|
|
{ |
|
|
{ |
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
|
|
|
|
|
|
|
|
|
if (read_data->event == RT_TOUCH_EVENT_DOWN) return true; |
|
|
|
|
|
if (read_data->event == RT_TOUCH_EVENT_MOVE) return true; |
|
|
|
|
|
if (read_data->event == RT_TOUCH_EVENT_UP) return true; |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -217,78 +261,78 @@ static bool touchpad_is_pressed(void) |
|
|
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) = read_data->x_coordinate; |
|
|
(*x) = 0; |
|
|
(*y) = read_data->y_coordinate; |
|
|
(*y) = 0; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*------------------
|
|
|
/*------------------
|
|
|
* Mouse |
|
|
* Mouse |
|
|
* -----------------*/ |
|
|
* -----------------*/ |
|
|
|
|
|
|
|
|
/*Initialize your mouse*/ |
|
|
/*Initialize your mouse*/ |
|
|
static void mouse_init(void) |
|
|
//static void mouse_init(void)
|
|
|
{ |
|
|
//{
|
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*Will be called by the library to read the mouse*/ |
|
|
/*Will be called by the library to read the mouse*/ |
|
|
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) |
|
|
//static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
|
|
{ |
|
|
//{
|
|
|
/*Get the current x and y coordinates*/ |
|
|
/*Get the current x and y coordinates*/ |
|
|
mouse_get_xy(&data->point.x, &data->point.y); |
|
|
// mouse_get_xy(&data->point.x, &data->point.y);
|
|
|
|
|
|
|
|
|
/*Get whether the mouse button is pressed or released*/ |
|
|
/*Get whether the mouse button is pressed or released*/ |
|
|
if(mouse_is_pressed()) { |
|
|
// if(mouse_is_pressed()) {
|
|
|
data->state = LV_INDEV_STATE_PR; |
|
|
// data->state = LV_INDEV_STATE_PR;
|
|
|
} |
|
|
// }
|
|
|
else { |
|
|
// else {
|
|
|
data->state = LV_INDEV_STATE_REL; |
|
|
// data->state = LV_INDEV_STATE_REL;
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*Return true is the mouse button is pressed*/ |
|
|
/*Return true is the mouse button is pressed*/ |
|
|
static bool mouse_is_pressed(void) |
|
|
//static bool mouse_is_pressed(void)
|
|
|
{ |
|
|
//{
|
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
|
|
|
|
|
|
return false; |
|
|
// return false;
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*Get the x and y coordinates if the mouse is pressed*/ |
|
|
/*Get the x and y coordinates if the mouse is pressed*/ |
|
|
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y) |
|
|
//static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
|
|
|
{ |
|
|
//{
|
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
|
|
|
|
|
|
(*x) = 0; |
|
|
// (*x) = 0;
|
|
|
(*y) = 0; |
|
|
// (*y) = 0;
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*------------------
|
|
|
/*------------------
|
|
|
* Keypad |
|
|
* Keypad |
|
|
* -----------------*/ |
|
|
* -----------------*/ |
|
|
|
|
|
|
|
|
/*Initialize your keypad*/ |
|
|
/*Initialize your keypad*/ |
|
|
static void keypad_init(void) |
|
|
//static void keypad_init(void)
|
|
|
{ |
|
|
//{
|
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*Will be called by the library to read the mouse*/ |
|
|
/*Will be called by the library to read the mouse*/ |
|
|
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) |
|
|
//static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
|
|
{ |
|
|
//{
|
|
|
static uint32_t last_key = 0; |
|
|
// static uint32_t last_key = 0;
|
|
|
|
|
|
|
|
|
/*Get the current x and y coordinates*/ |
|
|
/*Get the current x and y coordinates*/ |
|
|
mouse_get_xy(&data->point.x, &data->point.y); |
|
|
// mouse_get_xy(&data->point.x, &data->point.y);
|
|
|
|
|
|
|
|
|
/*Get whether the a key is pressed and save the pressed key*/ |
|
|
/*Get whether the a key is pressed and save the pressed key*/ |
|
|
uint32_t act_key = keypad_get_key(); |
|
|
// uint32_t act_key = keypad_get_key();
|
|
|
if(act_key != 0) { |
|
|
// if(act_key != 0) {
|
|
|
data->state = LV_INDEV_STATE_PR; |
|
|
// data->state = LV_INDEV_STATE_PR;
|
|
|
|
|
|
|
|
|
/*Translate the keys to LVGL control characters according to your key definitions*/ |
|
|
/*Translate the keys to LVGL control characters according to your key definitions*/ |
|
|
switch(act_key) { |
|
|
/* switch(act_key) {
|
|
|
case 1: |
|
|
case 1: |
|
|
act_key = LV_KEY_NEXT; |
|
|
act_key = LV_KEY_NEXT; |
|
|
break; |
|
|
break; |
|
|
@ -312,43 +356,43 @@ static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) |
|
|
data->state = LV_INDEV_STATE_REL; |
|
|
data->state = LV_INDEV_STATE_REL; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
data->key = last_key; |
|
|
data->key = last_key;*/ |
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*Get the currently being pressed key. 0 if no key is pressed*/ |
|
|
/*Get the currently being pressed key. 0 if no key is pressed*/ |
|
|
static uint32_t keypad_get_key(void) |
|
|
//static uint32_t keypad_get_key(void)
|
|
|
{ |
|
|
//{
|
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
|
|
|
|
|
|
return 0; |
|
|
// return 0;
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*------------------
|
|
|
/*------------------
|
|
|
* Encoder |
|
|
* Encoder |
|
|
* -----------------*/ |
|
|
* -----------------*/ |
|
|
|
|
|
|
|
|
/*Initialize your keypad*/ |
|
|
/*Initialize your keypad*/ |
|
|
static void encoder_init(void) |
|
|
//static void encoder_init(void)
|
|
|
{ |
|
|
//{
|
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*Will be called by the library to read the encoder*/ |
|
|
/*Will be called by the library to read the encoder*/ |
|
|
static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) |
|
|
//static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
|
|
{ |
|
|
//{
|
|
|
|
|
|
|
|
|
data->enc_diff = encoder_diff; |
|
|
// data->enc_diff = encoder_diff;
|
|
|
data->state = encoder_state; |
|
|
// data->state = encoder_state;
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*Call this function in an interrupt to process encoder events (turn, press)*/ |
|
|
/*Call this function in an interrupt to process encoder events (turn, press)*/ |
|
|
static void encoder_handler(void) |
|
|
//static void encoder_handler(void)
|
|
|
{ |
|
|
//{
|
|
|
/*Your code comes here*/ |
|
|
/*Your code comes here*/ |
|
|
|
|
|
|
|
|
encoder_diff += 0; |
|
|
// encoder_diff += 0;
|
|
|
encoder_state = LV_INDEV_STATE_REL; |
|
|
// encoder_state = LV_INDEV_STATE_REL;
|
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
/*------------------
|
|
|
/*------------------
|
|
|
* Button |
|
|
* Button |
|
|
|