Skip to content

Commit 43a67c2

Browse files
authored
Merge pull request #40 from alexleft/main
Enhanced compatibility
2 parents ea32f33 + 2b3fb83 commit 43a67c2

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@
4343
from busdisplay import BusDisplay
4444

4545
try:
46-
import typing
46+
from typing import Any
4747

4848
from fourwire import FourWire
4949
except ImportError:
5050
pass
51-
5251
__version__ = "0.0.0+auto.0"
5352
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7789.git"
5453

@@ -57,16 +56,27 @@
5756
b"\x11\x80\xff" # _SLPOUT and Delay 500ms
5857
b"\x3a\x81\x55\x0a" # _COLMOD and Delay 10ms
5958
b"\x36\x01\x08" # _MADCTL
60-
b"\x21\x80\x0a" # _INVON Hack and Delay 10ms
6159
b"\x13\x80\x0a" # _NORON and Delay 10ms
62-
b"\x36\x01\xc0" # _MADCTL
6360
b"\x29\x80\xff" # _DISPON and Delay 500ms
6461
)
6562

6663

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