Help with ST7796S TFT color configuration

Today I received my WT32-SC01 esp32 based board and I had some problems configuring the TFT driver ( ST7796S ).

image

Initially I compiled LVGL with LV_COLOR_DEPTH=16 and then I added LV_COLOR_16_SWAP=1, but nothing changes.

When I write directly to the LCD (no LVGL involved), I still see different colors than I spected.
I already tried to change the RBG/BGR color format on the MADCTL register, the inversion, the SPI endian… but I never got the correct colors.

The RGB565 colors I think LVGL needs are these, at least this is what I see on internet:
RED = 0xF800
GREEN = 0x07E0
BLUE = 0x001F
But with my LCD configuration I got:
image
Black and white are ok, so there is no LCD inversion needed, RED is ok, but GREEN and BLUE are swapped…and I dont know why…

Here is the code Im using
test_st7796s.py.txt (3.8 KB)
The driver datasheed:

I tried to swap the LVGL buffer at disp_drv_flush_cb via software before send it to the LCD with this function and now my LCD works fine, slow, but with correct colors.

def software_swap( buf ):
    for i in range(0, len(buf), 2):
        buf0 = buf[i+0]
        buf1 = buf[i+1]
        buf[i+0] = buf1
        buf[i+1] = buf0

image

So looks that the problem is the LV_COLOR_SWAP_16=1?

My build command is:

make -C ports/esp32 LV_CFLAGS="-DLV_COLOR_DEPTH=16 -DLV_COLOR_16_SWAP=1" BOARD=GENERIC_SPIRAM

In previous LVGL versions I modified lv_conh.h cause there was a “#deine LV_COLOR_16_SWAP”, but in current version it isnt and Im always confused if it is the correct define.

Also I noticed that is not exposed to micropython, so probably is not the correct build command:

>>> lv.COLOR_DEPTH
16
>>> lv.COLOR_16_SWAP
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'COLOR_16_SWAP'

Hi @jgpeiro !

In LVGL on latest lv_micropython, LV_COLOR_16_SWAP was removed.
Instead, this can be configured now on runtime. When registering the display driver you also pass color_format.

The exiting drivers were also fixed to receive color_format.
Try to pass lv.COLOR_FORMAT.NATIVE_REVERSE instead of the default value.

disp_drv.color_format = lv.COLOR_FORMAT.NATIVE_REVERSE

Ok, now is working fine.

Thank you!