Strange green-isch screen with LVGL on WT32-SC01-Plus

I have a WT32-SC01-Plus module and I get a very strange, green-isch, deformed view when using the LVGL library.

When I try a simple LovyanGFX sketch like this, without LVGL, it works fine.

But when I use LVGL I get something like this (it should be a blue-dotted slider bar on a white background):

What can be the issue?
I use Arduino IDE 2.2.1
I use these libraries

  • LovyanGFX by lovyan03: v1.1.9
  • lvgl by kisvegabor: v8.3.10
    lv_conf.h:
    lv_conf.h (25.1 KB)

ino file:

/**
Tools
  Board: ESP32S3 Dev Module
  USB CDC ob boot: enabled!!

Libraries:
- lvgl by kisvegabor: v8.3.10   !! Copy the ...\Arduino\libraries\lvgl\lv_conf_template.h file to ...\Arduino\libraries\lv_conf.h !! Thus, one folder up!
- LovyanGFX by lovyan03: v1.1.9 (Display & touch driver)

*/

/*
    Simple Touch Drawing sample for WT32-SC01-Plus_ESP32-S3
    Requirements:
    - Development board : WT32-SC01-Plus_ESP32-S3
    - Arduino Library - Display/Touch : LovyanGFX
    - Board selected in Arduino : ESP32S3 Dev Module

*/

#define LGFX_USE_V1       // set to use new version of library
#include <LovyanGFX.hpp>  // main library
#include <lvgl.h>

class LGFX : public lgfx::LGFX_Device {

  lgfx::Panel_ST7796 _panel_instance;  // ST7796UI
  lgfx::Bus_Parallel8 _bus_instance;   // MCU8080 8B
  lgfx::Light_PWM _light_instance;
  lgfx::Touch_FT5x06 _touch_instance;

public:
  LGFX(void) {
    {
      auto cfg = _bus_instance.config();
      cfg.freq_write = 20000000;
      cfg.pin_wr = 47;
      cfg.pin_rd = -1;
      cfg.pin_rs = 0;

      // LCD data interface, 8bit MCU (8080)
      cfg.pin_d0 = 9;
      cfg.pin_d1 = 46;
      cfg.pin_d2 = 3;
      cfg.pin_d3 = 8;
      cfg.pin_d4 = 18;
      cfg.pin_d5 = 17;
      cfg.pin_d6 = 16;
      cfg.pin_d7 = 15;

      _bus_instance.config(cfg);
      _panel_instance.setBus(&_bus_instance);
    }

    {
      auto cfg = _panel_instance.config();

      cfg.pin_cs = -1;
      cfg.pin_rst = 4;
      cfg.pin_busy = -1;

      cfg.memory_width = 320;   // Maximum width supported by driver IC
      cfg.memory_height = 480;  // Maximum height supported by driver IC
      cfg.panel_width = 320;
      cfg.panel_height = 480;
      cfg.offset_x = 0;
      cfg.offset_y = 0;
      cfg.offset_rotation = 0;
      cfg.dummy_read_pixel = 8;
      cfg.dummy_read_bits = 1;
      cfg.readable = false;  // changed! true
      cfg.invert = true;
      cfg.rgb_order = false;
      cfg.dlen_16bit = false;
      cfg.bus_shared = true;

      _panel_instance.config(cfg);
    }

    {
      auto cfg = _light_instance.config();

      cfg.pin_bl = 45;
      cfg.invert = false;
      cfg.freq = 44100;
      cfg.pwm_channel = 7;

      _light_instance.config(cfg);
      _panel_instance.setLight(&_light_instance);
    }

    {
      auto cfg = _touch_instance.config();

      cfg.x_min = 0;
      cfg.x_max = 319;
      cfg.y_min = 0;
      cfg.y_max = 479;
      cfg.pin_int = 7;
      cfg.bus_shared = false;  // changed! false
      cfg.offset_rotation = 0;

      cfg.i2c_port = 0;  // changed! 1
      cfg.i2c_addr = 0x38;
      cfg.pin_sda = 6;
      cfg.pin_scl = 5;
      cfg.freq = 400000;

      _touch_instance.config(cfg);
      _panel_instance.setTouch(&_touch_instance);
    }
    setPanel(&_panel_instance);
  }
};

