Display Shift Issue with ESP32-S3 and LVGL

1d438ef6
Posts: 6
Joined: Sun Jul 09, 2023 9:22 pm

Display Shift Issue with ESP32-S3 and LVGL

Postby 1d438ef6 » Wed Oct 25, 2023 2:30 pm

Hello
I try to control a GC9A01 display with a custom esp32-s3 board and LVGL, together with IDF version 5.1.1. For this purpose I use this display driver with the modification of replacing gpio_pad_select_gpio() with gpio_reset_pin().

My code compiles and doesn't throw errors, but the displayed image is shifted to the right and everything that is pushed out is displayed on the left side of the display, overlapping with some parts of the UI there. Below I added the Code I use for initializing the display and the screen, I only removed the objects I created on the screen in the image.

I've already tried to google this problem but didn't found a solution for this.
Has anyone else encountered this problem or has an idea how to solve this?
IMG_20231018_174515_2.jpg
IMG_20231018_174515_2.jpg (152.12 KiB) Viewed 2100 times
  1. SemaphoreHandle_t xGuiSemaphore;
  2.  
  3. void displayTask(void *pvParameter) {
  4.     (void) pvParameter;
  5.             xGuiSemaphore = xSemaphoreCreateMutex();
  6.  
  7.             lv_init();
  8.  
  9.             /* Initialize SPI or I2C bus used by the drivers */
  10.             lvgl_driver_init();
  11.  
  12.             lv_color_t* buf1 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
  13.             assert(buf1 != NULL);
  14.  
  15.             //lv_color_t* buf2 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
  16.             //assert(buf2 != NULL);
  17.             lv_color_t* buf2 = NULL;
  18.  
  19.             static lv_disp_draw_buf_t disp_buf;
  20.  
  21.             uint32_t size_in_px = DISP_BUF_SIZE;
  22.  
  23.             lv_disp_draw_buf_init(&disp_buf, buf1, buf2, size_in_px);
  24.  
  25.             lv_disp_drv_t disp_drv;
  26.             lv_disp_drv_init(&disp_drv);
  27.             disp_drv.flush_cb = disp_driver_flush;
  28.  
  29.         #if defined CONFIG_DISPLAY_ORIENTATION_PORTRAIT || defined CONFIG_DISPLAY_ORIENTATION_PORTRAIT_INVERTED
  30.             disp_drv.rotated = 1;
  31.         #endif
  32.  
  33.  
  34.             disp_drv.draw_buf = &disp_buf;
  35.             lv_disp_drv_register(&disp_drv);
  36.  
  37.  
  38.             /* Create and start a periodic timer interrupt to call lv_tick_inc */
  39.             const esp_timer_create_args_t periodic_timer_args = {
  40.                 .callback = &lv_tick_task,
  41.                 .name = "periodic_gui"
  42.             };
  43.             esp_timer_handle_t periodic_timer;
  44.             ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
  45.             ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000));
  46.  
  47.             ui_init();
  48.  
  49.             while (1) {
  50.                 /* Delay 1 tick (assumes FreeRTOS tick is 10ms */
  51.                 vTaskDelay(pdMS_TO_TICKS(10));
  52.  
  53.                 /* Try to take the semaphore, call lvgl related function on success */
  54.                 if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) {
  55.                     lv_task_handler();
  56.                     xSemaphoreGive(xGuiSemaphore);
  57.                }
  58.             }
  59.  
  60.             /* A task should NEVER return */
  61.             free(buf1);
  62.             free(buf2);
  63.             vTaskDelete(NULL);
  64.         }
  65.  
  66. void app_main() {
  67.     // Create task for display
  68.     xTaskCreate(displayTask, "display_task", 4096*4, NULL, 5, NULL);
  69. }
  1. void ui_Screen1_screen_init(void)
  2. {
  3. ui_Screen1 = lv_obj_create(NULL);
  4. lv_obj_clear_flag( ui_Screen1, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
  5. lv_obj_set_style_bg_color(ui_Screen1, lv_color_hex(0x480941), LV_PART_MAIN | LV_STATE_DEFAULT );
  6. lv_obj_set_style_bg_opa(ui_Screen1, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
  7. lv_obj_set_style_bg_img_src( ui_Screen1, &ui_img_watchface_png, LV_PART_MAIN | LV_STATE_DEFAULT );
  8. lv_obj_set_style_bg_img_recolor(ui_Screen1, lv_color_hex(0x3911E4), LV_PART_MAIN| LV_STATE_DEFAULT);
  9. lv_obj_set_style_bg_img_recolor_opa(ui_Screen1, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
  10. }

djixon
Posts: 113
Joined: Sun Oct 01, 2023 7:48 pm

Re: Display Shift Issue with ESP32-S3 and LVGL

Postby djixon » Wed Oct 25, 2023 5:50 pm

Is the CONFIG_DISPLAY_ORIENTATION_PORTRAIT defined?

1d438ef6
Posts: 6
Joined: Sun Jul 09, 2023 9:22 pm

Re: Display Shift Issue with ESP32-S3 and LVGL

Postby 1d438ef6 » Wed Oct 25, 2023 6:13 pm

No, but if i run

Code: Select all

disp_drv.rotated = 1;
the shift is not to the right, instead the shift is from top to bottom.

djixon
Posts: 113
Joined: Sun Oct 01, 2023 7:48 pm

Re: Display Shift Issue with ESP32-S3 and LVGL

Postby djixon » Thu Oct 26, 2023 9:44 am

Ok. Have you ever got it work properly? (I mean, with your custom modification removed)
There are lot of changes in 5.1.1 and new LVLG, I still haven't check, however you can try some modifications based on previous versions.
Anyway, the first unusual thing is not the shift. If you look better, the left part of your clock is overwritten by the right part. That suggests miss-size of data to be shown (your resource files) and resolution of the display. However, it can be produced an many different ways, by wrong buffer size allocation too or even wrong config for example. So for exact testing you should prepare:

1. Your images (ui_img_watchface_png ...) to be the exact the same resolution as the resolution of the display
2. your configuration should define CONFIG_LV_TFT_DISPLAY_CONTROLLER_GC9A01 for GC9A01 which will enable TFT_DISPLAY_BUFFER_SIZE_OVERFLOW_PROTECTION, check what your compiler says about that.
3. The DISPLAY_BUFFER_SIZE should be: resx * resy of your LCD (What is your DISPLAY_BUFFER_SIZE?)

Make those checks (and probably corrections) for testing. To me, it looks like you write larger images into smaller buffer so wrapping overlaps left part of image. Try smaller image, or for instant check try to draw your image at coordinate (-40, 0) or so to see what happens

1d438ef6
Posts: 6
Joined: Sun Jul 09, 2023 9:22 pm

Re: Display Shift Issue with ESP32-S3 and LVGL

Postby 1d438ef6 » Thu Oct 26, 2023 3:42 pm

So while looking a bit deeper into the Buffer size I solved it: the display size wasn't set correctly. I changed that and now it works just fine.
This is my first real project using LVGL and I didn't realize I had to set the display size separately. I thought this would be set in the display driver

djixon
Posts: 113
Joined: Sun Oct 01, 2023 7:48 pm

Re: Display Shift Issue with ESP32-S3 and LVGL

Postby djixon » Thu Oct 26, 2023 4:24 pm

Well, LVGL library is universal. So you have to make proper configuration to match your board type, display resolution etc.
cheers

Who is online

Users browsing this forum: rsimpsonbusa and 95 guests