|
4 | 4 | * SPDX-License-Identifier: CC0-1.0
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +#include "freertos/FreeRTOS.h" |
| 8 | + |
7 | 9 | #include "esp_timer.h"
|
8 | 10 | #undef ESP_UTILS_LOG_TAG
|
9 | 11 | #define ESP_UTILS_LOG_TAG "LvPort"
|
@@ -638,29 +640,46 @@ static lv_disp_t *display_init(LCD *lcd)
|
638 | 640 | return lv_disp_drv_register(&disp_drv);
|
639 | 641 | }
|
640 | 642 |
|
| 643 | +static SemaphoreHandle_t touch_detected; |
| 644 | + |
641 | 645 | static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
|
642 | 646 | {
|
643 | 647 | Touch *tp = (Touch *)indev_drv->user_data;
|
644 | 648 | 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 | + } |
645 | 655 |
|
646 | 656 | /* Read data from touch controller */
|
647 | 657 | int read_touch_result = tp->readPoints(&point, 1, 0);
|
648 | 658 | if (read_touch_result > 0) {
|
649 | 659 | data->point.x = point.x;
|
650 | 660 | data->point.y = point.y;
|
651 | 661 | data->state = LV_INDEV_STATE_PRESSED;
|
652 |
| - } else { |
653 |
| - data->state = LV_INDEV_STATE_RELEASED; |
654 | 662 | }
|
655 | 663 | }
|
656 | 664 |
|
| 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 | + |
657 | 672 | static lv_indev_t *indev_init(Touch *tp)
|
658 | 673 | {
|
659 | 674 | ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
|
660 | 675 | ESP_UTILS_CHECK_FALSE_RETURN(tp->getPanelHandle() != nullptr, nullptr, "Touch device is not initialized");
|
661 | 676 |
|
662 | 677 | static lv_indev_drv_t indev_drv_tp;
|
663 | 678 |
|
| 679 | + if(tp->isInterruptEnabled()) { |
| 680 | + touch_detected = xSemaphoreCreateBinary(); |
| 681 | + tp->attachInterruptCallback(onTouchInterruptCallback, tp); |
| 682 | + } |
664 | 683 | ESP_UTILS_LOGD("Register input driver to LVGL");
|
665 | 684 | lv_indev_drv_init(&indev_drv_tp);
|
666 | 685 | indev_drv_tp.type = LV_INDEV_TYPE_POINTER;
|
|
0 commit comments