Skip to content

Commit 4096498

Browse files
committed
fix(examples): lvgl_port_v8 only poll touch screen if interrupt happened
@hegdi (#209) Closes #209
1 parent f0dcf0e commit 4096498

File tree

9 files changed

+162
-17
lines changed

9 files changed

+162
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
* feat(docs): provides an example of how to integrate this library into micropython by @tsteinruecken (#190)
88

9+
### Bugfixes:
10+
11+
* fix(examples): lvgl_port_v8 only poll touch screen if interrupt happened @hegdi (#209)
12+
913
## v1.0.2 - 2025-04-23
1014

1115
### Enhancements:

examples/arduino/gui/lvgl_v8/simple_port/lvgl_v8_port.cpp

Lines changed: 22 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,47 @@ 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+
{
667+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
668+
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
669+
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
670+
return false;
671+
}
672+
657673
static lv_indev_t *indev_init(Touch *tp)
658674
{
659675
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
660676
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
661677

662678
static lv_indev_drv_t indev_drv_tp;
663679

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

examples/arduino/gui/lvgl_v8/simple_rotation/lvgl_v8_port.cpp

Lines changed: 22 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,47 @@ 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+
{
667+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
668+
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
669+
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
670+
return false;
671+
}
672+
657673
static lv_indev_t *indev_init(Touch *tp)
658674
{
659675
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
660676
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
661677

662678
static lv_indev_drv_t indev_drv_tp;
663679

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

examples/arduino/gui/lvgl_v8/squareline_port/lvgl_v8_port.cpp

Lines changed: 22 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,47 @@ 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+
{
667+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
668+
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
669+
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
670+
return false;
671+
}
672+
657673
static lv_indev_t *indev_init(Touch *tp)
658674
{
659675
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
660676
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
661677

662678
static lv_indev_drv_t indev_drv_tp;
663679

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

examples/arduino/gui/lvgl_v8/squareline_wifi_clock/lvgl_v8_port.cpp

Lines changed: 22 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,47 @@ 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+
{
667+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
668+
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
669+
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
670+
return false;
671+
}
672+
657673
static lv_indev_t *indev_init(Touch *tp)
658674
{
659675
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
660676
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
661677

662678
static lv_indev_drv_t indev_drv_tp;
663679

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

examples/esp_idf/lvgl_v8_port/main/lvgl_v8_port.cpp

Lines changed: 22 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,47 @@ 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+
{
667+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
668+
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
669+
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
670+
return false;
671+
}
672+
657673
static lv_indev_t *indev_init(Touch *tp)
658674
{
659675
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
660676
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
661677

662678
static lv_indev_drv_t indev_drv_tp;
663679

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

examples/platformio/lvgl_v8_port/src/lvgl_v8_port.cpp

Lines changed: 22 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,47 @@ 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+
{
667+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
668+
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
669+
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
670+
return false;
671+
}
672+
657673
static lv_indev_t *indev_init(Touch *tp)
658674
{
659675
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
660676
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
661677

662678
static lv_indev_drv_t indev_drv_tp;
663679

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

template_files/lvgl_v8_port.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
649649
data->state = LV_INDEV_STATE_RELEASED;
650650

651651
/* if we are interrupt driven wait for the ISR to fire */
652-
if( tp->isInterruptEnabled() && (xSemaphoreTake( touch_detected, 0 ) == pdFALSE) ) {
652+
if ( tp->isInterruptEnabled() && (xSemaphoreTake( touch_detected, 0 ) == pdFALSE) ) {
653653
return;
654654
}
655655

@@ -662,7 +662,8 @@ static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
662662
}
663663
}
664664

665-
static bool onTouchInterruptCallback(void *user_data) {
665+
static bool onTouchInterruptCallback(void *user_data)
666+
{
666667
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
667668
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
668669
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
@@ -676,7 +677,7 @@ static lv_indev_t *indev_init(Touch *tp)
676677

677678
static lv_indev_drv_t indev_drv_tp;
678679

679-
if(tp->isInterruptEnabled()) {
680+
if (tp->isInterruptEnabled()) {
680681
touch_detected = xSemaphoreCreateBinary();
681682
tp->attachInterruptCallback(onTouchInterruptCallback, tp);
682683
}

0 commit comments

Comments
 (0)