|
25 | 25 | /* Includes -----------------------------------------------------------------*/
|
26 | 26 | #include "Arduino_GigaDisplayTouch.h"
|
27 | 27 |
|
| 28 | +#if __has_include ("lvgl.h") |
| 29 | +#include "lvgl.h" |
| 30 | +#endif |
| 31 | + |
28 | 32 | /* Private defines -----------------------------------------------------------*/
|
29 | 33 | #define GT911_REG_GESTURE_START_POINT 0x814E
|
30 | 34 | #define GT911_REG_CONFIG_VERSION 0x8047
|
|
33 | 37 | rtos::Thread t;
|
34 | 38 | events::EventQueue queue(32 * EVENTS_EVENT_SIZE);
|
35 | 39 |
|
| 40 | +#if __has_include ("lvgl.h") |
| 41 | +bool lvgl_touch_pressed = false; |
| 42 | +uint16_t lvgl_touch_x_coord = 0; |
| 43 | +uint16_t lvgl_touch_y_coord = 0; |
| 44 | +#endif |
| 45 | + |
36 | 46 | /* Private function prototypes -----------------------------------------------*/
|
| 47 | +#if __has_include ("lvgl.h") |
| 48 | +void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data); |
| 49 | +#endif |
37 | 50 |
|
38 | 51 | /* Functions -----------------------------------------------------------------*/
|
39 | 52 | Arduino_GigaDisplayTouch::Arduino_GigaDisplayTouch(TwoWire& wire, uint8_t intPin, uint8_t rstPin, uint8_t addr)
|
@@ -70,14 +83,37 @@ bool Arduino_GigaDisplayTouch::begin() {
|
70 | 83 | pinMode(_intPin, INPUT);
|
71 | 84 |
|
72 | 85 | _gt911TouchHandler = nullptr;
|
| 86 | + t.start(callback(&queue, &events::EventQueue::dispatch_forever)); |
| 87 | + _irqInt.rise(queue.event(mbed::callback(this, &Arduino_GigaDisplayTouch::_gt911onIrq))); |
73 | 88 |
|
74 | 89 | /* GT911 test communication */
|
75 | 90 | uint8_t testByte;
|
76 | 91 | uint8_t error = _gt911ReadOp(GT911_REG_CONFIG_VERSION, &testByte, 1);
|
77 | 92 |
|
| 93 | +#if __has_include ("lvgl.h") |
| 94 | + static lv_indev_drv_t indev_drv; /* Descriptor of a input device driver */ |
| 95 | + lv_indev_drv_init(&indev_drv); /* Basic initialization */ |
| 96 | + indev_drv.type = LV_INDEV_TYPE_POINTER; /* Touch pad is a pointer-like device */ |
| 97 | + indev_drv.read_cb = _lvglTouchCb; /* Set your driver function */ |
| 98 | + lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv); /* Register the driver in LVGL and save the created input device object */ |
| 99 | +#endif |
| 100 | + |
78 | 101 | return (error == 0);
|
79 | 102 | }
|
80 | 103 |
|
| 104 | +#if __has_include ("lvgl.h") |
| 105 | +void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data) { |
| 106 | + data->state = (lvgl_touch_pressed) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; |
| 107 | + if(data->state == LV_INDEV_STATE_PR) { |
| 108 | + data->point.x = lvgl_touch_x_coord; |
| 109 | + data->point.y = lvgl_touch_y_coord; |
| 110 | + lvgl_touch_pressed = false; |
| 111 | + } |
| 112 | + |
| 113 | + return; |
| 114 | +} |
| 115 | +#endif |
| 116 | + |
81 | 117 | void Arduino_GigaDisplayTouch::end()
|
82 | 118 | { }
|
83 | 119 |
|
@@ -105,9 +141,6 @@ bool Arduino_GigaDisplayTouch::detect(uint8_t& contacts, GDTpoint_t* points) {
|
105 | 141 | }
|
106 | 142 |
|
107 | 143 | void Arduino_GigaDisplayTouch::attach(void (*handler)(uint8_t, GDTpoint_t*)) {
|
108 |
| - t.start(callback(&queue, &events::EventQueue::dispatch_forever)); |
109 |
| - _irqInt.rise(queue.event(mbed::callback(this, &Arduino_GigaDisplayTouch::_gt911onIrq))); |
110 |
| - |
111 | 144 | _gt911TouchHandler = handler;
|
112 | 145 | }
|
113 | 146 |
|
@@ -175,6 +208,14 @@ void Arduino_GigaDisplayTouch::_gt911onIrq() {
|
175 | 208 | }
|
176 | 209 |
|
177 | 210 | if (contacts > 0 && _gt911TouchHandler != nullptr) _gt911TouchHandler(contacts, _points);
|
| 211 | + |
| 212 | +#if __has_include ("lvgl.h") |
| 213 | + if (contacts > 0) { |
| 214 | + lvgl_touch_pressed = true; |
| 215 | + lvgl_touch_x_coord = _points[0].x; |
| 216 | + lvgl_touch_y_coord = _points[0].y; |
| 217 | + } |
| 218 | +#endif |
178 | 219 |
|
179 | 220 | _gt911WriteOp(GT911_REG_GESTURE_START_POINT, 0); /* Reset buffer status to finish the reading */
|
180 | 221 | }
|
|
0 commit comments