lvgl / lv_binding_micropython

LVGL binding for MicroPython
MIT License
237 stars 156 forks source link

st7789 driver cannot switch invert #339

Open redcoco opened 1 month ago

redcoco commented 1 month ago

https://github.com/lvgl/lv_binding_micropython/blob/master/driver/esp32/ili9XXX.py ` class st7789(ili9XXX):

# The st7789 display controller has an internal framebuffer arranged in a 320x240 pixel
# configuration. Physical displays with pixel sizes less than 320x240 must supply a start_x and
# start_y argument to indicate where the physical display begins relative to the start of the
# display controllers internal framebuffer.

def __init__(self,
    miso=-1, mosi=19, clk=18, cs=5, dc=16, rst=23, power=-1, backlight=4, backlight_on=1, power_on=0,
    spihost=esp.HSPI_HOST, spimode=0, mhz=40, factor=4, hybrid=True, width=320, height=240, start_x=0, start_y=0,
    colormode=COLOR_MODE_BGR, rot=PORTRAIT, invert=True, double_buffer=True, half_duplex=True,
    asynchronous=False, initialize=True, color_format=lv.COLOR_FORMAT.RGB565, swap_rgb565_bytes=True):

    # Make sure Micropython was built such that color won't require processing before DMA

    if lv.color_format_get_bpp(color_format) != 16:
        raise RuntimeError('st7789 micropython driver requires 16 bit color format')

    self.display_name = 'ST7789'

    self.init_cmds = [
        {'cmd':  0x11, 'data': bytes([0x0]), 'delay': 120},
        {'cmd':  0x13, 'data': bytes([0x0])},

        {'cmd':  0x36, 'data': bytes([
            self.madctl(colormode, rot, (0x0, MADCTL_MX | MADCTL_MV, MADCTL_MY | MADCTL_MX, MADCTL_MY | MADCTL_MV))])},  # MADCTL

        {'cmd':  0xb6, 'data': bytes([0xa, 0x82])},
        {'cmd':  0x3a, 'data': bytes([0x55]),'delay': 10},
        {'cmd':  0xb2, 'data': bytes([0xc, 0xc, 0x0, 0x33, 0x33])},
        {'cmd':  0xb7, 'data': bytes([0x35])},
        {'cmd':  0xbb, 'data': bytes([0x28])},
        {'cmd':  0xc0, 'data': bytes([0xc])},
        {'cmd':  0xc2, 'data': bytes([0x1, 0xff])},
        {'cmd':  0xc3, 'data': bytes([0x10])},
        {'cmd':  0xc4, 'data': bytes([0x20])},
        {'cmd':  0xc6, 'data': bytes([0xf])},
        {'cmd':  0xd0, 'data': bytes([0xa4, 0xa1])},
        {'cmd':  0xe0, 'data': bytes([0xd0, 0x0, 0x2, 0x7, 0xa, 0x28, 0x32, 0x44, 0x42, 0x6, 0xe, 0x12, 0x14, 0x17])},
        {'cmd':  0xe1, 'data': bytes([0xd0, 0x0, 0x2, 0x7, 0xa, 0x28, 0x31, 0x54, 0x47, 0xe, 0x1c, 0x17, 0x1b, 0x1e])},
        {'cmd':  0x21, 'data': bytes([0x0])},
        {'cmd':  0x2a, 'data': bytes([0x0, 0x0, 0x0, 0xe5])},
        {'cmd':  0x2b, 'data': bytes([0x0, 0x0, 0x1, 0x3f]), 'delay': 120},
        {'cmd':  0x29, 'data': bytes([0x0]), 'delay': 120}
    ]

    super().__init__(miso=miso, mosi=mosi, clk=clk, cs=cs, dc=dc, rst=rst, power=power, backlight=backlight,
        backlight_on=backlight_on, power_on=power_on, spihost=spihost, spimode=spimode, mhz=mhz, factor=factor, hybrid=hybrid,
        width=width, height=height, start_x=start_x, start_y=start_y, invert=invert, double_buffer=double_buffer,
        half_duplex=half_duplex, display_type=DISPLAY_TYPE_ST7789, asynchronous=asynchronous,
        initialize=initialize, color_format=color_format, swap_rgb565_bytes=swap_rgb565_bytes)

in line 724 st7789 init param invert=True is default set; but other default set False and in line 127 if invert: self.init_cmds.append({'cmd': 0x21}) only support invert=True ,so st7789 can not switch invert param change . so I suggest change the param invert=False as default, and line 127 add false code and line 754{'cmd': 0x21, 'data': bytes([0x0])},` not need .