lib: gui: lvgl: add support for kscan axes swap and inversion

Add new Kconfig options to allow kscan axes swap and inversion. These
options are useful to align display and touch frame of reference. If a
touch API is ever introduced these options could be moved there.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2020-09-14 14:56:35 +02:00 committed by Carles Cufí
commit b28ec03f0e
2 changed files with 45 additions and 2 deletions

View file

@ -24,6 +24,24 @@ config LVGL_POINTER_KSCAN_MSGQ_COUNT
help
Maximum number of items in the keyboard scan message queue.
config LVGL_POINTER_KSCAN_SWAP_XY
bool "Swap keyboard scan X,Y axes"
help
Swap keyboard scan X,Y axes. This option can be used to align keyboard
scan coordinates with the display.
config LVGL_POINTER_KSCAN_INVERT_X
bool "Invert keyboard scan X axis"
help
Invert keyboard scan X axis. This option can be used to align keyboard
scan coordinates with the display.
config LVGL_POINTER_KSCAN_INVERT_Y
bool "Invert keyboard scan Y axis"
help
Invert keyboard scan Y axis. This option can be used to align keyboard
scan coordinates with the display.
endif # LVGL_POINTER_KSCAN
config LVGL_INDEV_DEF_READ_PERIOD

View file

@ -195,18 +195,43 @@ static void lvgl_pointer_kscan_callback(const struct device *dev,
static bool lvgl_pointer_kscan_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
lv_disp_t *disp;
const struct device *disp_dev;
struct display_capabilities cap;
lv_indev_data_t curr;
static lv_indev_data_t prev = {
.point.x = 0,
.point.y = 0,
.state = LV_INDEV_STATE_REL,
};
lv_indev_data_t curr;
if (k_msgq_get(&kscan_msgq, &curr, K_NO_WAIT) == 0) {
prev = curr;
}
disp = lv_disp_get_default();
disp_dev = disp->driver.user_data;
display_get_capabilities(disp_dev, &cap);
/* adjust kscan coordinates */
if (IS_ENABLED(CONFIG_LVGL_POINTER_KSCAN_SWAP_XY)) {
lv_coord_t x;
x = prev.point.x;
prev.point.x = prev.point.y;
prev.point.y = x;
}
if (IS_ENABLED(CONFIG_LVGL_POINTER_KSCAN_INVERT_X)) {
prev.point.x = cap.x_resolution - prev.point.x;
}
if (IS_ENABLED(CONFIG_LVGL_POINTER_KSCAN_INVERT_Y)) {
prev.point.y = cap.y_resolution - prev.point.y;
}
*data = prev;
return k_msgq_num_used_get(&kscan_msgq) > 0;