From 443d70403a5f6c3338ce928f508573108d26bedc Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 11 Oct 2019 10:48:37 -0700 Subject: [PATCH] Added all 3 ST7735R displays, added BGR param for miniTFT --- adafruit_rgb_display/st7735.py | 20 ++++++++++++++++---- examples/rgb_display_pillow_demo.py | 4 ++++ examples/rgb_display_pillow_image.py | 4 ++++ examples/rgb_display_pillow_stats.py | 4 ++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/adafruit_rgb_display/st7735.py b/adafruit_rgb_display/st7735.py index bd55ce5..7864a9f 100644 --- a/adafruit_rgb_display/st7735.py +++ b/adafruit_rgb_display/st7735.py @@ -133,8 +133,12 @@ class ST7735(DisplaySPI): _ENCODE_POS = ">HH" #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=128, height=128, rotation=0): - super().__init__(spi, dc, cs, rst, width, height, rotation) + def __init__(self, spi, dc, cs, rst=None, width=128, height=128, + baudrate=16000000, polarity=0, phase=0, *, + x_offset=0, y_offset=0, rotation=0): + super().__init__(spi, dc, cs, rst, width, height, + baudrate=baudrate, polarity=polarity, phase=phase, + x_offset=x_offset, y_offset=y_offset, rotation=rotation) class ST7735R(ST7735): @@ -167,13 +171,19 @@ class ST7735R(ST7735): ) #pylint: disable-msg=useless-super-delegation, too-many-arguments - def __init__(self, spi, dc, cs, rst=None, width=128, height=160, rotation=0): - super().__init__(spi, dc, cs, rst, width, height, rotation) + def __init__(self, spi, dc, cs, rst=None, width=128, height=160, + baudrate=16000000, polarity=0, phase=0, *, + x_offset=0, y_offset=0, rotation=0, bgr=False): + self._bgr = bgr + super().__init__(spi, dc, cs, rst, width, height, + baudrate=baudrate, polarity=polarity, phase=phase, + x_offset=x_offset, y_offset=y_offset, rotation=rotation) def init(self): super().init() cols = struct.pack('>HH', 0, self.width - 1) rows = struct.pack('>HH', 0, self.height - 1) + for command, data in ( (_CASET, cols), (_RASET, rows), @@ -181,3 +191,5 @@ def init(self): (_DISPON, None), ): self.write(command, data) + if self._bgr: + self.write(_MADCTL, b'\xc0') diff --git a/examples/rgb_display_pillow_demo.py b/examples/rgb_display_pillow_demo.py index dad4e84..7f1f9b4 100644 --- a/examples/rgb_display_pillow_demo.py +++ b/examples/rgb_display_pillow_demo.py @@ -4,6 +4,7 @@ import adafruit_rgb_display.ili9341 as ili9341 import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import +import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import # First define some constants to allow easy resizing of shapes. BORDER = 20 @@ -24,6 +25,9 @@ #disp = st7789.ST7789(spi, rotation=90 # 2.0" ST7789 #disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=90 # 1.3", 1.54" ST7789 #disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 +#disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R +#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R +#disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R disp = ili9341.ILI9341(spi, rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) diff --git a/examples/rgb_display_pillow_image.py b/examples/rgb_display_pillow_image.py index 04fbcd5..a5267e0 100644 --- a/examples/rgb_display_pillow_image.py +++ b/examples/rgb_display_pillow_image.py @@ -4,6 +4,7 @@ import adafruit_rgb_display.ili9341 as ili9341 import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import +import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import # Configuration for CS and DC pins (these are PiTFT defaults): cs_pin = digitalio.DigitalInOut(board.CE0) @@ -20,6 +21,9 @@ #disp = st7789.ST7789(spi, rotation=90 # 2.0" ST7789 #disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=90 # 1.3", 1.54" ST7789 #disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 +#disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R +#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R +#disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R disp = ili9341.ILI9341(spi, rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) diff --git a/examples/rgb_display_pillow_stats.py b/examples/rgb_display_pillow_stats.py index fc9fb4c..ac9047b 100644 --- a/examples/rgb_display_pillow_stats.py +++ b/examples/rgb_display_pillow_stats.py @@ -6,6 +6,7 @@ import adafruit_rgb_display.ili9341 as ili9341 import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import +import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import # Configuration for CS and DC pins (these are PiTFT defaults): cs_pin = digitalio.DigitalInOut(board.CE0) @@ -22,6 +23,9 @@ #disp = st7789.ST7789(spi, rotation=90 # 2.0" ST7789 #disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=90 # 1.3", 1.54" ST7789 #disp = hx8357.HX8357(spi, rotation=180, # 3.5" HX8357 +#disp = st7735.ST7735R(spi, rotation=90, # 1.8" ST7735R +#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3, # 1.44" ST7735R +#disp = st7735.ST7735R(spi, rotation=90, bgr=True, # 0.96" MiniTFT ST7735R disp = ili9341.ILI9341(spi, rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)