Skip to content

Commit

Permalink
Issue pimoroni#22 - Provide support to invert MADCTL from BGR to RGB …
Browse files Browse the repository at this point in the history
…for Adafruit #358 display https://www.adafruit.com/product/358
  • Loading branch information
lynniemagoo committed Mar 17, 2022
1 parent 1a70d3a commit 99e4409
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/ST7735/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ST7735(object):
"""Representation of an ST7735 TFT LCD."""

def __init__(self, port, cs, dc, backlight=None, rst=None, width=ST7735_TFTWIDTH,
height=ST7735_TFTHEIGHT, rotation=90, offset_left=None, offset_top=None, invert=True, spi_speed_hz=4000000):
height=ST7735_TFTHEIGHT, rotation=90, offset_left=None, offset_top=None, invert=True, bgr=True, spi_speed_hz=4000000):
"""Create an instance of the display using SPI communication.
Must provide the GPIO pin number for the D/C pin and the SPI driver.
Expand Down Expand Up @@ -154,6 +154,7 @@ def __init__(self, port, cs, dc, backlight=None, rst=None, width=ST7735_TFTWIDTH
self._height = height
self._rotation = rotation
self._invert = invert
self._bgr = bgr

# Default left offset to center display
if offset_left is None:
Expand Down Expand Up @@ -280,12 +281,19 @@ def _init(self):
self.data(0x0E)

if self._invert:
print("ST7735_INVON")
self.command(ST7735_INVON) # Invert display
else:
print("ST7735_INVOFF")
self.command(ST7735_INVOFF) # Don't invert display

self.command(ST7735_MADCTL) # Memory access control (directions)
self.data(0xC8) # row addr/col addr, bottom to top refresh
if self._bgr:
print("MADCTL 0xC8")
self.data(0xC8) # row addr/col addr, bottom to top refresh; Set D3 RGB Bit to 1 for format BGR
else:
print("MADCTL 0xC0")
self.data(0xC0) # row addr/col addr, bottom to top refresh; Set D3 RGB Bit to 0 for format RGB

self.command(ST7735_COLMOD) # set color mode
self.data(0x05) # 16-bit color
Expand Down

0 comments on commit 99e4409

Please sign in to comment.