1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-10-18     Meco Man     The first version
9  */
10 #include <lvgl.h>
11 #include <stdbool.h>
12 #include <rtdevice.h>
13 
14 #include <drv_clcd.h>
15 
16 lv_indev_t * touch_indev;
17 
18 static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
19 static rt_int16_t last_x = 0;
20 static rt_int16_t last_y = 0;
21 
input_read(lv_indev_drv_t * indev_drv,lv_indev_data_t * data)22 static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
23 {
24     data->point.x = last_x;
25     data->point.y = last_y;
26     data->state = last_state;
27 }
28 
lv_port_indev_input(rt_int16_t x,rt_int16_t y,lv_indev_state_t state)29 void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
30 {
31     last_state = state;
32     last_x = x;
33     last_y = y;
34 }
35 
lv_port_indev_init(void)36 void lv_port_indev_init(void)
37 {
38     static lv_indev_drv_t indev_drv;
39 
40     lv_indev_drv_init(&indev_drv);      /*Basic initialization*/
41     indev_drv.type = LV_INDEV_TYPE_POINTER;
42     indev_drv.read_cb = input_read;
43 
44     /*Register the driver in LVGL and save the created input device object*/
45     touch_indev = lv_indev_drv_register(&indev_drv);
46 }
47