Skip to content

Enhanced compatibility #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Usage Example

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

display = ST7789(display_bus, width=240, height=240, rowstart=80)
display = ST7789(display_bus, width=240, height=240, rowstart=80, bgr=True, invert=True)

# Make the display context
splash = displayio.Group()
Expand Down
26 changes: 18 additions & 8 deletions adafruit_st7789.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
from busdisplay import BusDisplay

try:
import typing
from typing import Any

from fourwire import FourWire
except ImportError:
pass

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7789.git"

Expand All @@ -57,16 +56,27 @@
b"\x11\x80\xff" # _SLPOUT and Delay 500ms
b"\x3a\x81\x55\x0a" # _COLMOD and Delay 10ms
b"\x36\x01\x08" # _MADCTL
b"\x21\x80\x0a" # _INVON Hack and Delay 10ms
b"\x13\x80\x0a" # _NORON and Delay 10ms
b"\x36\x01\xc0" # _MADCTL
b"\x29\x80\xff" # _DISPON and Delay 500ms
)


# pylint: disable=too-few-public-methods
class ST7789(BusDisplay):
"""ST7789 driver"""

def __init__(self, bus: FourWire, **kwargs) -> None:
super().__init__(bus, _INIT_SEQUENCE, **kwargs)
"""
ST7789 driver

:param FourWire bus: bus that the display is connected to
:param bool bgr: (Optional) An extra init sequence to append (default=True)
:param bool invert: (Optional) Invert the colors (default=True)
"""

def __init__(self, bus: FourWire, *, bgr: bool = True, invert: bool = True, **kwargs: Any):
init_sequence = _INIT_SEQUENCE
if bgr:
init_sequence += b"\x36\x01\xc0" # _MADCTL Default rotation plus BGR encoding
else:
init_sequence += b"\x36\x01\xc8" # _MADCTL Default rotation plus RGB encoding
if invert:
init_sequence += b"\x21\x00" # _INVON
super().__init__(bus, init_sequence, **kwargs)
2 changes: 1 addition & 1 deletion examples/st7789_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

display = ST7789(display_bus, width=240, height=240, rowstart=80)
display = ST7789(display_bus, width=240, height=240, rowstart=80, bgr=True, invert=True)

# Make the display context
splash = displayio.Group()
Expand Down