Skip to content

Commit a32f230

Browse files
committed
lvgl_v8_port:
only poll touch screen if interrupt happened. Prevents cst816s and similar, which are only accessible after resume, from generating i2c errors.
1 parent 2128a6e commit a32f230

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

template_files/lvgl_v8_port.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: CC0-1.0
55
*/
66

7+
#include "freertos/FreeRTOS.h"
8+
79
#include "esp_timer.h"
810
#undef ESP_UTILS_LOG_TAG
911
#define ESP_UTILS_LOG_TAG "LvPort"
@@ -638,29 +640,46 @@ static lv_disp_t *display_init(LCD *lcd)
638640
return lv_disp_drv_register(&disp_drv);
639641
}
640642

643+
static SemaphoreHandle_t touch_detected;
644+
641645
static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
642646
{
643647
Touch *tp = (Touch *)indev_drv->user_data;
644648
TouchPoint point;
649+
data->state = LV_INDEV_STATE_RELEASED;
650+
651+
/* if we are interrupt driven wait for the ISR to fire */
652+
if( tp->isInterruptEnabled() && (xSemaphoreTake( touch_detected, 0 ) == pdFALSE) ) {
653+
return;
654+
}
645655

646656
/* Read data from touch controller */
647657
int read_touch_result = tp->readPoints(&point, 1, 0);
648658
if (read_touch_result > 0) {
649659
data->point.x = point.x;
650660
data->point.y = point.y;
651661
data->state = LV_INDEV_STATE_PRESSED;
652-
} else {
653-
data->state = LV_INDEV_STATE_RELEASED;
654662
}
655663
}
656664

665+
static bool onTouchInterruptCallback(void *user_data) {
666+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
667+
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
668+
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
669+
return false;
670+
}
671+
657672
static lv_indev_t *indev_init(Touch *tp)
658673
{
659674
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
660675
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
661676

662677
static lv_indev_drv_t indev_drv_tp;
663678

679+
if(tp->isInterruptEnabled()) {
680+
touch_detected = xSemaphoreCreateBinary();
681+
tp->attachInterruptCallback(onTouchInterruptCallback, tp);
682+
}
664683
ESP_UTILS_LOGD("Register input driver to LVGL");
665684
lv_indev_drv_init(&indev_drv_tp);
666685
indev_drv_tp.type = LV_INDEV_TYPE_POINTER;

0 commit comments

Comments
 (0)