Touchscreen transformation issues after LVGL update

The update to LVGL 9.x introduced changes in the configuration of the display and touch screen. I have updated a working configuration based on the previous LVGL implementation (ESPHOME 2026.1.0) and having issues with the touchscreen that seem to be related to the transformation.

I am using a 320x240 touchscreen and use the following display configuration:

display:
  - platform: mipi_spi
    model: ILI9341

    buffer_size: 50%
    dimensions:
      width: 240
      height: 320
      offset_width: 0
      offset_height: 0

The screen is used in landscape mode:

lvgl:
  rotation: 90

As expected, drawing on the screen, x=0 and y=0 is top left and x=320 and y=240 is bottom right.

I have calibrated the toch screen and found the raw values for X and Y.
The calibration showed that the X and Y access are swapped.

touchscreen:
  platform: xpt2046
  display: my_display
  id: my_touchscreen
  calibration:
    y_min: 453
    y_max: 3767
    x_min: 290
    x_max: 3871
  transform:
    swap_xy: true

When testing the touchscreen, there seems to be an issue with the transformation of the raw values of the touchscreen.

Top Right returns:
x=237, y=0, x_raw=3838, y_raw=414 ---> incorrect, x should read 320 (width of the screen)

Bottom left returns:
x=1, y=319, x_raw=314, y_raw=3797 ---> incorrect, y should read 240 (height of the screen)

Bottom right returns:
x=239, y=319, x_raw=3892, y_raw=3876 --->incorrect, x should read 320, y should read 240

The transformed values for x and y show that the width and height of the screen were swapped when performing the transform.

My questions:

  • Is this a programmatic bug or did I implement the rotation in an incorrect way??

Component details
MCU: ESP32-WROOM-32D (esp-idf framework)
Display: 2.8" ILI9341 320×240 TFT via MIPI-SPI
Touch: XPT2046 resistive touchscreen (separate SPI bus)
ESPHOME version: 2026.5.0 (tested with the 2026.4.x versions too)

EDIT: I have reported this as a bug on Touchscreen transformation issues after LVGL update · Issue #25 · ESPBoards/esphome-lvgl-ui-builder

Remove the swap_xy from the touchscreen config and make sure the calibration values represent the touchscreen before any rotation. LVGL will rotate the touch points so the touchscreen config should not be doing that now.

I'd suggest you remove the rotation from the LVGL config and get it all working correctly in portrait mode, then just add the rotation back into LVGL and it should then Just Work.

Clyde,

Thanks for the reply, really appreciated. I have followed your suggestions and got it to work now.

I believe the mistakes I made was I kept the swap_xy in the touch section and it overruled the rotation of the touchscreen based on the display rotation. Once I removed it, it worked for the buttons on the various pages.

For anyone interested, the following configuration works:

touchscreen:
  calibration:
    y_min: 193           # Values from display configuration
    y_max: 3921
    x_min: 321
    x_max: 3941
  transform:             # swap_xy removed!
    mirror_x: true

lvgl:
  rotation: 90

Sample button definition:

        - button:                      
            id: btn_mode_add          
            styles:
              - style_base
            x: 0
            y: 70
            width: 155
            height: 70
            checkable: false
            widgets:
              - label:
                  align: CENTER
                  long_mode: wrap
                  text: "${txt_mode_add}"
            on_click:
              then:
                - script.execute: show_add_product
1 Like