Skip to content

Commit 118d166

Browse files
Merge pull request #5 from arduino-libraries/lvgl9
Compatibility: port indev to lvgl9
2 parents 15f6c1b + 439b0f9 commit 118d166

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Arduino_GigaDisplayTouch.cpp

+31-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ Arduino_GigaDisplayTouch * gThis;
4040

4141
/* Private function prototypes -----------------------------------------------*/
4242
#if __has_include ("lvgl.h")
43+
#if (LVGL_VERSION_MAJOR == 9)
44+
void _lvglTouchCb(lv_indev_t * indev, lv_indev_data_t * data);
45+
#else
4346
void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data);
4447
#endif
48+
#endif
4549

4650
/* Functions -----------------------------------------------------------------*/
4751
Arduino_GigaDisplayTouch::Arduino_GigaDisplayTouch(TwoWire& wire, uint8_t intPin, uint8_t rstPin, uint8_t addr)
@@ -84,19 +88,42 @@ bool Arduino_GigaDisplayTouch::begin() {
8488
uint8_t error = _gt911ReadOp(GT911_REG_CONFIG_VERSION, &testByte, 1);
8589

8690
#if __has_include ("lvgl.h")
91+
#if (LVGL_VERSION_MAJOR == 9)
92+
static lv_indev_t * indev = lv_indev_create();
93+
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
94+
lv_indev_set_read_cb(indev, _lvglTouchCb);
95+
#else
8796
static lv_indev_drv_t indev_drv; /* Descriptor of a input device driver */
8897
lv_indev_drv_init(&indev_drv); /* Basic initialization */
89-
indev_drv.type = LV_INDEV_TYPE_POINTER; /* Touch pad is a pointer-like device */
98+
indev_drv.type = LV_INDEV_TYPE_POINTER; /* Touch pad is a pointer-like device */
9099
indev_drv.read_cb = _lvglTouchCb; /* Set your driver function */
91100
lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv); /* Register the driver in LVGL and save the created input device object */
92-
93-
gThis = this;
101+
#endif
94102
#endif
95103

104+
gThis = this;
96105
return (error == 0);
97106
}
98107

99108
#if __has_include ("lvgl.h")
109+
#if (LVGL_VERSION_MAJOR == 9)
110+
void _lvglTouchCb(lv_indev_t * indev, lv_indev_data_t * data) {
111+
uint8_t contacts;
112+
GDTpoint_t points[5];
113+
114+
contacts = gThis->getTouchPoints(points);
115+
116+
if(contacts > 0) {
117+
data->state = LV_INDEV_STATE_PRESSED;
118+
data->point.x = points[0].x;
119+
data->point.y = points[0].y;
120+
} else {
121+
data->state = LV_INDEV_STATE_RELEASED;
122+
}
123+
124+
return;
125+
}
126+
#else
100127
void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data) {
101128
uint8_t contacts;
102129
GDTpoint_t points[5];
@@ -114,6 +141,7 @@ void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data) {
114141
return;
115142
}
116143
#endif
144+
#endif
117145

118146
void Arduino_GigaDisplayTouch::end()
119147
{ }

0 commit comments

Comments
 (0)