St7789 Generic driver bgr option (color display is wrong)

Hello,
I’m trying to run LVGL’s Example Create styles from scratch for buttons. the URI is the following line

https://docs.lvgl.io/master/examples.html#create-styles-from-scratch-for-buttons

import sys
sys.path.append('.')
from st77xx import *
from xpt2046 import *

spi=machine.SPI(
    1,
    baudrate=24_000_000,
    polarity=0,
    phase=0,
    sck=machine.Pin(10,machine.Pin.OUT),
    mosi=machine.Pin(11,machine.Pin.OUT),
    miso=machine.Pin(12,machine.Pin.IN)
)

import lvgl as lv
lv.init()
lcd=St7789(rot=1,res=(240,320),spi=spi,cs=9,dc=8,bl=13,rst=15,bgr=False)
lcd.set_backlight(50)
touch=Xpt2046(spi=spi,cs=16,rot=1,spiPrereadCb=lcd.rp2_wait_dma)
scr=lv.obj()
#
# Create styles from scratch for buttons.
#
style_btn =  lv.style_t()
style_btn_red = lv.style_t()
style_btn_pressed = lv.style_t()

# Create a simple button style
style_btn.init()
style_btn.set_radius(10)
style_btn.set_bg_opa(lv.OPA.COVER)
style_btn.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
style_btn.set_bg_grad_color(lv.palette_main(lv.PALETTE.GREY))
style_btn.set_bg_grad_dir(lv.GRAD_DIR.VER)

# Add a border
style_btn.set_border_color(lv.color_white())
style_btn.set_border_opa(lv.OPA._70)
style_btn.set_border_width(2)

# Set the text style
style_btn.set_text_color(lv.color_white())

# Create a red style. Change only some colors.
style_btn_red.init()
style_btn_red.set_bg_color(lv.palette_main(lv.PALETTE.RED))
style_btn_red.set_bg_grad_color(lv.palette_lighten(lv.PALETTE.RED, 2))

# Create a style for the pressed state.
style_btn_pressed.init()
style_btn_pressed.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
style_btn_pressed.set_bg_grad_color(lv.palette_darken(lv.PALETTE.RED, 3))

# Create a button and use the new styles
btn = lv.btn(lv.scr_act())                  # Add a button the current screen
# Remove the styles coming from the theme
# Note that size and position are also stored as style properties
# so lv_obj_remove_style_all will remove the set size and position too
btn.remove_style_all()                      # Remove the styles coming from the theme
btn.set_pos(10, 10)                         # Set its position
btn.set_size(120, 50)                       # Set its size
btn.add_style(style_btn, 0)
btn.add_style(style_btn_pressed, lv.STATE.PRESSED)

label = lv.label(btn)                       # Add a label to the button
label.set_text("Button")                    # Set the labels text
label.center()

# Create another button and use the red style too
btn2 = lv.btn(lv.scr_act())
btn2.remove_style_all()                     # Remove the styles coming from the theme
btn2.set_pos(10, 80)                        # Set its position
btn2.set_size(120, 50)                      # Set its size
btn2.add_style(style_btn, 0)
btn2.add_style(style_btn_red, 0)
btn2.add_style(style_btn_pressed, lv.STATE.PRESSED)
btn2.set_style_radius(lv.RADIUS_CIRCLE, 0)  # Add a local style

label = lv.label(btn2)                      # Add a label to the button
label.set_text("Button 2")                  # Set the labels text
label.center()

The screen display seems to be wrong when the bgr option = False in st7789.py generic driver.

lcd=St7789(rot=1,res=(240,320),spi=spi,cs=9,dc=8,bl=13,rst=15,bgr=False)

lcd=St7789(rot=1,res=(240,320),spi=spi,cs=9,dc=8,bl=13,rst=15,bgr=True)

The RP2040 ports are configured as follows.

    git clone https://github.com/lvgl/lv_micropython.git
    cd lv_micropython
    git submodule update --init --recursive lib/lv_bindings
    git revert b912b45 -m 1
    vim lib/lv_binding/lv_conf.h   change COLOR_DEPTH 32 to 16
    make -C ports/rp2 BOARD=PICO submodules
    make -j -C mpy-cross
    make -j -C ports/rp2 BOARD=PICO USER_C_MODULES=... /... /lib/lv_bindings/bindings.cmake

Thanks

Hi @ngc6589 !

Thank you for reporting this.

Fixed on:

CC: @eudoxos

amirgon-san

Thank you very much.
The gray and red buttons are now displayed.