Skip to content

Commit 3bf6460

Browse files
committed
Add 2 arguments:
1. bgr: bool, support for choosing bgr or rgb pixel order. 2. invert: bool, support for sending color inverse command.
1 parent ea32f33 commit 3bf6460

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Usage Example
5757
5858
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
5959
60-
display = ST7789(display_bus, width=240, height=240, rowstart=80)
60+
display = ST7789(display_bus, width=240, height=240, rowstart=80, bgr=True, invert=True)
6161
6262
# Make the display context
6363
splash = displayio.Group()

adafruit_st7789.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
b"\x11\x80\xff" # _SLPOUT and Delay 500ms
5858
b"\x3a\x81\x55\x0a" # _COLMOD and Delay 10ms
5959
b"\x36\x01\x08" # _MADCTL
60-
b"\x21\x80\x0a" # _INVON Hack and Delay 10ms
6160
b"\x13\x80\x0a" # _NORON and Delay 10ms
6261
b"\x36\x01\xc0" # _MADCTL
6362
b"\x29\x80\xff" # _DISPON and Delay 500ms
@@ -66,7 +65,20 @@
6665

6766
# pylint: disable=too-few-public-methods
6867
class ST7789(BusDisplay):
69-
"""ST7789 driver"""
70-
71-
def __init__(self, bus: FourWire, **kwargs) -> None:
72-
super().__init__(bus, _INIT_SEQUENCE, **kwargs)
68+
"""
69+
ST7789 driver
70+
71+
:param FourWire bus: bus that the display is connected to
72+
:param bool bgr: (Optional) An extra init sequence to append (default=False)
73+
:param bool invert: (Optional) Invert the colors (default=False)
74+
"""
75+
76+
def __init__(self, bus: FourWire, *, bgr: bool = False, invert: bool = False, **kwargs: Any):
77+
init_sequence = _INIT_SEQUENCE
78+
if bgr:
79+
init_sequence += b"\x36\x01\xc0" # _MADCTL Default rotation plus BGR encoding
80+
else:
81+
init_sequence += b"\x36\x01\xc8" # _MADCTL Default rotation plus RGB encoding
82+
if invert:
83+
init_sequence += b"\x21\x00" # _INVON
84+
super().__init__(bus, init_sequence, **kwargs)

examples/st7789_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
2525

26-
display = ST7789(display_bus, width=240, height=240, rowstart=80)
26+
display = ST7789(display_bus, width=240, height=240, rowstart=80, bgr=True, invert=True)
2727

2828
# Make the display context
2929
splash = displayio.Group()

0 commit comments

Comments
 (0)