Skip to content

esp_lvgl_port direct_mode on st7789 display corruption (BSP-662) #548

Open
@mutatrum

Description

@mutatrum

Board

ESP32-P4 Dev Board

Hardware Description

ST7789 display

IDE Name

VSCode

Operating System

Ubuntu 22.04
ESP-IDF v5.4-dev-4291-g7a305c0284

Description

I'm trying to use direct_mode on this display, but that corrupts the display on animated elements, such as a scrolling label, color changes on focus or other moving parts. In some cases, the label doesn't show at all, in some cases (depending on geometry of the element) it's corrupted.

This looks similar to this issue: https://forum.lvgl.io/t/lvgl-8-3-2-corrupted-display-when-disp-drv-direct-mode-1/9892

dependencies:
  idf: ">=5.4.0"
  lvgl/lvgl: "9.2.2"
  esp_lvgl_port: "2.5.0"

When setting LVGL_DIRECT_MODE to true, the issue is shown. I tried to make a minimal sketch to show the issue.

Sketch

#include "driver/gpio.h"

#include "esp_lvgl_port.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"

#include "lvgl.h"

#define TAG "app_main"

#define LVGL_DIRECT_MODE (false)

#define LCD_H_RES     (320)
#define LCD_V_RES     (240)

#define LCD_SPI_NUM   (SPI3_HOST)

#define LCD_GPIO_BL   (GPIO_NUM_3)
#define LCD_GPIO_MOSI (GPIO_NUM_4)
#define LCD_GPIO_CS   (GPIO_NUM_5)
#define LCD_GPIO_RST  (GPIO_NUM_6)
#define LCD_GPIO_SCLK (GPIO_NUM_24)
#define LCD_GPIO_DC   (GPIO_NUM_33)

#define LCD_SWAP_XY   (true)
#define LCD_MIRROR_X  (true)
#define LCD_MIRROR_Y  (false)

static esp_lcd_panel_io_handle_t lcd_io = NULL;
static esp_lcd_panel_handle_t lcd_panel = NULL;

void app_main(void)
{
    const gpio_config_t bk_gpio_config = {
        .mode = GPIO_MODE_OUTPUT,
        .pin_bit_mask = 1ULL << LCD_GPIO_BL,
    };
    ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));

    const spi_bus_config_t buscfg = {
        .sclk_io_num = LCD_GPIO_SCLK,
        .mosi_io_num = LCD_GPIO_MOSI,
        .miso_io_num = GPIO_NUM_NC,
        .quadwp_io_num = GPIO_NUM_NC,
        .quadhd_io_num = GPIO_NUM_NC,
        .max_transfer_sz = LCD_H_RES * LCD_V_RES * sizeof(uint16_t),
    };
    ESP_ERROR_CHECK(spi_bus_initialize(LCD_SPI_NUM, &buscfg, SPI_DMA_CH_AUTO));

    const esp_lcd_panel_io_spi_config_t io_config = {
        .dc_gpio_num = LCD_GPIO_DC,
        .cs_gpio_num = LCD_GPIO_CS,
        .pclk_hz = 20000000,
        .lcd_cmd_bits = 8,
        .lcd_param_bits = 8,
        .spi_mode = 0,
        .trans_queue_depth = 10,
    };
    ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_SPI_NUM, &io_config, &lcd_io));

    const esp_lcd_panel_dev_config_t panel_config = {
        .data_endian = LCD_RGB_DATA_ENDIAN_LITTLE,
        .reset_gpio_num = LCD_GPIO_RST,
        .color_space = ESP_LCD_COLOR_SPACE_RGB,
        .bits_per_pixel = 16,
    };
    ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(lcd_io, &panel_config, &lcd_panel));

    ESP_ERROR_CHECK(esp_lcd_panel_reset(lcd_panel));
    ESP_ERROR_CHECK(esp_lcd_panel_init(lcd_panel));
    ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(lcd_panel, LCD_SWAP_XY));
    ESP_ERROR_CHECK(esp_lcd_panel_mirror(lcd_panel, LCD_MIRROR_X, LCD_MIRROR_Y));
    ESP_ERROR_CHECK(esp_lcd_panel_invert_color(lcd_panel, true));

    ESP_ERROR_CHECK(gpio_set_level(LCD_GPIO_BL, 1));

    const lvgl_port_cfg_t lvgl_cfg = {
        .task_priority = 12,
        .task_stack = 8192,
        .task_affinity = -1,
        .task_max_sleep_ms = 500,
        .timer_period_ms = 5,
    };
    ESP_ERROR_CHECK(lvgl_port_init(&lvgl_cfg));

    const lvgl_port_display_cfg_t disp_cfg = {
        .io_handle = lcd_io,
        .panel_handle = lcd_panel,
        .buffer_size = LCD_H_RES * LCD_V_RES,
        .double_buffer = true,
        .hres = LCD_H_RES,
        .vres = LCD_V_RES,
        .monochrome = false,
        .rotation = {
            .swap_xy = LCD_SWAP_XY,
            .mirror_x = LCD_MIRROR_X,
            .mirror_y = LCD_MIRROR_Y,
        },
        .flags = {
            .buff_dma = true,
            .buff_spiram = false,
            .direct_mode = LVGL_DIRECT_MODE,
            .full_refresh = false,
        },
    };

    lv_display_t * display = lvgl_port_add_disp(&disp_cfg);

    ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(lcd_panel, true));
    
    if (lvgl_port_lock(0)) {

        static lv_style_t style_scr;
        lv_style_init(&style_scr);
        lv_style_set_bg_color(&style_scr, lv_color_black());
        lv_style_set_bg_opa(&style_scr, LV_OPA_COVER);    
    
        static lv_style_t style_label;
        lv_style_init(&style_label);
        lv_style_set_text_color(&style_label, lv_color_white());

        lv_obj_t *scr = lv_scr_act();
    
        lv_obj_clean(scr);
        lv_obj_set_size(scr, lv_disp_get_hor_res(display), lv_disp_get_ver_res(display));
        lv_obj_add_style(scr, &style_scr, LV_STATE_DEFAULT);

        lv_obj_set_layout(scr, LV_LAYOUT_FLEX);
        lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN);
        lv_obj_set_style_flex_main_place(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_STATE_DEFAULT);

        lv_obj_t *label1 = lv_label_create(scr);
        lv_label_set_text(label1, "Label");
        lv_obj_center(label1);
        lv_obj_set_width(label1, lv_pct(100));
        lv_obj_add_style(label1, &style_label, LV_STATE_DEFAULT);

        lv_obj_t *label2 = lv_label_create(scr);
        lv_label_set_text(label2, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
        lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL);
        lv_obj_center(label2);
        lv_obj_set_width(label2, lv_pct(100));
        lv_obj_add_style(label2, &style_label, LV_STATE_DEFAULT);
    
        lvgl_port_unlock();
    }
}

Other Steps to Reproduce

No response

I have checked existing issues, README.md and ESP32 Forum

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions