Skip to content

Commit

Permalink
Merge pull request #5 from arduino-libraries/lvgl9
Browse files Browse the repository at this point in the history
Compatibility: port indev to lvgl9
  • Loading branch information
leonardocavagnis authored Mar 18, 2024
2 parents 15f6c1b + 439b0f9 commit 118d166
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/Arduino_GigaDisplayTouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ Arduino_GigaDisplayTouch * gThis;

/* Private function prototypes -----------------------------------------------*/
#if __has_include ("lvgl.h")
#if (LVGL_VERSION_MAJOR == 9)
void _lvglTouchCb(lv_indev_t * indev, lv_indev_data_t * data);
#else
void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data);
#endif
#endif

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

#if __has_include ("lvgl.h")
#if (LVGL_VERSION_MAJOR == 9)
static lv_indev_t * indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, _lvglTouchCb);
#else
static lv_indev_drv_t indev_drv; /* Descriptor of a input device driver */
lv_indev_drv_init(&indev_drv); /* Basic initialization */
indev_drv.type = LV_INDEV_TYPE_POINTER; /* Touch pad is a pointer-like device */
indev_drv.type = LV_INDEV_TYPE_POINTER; /* Touch pad is a pointer-like device */
indev_drv.read_cb = _lvglTouchCb; /* Set your driver function */
lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv); /* Register the driver in LVGL and save the created input device object */

gThis = this;
#endif
#endif

gThis = this;
return (error == 0);
}

#if __has_include ("lvgl.h")
#if (LVGL_VERSION_MAJOR == 9)
void _lvglTouchCb(lv_indev_t * indev, lv_indev_data_t * data) {
uint8_t contacts;
GDTpoint_t points[5];

contacts = gThis->getTouchPoints(points);

if(contacts > 0) {
data->state = LV_INDEV_STATE_PRESSED;
data->point.x = points[0].x;
data->point.y = points[0].y;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}

return;
}
#else
void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data) {
uint8_t contacts;
GDTpoint_t points[5];
Expand All @@ -114,6 +141,7 @@ void _lvglTouchCb(lv_indev_drv_t * indev, lv_indev_data_t * data) {
return;
}
#endif
#endif

void Arduino_GigaDisplayTouch::end()
{ }
Expand Down

0 comments on commit 118d166

Please sign in to comment.