LGFX tft;

#define screenWidth 480
#define screenHeight 320

void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
  uint32_t w = (area->x2 - area->x1 + 1);
  uint32_t h = (area->y2 - area->y1 + 1);
  tft.startWrite();
  tft.setAddrWindow(area->x1, area->y1, w, h);
  // tft.pushColors(&color_p->full, w * h, true);
  tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
  tft.endWrite();
  lv_disp_flush_ready(disp);
}

void my_touch_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) {
  uint16_t touchX, touchY;
  bool touched = tft.getTouch(&touchX, &touchY);
  if (!touched) {
    data->state = LV_INDEV_STATE_REL;
  } else {
    data->state = LV_INDEV_STATE_PR;
    data->point.x = touchX;
    data->point.y = touchY;
  }
  Serial.println("in my_touch_read");
}


static lv_style_t label_style;
static lv_obj_t *headerLabel;
static lv_obj_t *label;

static void slider_event_cb(lv_event_t *e) {
  Serial.println("in slider_event_cb");
  lv_obj_t *slider = lv_event_get_target(e);

  /*Refresh the text*/
  lv_label_set_text_fmt(label, "%" LV_PRId32, lv_slider_get_value(slider));
  lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/
}

/**
 * Create a slider and write its value on a label.
 */
void lv_example_get_started_3(void) {
  /*Create a slider in the center of the display*/
  lv_obj_t *slider = lv_slider_create(lv_scr_act());
  lv_obj_set_width(slider, 200);                                              /*Set the width*/
  lv_obj_center(slider);                                                      /*Align to the center of the parent (screen)*/
  lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); /*Assign an event function*/

  /*Create a label above the slider*/
  label = lv_label_create(lv_scr_act());
  lv_label_set_text(label, "0");
  lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/
}


void setup() {
  Serial.begin(115200);

  tft.begin();
  tft.setRotation(1);
  tft.setBrightness(64);

  setupLvgl();
  lv_example_get_started_3();
  Serial.println("Setup done - sketch_nov21d.ino");
}

static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf1[screenWidth * screenHeight / 10];
static lv_disp_drv_t disp_drv;
static lv_indev_drv_t indev_drv;

void setupLvgl() {
  lv_init();

  // Display Buffer
  lv_disp_draw_buf_init(&draw_buf, buf1, NULL, screenWidth * screenHeight / 10); /*Initialize the display buffer.*/

  // Init Display
  lv_disp_drv_init(&disp_drv);       /*Basic initialization*/
  disp_drv.flush_cb = my_disp_flush; /*Set your driver function*/
  disp_drv.draw_buf = &draw_buf;     /*Assign the buffer to the display*/
  disp_drv.hor_res = screenWidth;    /*Set the horizontal resolution of the display*/
  disp_drv.ver_res = screenHeight;   /*Set the vertical resolution of the display*/
  lv_disp_drv_register(&disp_drv);   /*Finally register the driver*/


  // Init Touchscreen
  lv_indev_drv_init(&indev_drv);
  indev_drv.type = LV_INDEV_TYPE_POINTER;
  indev_drv.read_cb = my_touch_read;
  lv_indev_drv_register(&indev_drv);
}


void loop() {
  lv_timer_handler();
  delay(5);
}

I really appreciate any thoughts on this!

I progressed a little:

I changed the following settings in the lv_conf.h:

#define LV_COLOR_DEPTH 16 /* WAS 32 /
#define LV_COLOR_16_SWAP 1 /
WAS 0 /
#define LV_COLOR_SCREEN_TRANSP 0 /
WAS (__LVGL_V8_3 ? 1 : 0) */

Now I have a better readable screen, though still not OK (low resolution?!).
The slider is also still green instead of blue.

What can I do to get the correct colors and resolution?

Hmm, ok, I found the adjustments in a post. Since the result wasn’t ok yet, I tried to reduce the number of modifications at once, and bingo!

#define LV_COLOR_DEPTH 16 /* WAS 32 /
#define LV_COLOR_16_SWAP 0 / back to 0 /
#define LV_COLOR_SCREEN_TRANSP (__LVGL_V8_3 ? 1 : 0) /
back to original */

Now the screen looks great and react as expected too:

I hope someone else can benefit from this too.

Michiel