Skip to content

lvgl_v8_port, poll touch controller on interrupt only #209

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

Closed
Closed
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
23 changes: 21 additions & 2 deletions template_files/lvgl_v8_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: CC0-1.0
*/

#include "freertos/FreeRTOS.h"

#include "esp_timer.h"
#undef ESP_UTILS_LOG_TAG
#define ESP_UTILS_LOG_TAG "LvPort"
Expand Down Expand Up @@ -638,29 +640,46 @@ static lv_disp_t *display_init(LCD *lcd)
return lv_disp_drv_register(&disp_drv);
}

static SemaphoreHandle_t touch_detected;

static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
Touch *tp = (Touch *)indev_drv->user_data;
TouchPoint point;
data->state = LV_INDEV_STATE_RELEASED;

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

/* Read data from touch controller */
int read_touch_result = tp->readPoints(&point, 1, 0);
if (read_touch_result > 0) {
data->point.x = point.x;
data->point.y = point.y;
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}

static bool onTouchInterruptCallback(void *user_data) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR( touch_detected, &xHigherPriorityTaskWoken );
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
return false;
}

static lv_indev_t *indev_init(Touch *tp)
{
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");

static lv_indev_drv_t indev_drv_tp;

if(tp->isInterruptEnabled()) {
touch_detected = xSemaphoreCreateBinary();
tp->attachInterruptCallback(onTouchInterruptCallback, tp);
}
ESP_UTILS_LOGD("Register input driver to LVGL");
lv_indev_drv_init(&indev_drv_tp);
indev_drv_tp.type = LV_INDEV_TYPE_POINTER;
Expand Down
Loading