smartpanle / PanelLan_esp32_arduino

PanelLan esp32 arduino lib, supports PanelLan displays, SC01, SC01_PLUS(ZX3D50CE08S), SC02(ZX4D30NE01S-UR), SC05(ZX7D00CE01S), KC01(ZX2D10GE01S), BC02(ZX3D95CE01S-TR), SC07(ZX4D30CE08S-4827)
MIT License
16 stars 3 forks source link

Touch controller CST3240 doesn't work well with LVGL #11

Closed ilnavigante closed 1 month ago

ilnavigante commented 2 months ago

Hey,

I was running the LVGL demo for Arduino, using the BOARD_SC07 (WT32S3-43H), and as soon as I tried the lv_demo_widgets() for testing the whole system, I found out the touch controller was very glitchy.

I think the reason is because the CST3240 not only reports TOUCH_PRESSED events, but also TOUCH_RELEASE ones, and the LVGL library doesn't support that.

My quick fix was to copy the event check from the driver in the QMSD repository, QMSD-ESP32-BSP/components/qmsd_touch/cst3240/cst3240.c:

static qmsd_err_t cst3240_read_point_data(touch_panel_points_t *point) {
    ...
    point->event = (data[0] & 0x04)? TOUCH_EVT_PRESS : TOUCH_EVT_RELEASE;
    ...
}

and ignore any RELEASE event, PanelLan_esp32_arduino/src/board/sc07/Touch_CST3240.cpp:

uint_fast8_t Touch_CST3240::getTouchRaw(touch_point_t *__restrict tp, uint_fast8_t count) {
    ...
    uint8_t event = (data[0] & 0x04) ? TOUCH_EVT_PRESS : TOUCH_EVT_RELEASE;
    if (event == TOUCH_EVT_RELEASE) {
      return 0;
    }
    ...
}

It worked for me, I don't know if it's right. Also, the Arduino demo seems to run the display 4 times slower than the ESP demo one, but that's another issue, don't know if it's related somehow.

EeeeBin commented 2 months ago

hi, ilnavigante

The touch issue has already been tested and investigated.

There are two main reasons why Arduino is slower compared to ESP-IDF:

  1. The tuning and adaptation of the LVGL driver in ESP-IDF, particularly the buffer configuration and update thread, differ from those in Arduino.
  2. The screen clock (clk) in the Arduino driver for the NV3041A is lower than that in IDF. When the clock is matched, the screen does not function correctly in the Arduino driver, though the exact cause of this is still unclear.

If you're accustomed to using GFX for screen rendering, Arduino should meet your needs. However, if LVGL is required, developing with ESP-IDF would be a more suitable option.

EeeeBin commented 1 month ago

Touch fixed: https://github.com/smartpanle/PanelLan_esp32_arduino/commit/26bef953b02b438bfdcbc11c4613ede8d4a1df98