From 907a41f7ff9e7378029fccf41bc66d7736d90807 Mon Sep 17 00:00:00 2001 From: Philipp Keller <11523+philippkeller@users.noreply.github.com> Date: Sat, 4 Jan 2020 18:43:50 +0100 Subject: [PATCH 1/5] starting to implement for ST7735S --- adafruit_rgb_display/rgb.py | 1 + adafruit_rgb_display/st7735.py | 83 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/adafruit_rgb_display/rgb.py b/adafruit_rgb_display/rgb.py index d64dfa9..be2debf 100644 --- a/adafruit_rgb_display/rgb.py +++ b/adafruit_rgb_display/rgb.py @@ -138,6 +138,7 @@ def __init__(self, width, height, rotation): def init(self): """Run the initialization commands.""" + print('init commands') for command, data in self._INIT: self.write(command, data) diff --git a/adafruit_rgb_display/st7735.py b/adafruit_rgb_display/st7735.py index 7864a9f..30d99b3 100644 --- a/adafruit_rgb_display/st7735.py +++ b/adafruit_rgb_display/st7735.py @@ -28,6 +28,8 @@ * Author(s): Radomir Dopieralski, Michael McWethy """ +import time + try: import struct except ImportError: @@ -84,6 +86,9 @@ _GMCTRP1 = const(0xE0) _GMCTRN1 = const(0xE1) +_TSTCMD1 = const(0xF0) +_DISRPSM1 = const(0xF6) + class ST7735(DisplaySPI): """ @@ -193,3 +198,81 @@ def init(self): self.write(command, data) if self._bgr: self.write(_MADCTL, b'\xc0') + +class ST7735S(ST7735): + """A simple driver for the ST7735S-based displays.""" + _INIT = ( + # Frame Rate + (_FRMCTR1, b'\x01\x2c\x2d'), # B1 + (_FRMCTR2, b'\x01\x2c\x2d'), # B2 + (_FRMCTR3, b'\x01\x2c\x2d\x01\x2c\x2d'), # B3 + + # Column inversion + (_INVCTR, b'\x07'), # B4 + + # Power Sequence + (_PWCTR1, b'\xa2\x02\x84'), # C0 + (_PWCTR2, b'\xc5'), # C1 + (_PWCTR3, b'\x0a\x00'), # C2 + (_PWCTR4, b'\x8a\x2a'), # C3 + (_PWCTR5, b'\x8a\xee'), # C4 + + # VCOM + (_VMCTR1, b'\x0e'), # C5 + + # Gamma + (_GMCTRP1, b'\x0f\x1a\x0f\x18\x2f\x28\x20\x22' # E0 + b'\x1f\x1b\x23\x37\x00\x07\x02\x10'), + + (_GMCTRN1, b'\x0f\x1b\x0f\x17\x33\x2c\x29\x2e' # E1 + b'\x30\x30\x39\x3f\x00\x07\x03\x10'), + # Enable test command + (_TSTCMD1, b'\x01'), # F0 + # Disable ram power save mode + (_DISRPSM1, b'\x00'), # F6 + # 65k mode + (_COLMOD, b'\x05'), # 3A + # set scan direction: up to down, right to left + (_MADCTL, b'\x60'), # 36 + ) + + #pylint: disable-msg=useless-super-delegation, too-many-arguments + def __init__(self, spi, dc, cs, bl, rst=None, width=128, height=160, + baudrate=16000000, polarity=0, phase=0, *, + x_offset=2, y_offset=1, rotation=0, bgr=False): + self._bl = bl + # Turn on backlight + print('turn on backlight') + self._bl.switch_to_output(value=1) + 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 reset(self): + # print('reset') + # self.rst.value = 1 + # time.sleep(0.100) + # self.rst.value = 0 + # time.sleep(0.100) + # self.rst.value = 1 + # time.sleep(0.100) + + def init(self): + + super().init() + print('last commands of 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), + # (_NORON, None), + # (_DISPON, None), + # ): + # self.write(command, data) + time.sleep(0.200) + self.write(_SLPOUT) + time.sleep(0.120) + self.write(_DISPON) From 5ecb70e3056008435d04bb8ddf81d8fa6eaaa27c Mon Sep 17 00:00:00 2001 From: Philipp Keller <11523+philippkeller@users.noreply.github.com> Date: Sun, 5 Jan 2020 13:31:04 +0100 Subject: [PATCH 2/5] got it running with my waveshare 1.8 inch lcd, remove unnecessary code, remove debug statements --- adafruit_rgb_display/rgb.py | 1 - adafruit_rgb_display/st7735.py | 69 +++++++++------------------------- 2 files changed, 18 insertions(+), 52 deletions(-) diff --git a/adafruit_rgb_display/rgb.py b/adafruit_rgb_display/rgb.py index be2debf..d64dfa9 100644 --- a/adafruit_rgb_display/rgb.py +++ b/adafruit_rgb_display/rgb.py @@ -138,7 +138,6 @@ def __init__(self, width, height, rotation): def init(self): """Run the initialization commands.""" - print('init commands') for command, data in self._INIT: self.write(command, data) diff --git a/adafruit_rgb_display/st7735.py b/adafruit_rgb_display/st7735.py index 30d99b3..fe98851 100644 --- a/adafruit_rgb_display/st7735.py +++ b/adafruit_rgb_display/st7735.py @@ -28,8 +28,6 @@ * Author(s): Radomir Dopieralski, Michael McWethy """ -import time - try: import struct except ImportError: @@ -86,10 +84,6 @@ _GMCTRP1 = const(0xE0) _GMCTRN1 = const(0xE1) -_TSTCMD1 = const(0xF0) -_DISRPSM1 = const(0xF6) - - class ST7735(DisplaySPI): """ A simple driver for the ST7735-based displays. @@ -203,37 +197,39 @@ class ST7735S(ST7735): """A simple driver for the ST7735S-based displays.""" _INIT = ( # Frame Rate - (_FRMCTR1, b'\x01\x2c\x2d'), # B1 - (_FRMCTR2, b'\x01\x2c\x2d'), # B2 - (_FRMCTR3, b'\x01\x2c\x2d\x01\x2c\x2d'), # B3 + (_FRMCTR1, b'\x01\x2c\x2d'), + (_FRMCTR2, b'\x01\x2c\x2d'), + (_FRMCTR3, b'\x01\x2c\x2d\x01\x2c\x2d'), # Column inversion - (_INVCTR, b'\x07'), # B4 + (_INVCTR, b'\x07'), # Power Sequence - (_PWCTR1, b'\xa2\x02\x84'), # C0 - (_PWCTR2, b'\xc5'), # C1 - (_PWCTR3, b'\x0a\x00'), # C2 - (_PWCTR4, b'\x8a\x2a'), # C3 - (_PWCTR5, b'\x8a\xee'), # C4 + (_PWCTR1, b'\xa2\x02\x84'), + (_PWCTR2, b'\xc5'), + (_PWCTR3, b'\x0a\x00'), + (_PWCTR4, b'\x8a\x2a'), + (_PWCTR5, b'\x8a\xee'), # VCOM - (_VMCTR1, b'\x0e'), # C5 + (_VMCTR1, b'\x0e'), # Gamma - (_GMCTRP1, b'\x0f\x1a\x0f\x18\x2f\x28\x20\x22' # E0 + (_GMCTRP1, b'\x0f\x1a\x0f\x18\x2f\x28\x20\x22' b'\x1f\x1b\x23\x37\x00\x07\x02\x10'), - (_GMCTRN1, b'\x0f\x1b\x0f\x17\x33\x2c\x29\x2e' # E1 + (_GMCTRN1, b'\x0f\x1b\x0f\x17\x33\x2c\x29\x2e' b'\x30\x30\x39\x3f\x00\x07\x03\x10'), # Enable test command - (_TSTCMD1, b'\x01'), # F0 + # (_TSTCMD1, b'\x01'), # Disable ram power save mode - (_DISRPSM1, b'\x00'), # F6 + # (_DISRPSM1, b'\x00'), # 65k mode - (_COLMOD, b'\x05'), # 3A + (_COLMOD, b'\x05'), # set scan direction: up to down, right to left - (_MADCTL, b'\x60'), # 36 + (_MADCTL, b'\x60'), + (_SLPOUT, None), + (_DISPON, None), ) #pylint: disable-msg=useless-super-delegation, too-many-arguments @@ -242,37 +238,8 @@ def __init__(self, spi, dc, cs, bl, rst=None, width=128, height=160, x_offset=2, y_offset=1, rotation=0, bgr=False): self._bl = bl # Turn on backlight - print('turn on backlight') self._bl.switch_to_output(value=1) 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 reset(self): - # print('reset') - # self.rst.value = 1 - # time.sleep(0.100) - # self.rst.value = 0 - # time.sleep(0.100) - # self.rst.value = 1 - # time.sleep(0.100) - - def init(self): - - super().init() - print('last commands of 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), - # (_NORON, None), - # (_DISPON, None), - # ): - # self.write(command, data) - time.sleep(0.200) - self.write(_SLPOUT) - time.sleep(0.120) - self.write(_DISPON) From 15815d4b518e9508de5c245de89c7af78720a6f4 Mon Sep 17 00:00:00 2001 From: Philipp Keller <11523+philippkeller@users.noreply.github.com> Date: Sun, 5 Jan 2020 13:34:08 +0100 Subject: [PATCH 3/5] mention in Readme that ST7735R and ST7735S are supported --- README.rst | 2 +- adafruit_rgb_display/st7735.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b4327ea..bb3fa41 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,7 @@ Port of display drivers from https://github.com/adafruit/micropython-adafruit-rg .. note:: This driver currently won't work on micropython.org firmware, instead you want the micropython-adafruit-rgb-display driver linked above! -This CircuitPython driver currently supports displays that use the following display-driver chips: HX8353, HX8357, ILI9341, S6D02A1, ST7789, SSD1331, SSD1351, and ST7735. +This CircuitPython driver currently supports displays that use the following display-driver chips: HX8353, HX8357, ILI9341, S6D02A1, ST7789, SSD1331, SSD1351, and ST7735 (including variants ST7735R and ST7735S). Dependencies ============= diff --git a/adafruit_rgb_display/st7735.py b/adafruit_rgb_display/st7735.py index fe98851..012ef43 100644 --- a/adafruit_rgb_display/st7735.py +++ b/adafruit_rgb_display/st7735.py @@ -84,6 +84,7 @@ _GMCTRP1 = const(0xE0) _GMCTRN1 = const(0xE1) + class ST7735(DisplaySPI): """ A simple driver for the ST7735-based displays. From 267164ac51a1bcea575250a92ed586c458f64694 Mon Sep 17 00:00:00 2001 From: Philipp Keller <11523+philippkeller@users.noreply.github.com> Date: Sun, 5 Jan 2020 13:55:59 +0100 Subject: [PATCH 4/5] remove unnecessary variable, fix linting error --- adafruit_rgb_display/st7735.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_rgb_display/st7735.py b/adafruit_rgb_display/st7735.py index 012ef43..5f27de7 100644 --- a/adafruit_rgb_display/st7735.py +++ b/adafruit_rgb_display/st7735.py @@ -236,11 +236,10 @@ class ST7735S(ST7735): #pylint: disable-msg=useless-super-delegation, too-many-arguments def __init__(self, spi, dc, cs, bl, rst=None, width=128, height=160, baudrate=16000000, polarity=0, phase=0, *, - x_offset=2, y_offset=1, rotation=0, bgr=False): + x_offset=2, y_offset=1, rotation=0): self._bl = bl # Turn on backlight self._bl.switch_to_output(value=1) super().__init__(spi, dc, cs, rst, width, height, baudrate=baudrate, polarity=polarity, phase=phase, x_offset=x_offset, y_offset=y_offset, rotation=rotation) - From 7753772394fc198536f12c8757419a60c10cd143 Mon Sep 17 00:00:00 2001 From: Philipp Keller <11523+philippkeller@users.noreply.github.com> Date: Sun, 5 Jan 2020 14:03:01 +0100 Subject: [PATCH 5/5] remove commented out, unecessary code --- adafruit_rgb_display/st7735.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/adafruit_rgb_display/st7735.py b/adafruit_rgb_display/st7735.py index 5f27de7..aae3a41 100644 --- a/adafruit_rgb_display/st7735.py +++ b/adafruit_rgb_display/st7735.py @@ -221,10 +221,6 @@ class ST7735S(ST7735): (_GMCTRN1, b'\x0f\x1b\x0f\x17\x33\x2c\x29\x2e' b'\x30\x30\x39\x3f\x00\x07\x03\x10'), - # Enable test command - # (_TSTCMD1, b'\x01'), - # Disable ram power save mode - # (_DISRPSM1, b'\x00'), # 65k mode (_COLMOD, b'\x05'), # set scan direction: up to down, right to left