Skip to content

Compatibility: port indev to lvgl9 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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