Skip to content

Commit 907a41f

Browse files
committed
starting to implement for ST7735S
1 parent 4674551 commit 907a41f

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

adafruit_rgb_display/rgb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def __init__(self, width, height, rotation):
138138

139139
def init(self):
140140
"""Run the initialization commands."""
141+
print('init commands')
141142
for command, data in self._INIT:
142143
self.write(command, data)
143144

adafruit_rgb_display/st7735.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* Author(s): Radomir Dopieralski, Michael McWethy
2929
"""
3030

31+
import time
32+
3133
try:
3234
import struct
3335
except ImportError:
@@ -84,6 +86,9 @@
8486
_GMCTRP1 = const(0xE0)
8587
_GMCTRN1 = const(0xE1)
8688

89+
_TSTCMD1 = const(0xF0)
90+
_DISRPSM1 = const(0xF6)
91+
8792

8893
class ST7735(DisplaySPI):
8994
"""
@@ -193,3 +198,81 @@ def init(self):
193198
self.write(command, data)
194199
if self._bgr:
195200
self.write(_MADCTL, b'\xc0')
201+
202+
class ST7735S(ST7735):
203+
"""A simple driver for the ST7735S-based displays."""
204+
_INIT = (
205+
# Frame Rate
206+
(_FRMCTR1, b'\x01\x2c\x2d'), # B1
207+
(_FRMCTR2, b'\x01\x2c\x2d'), # B2
208+
(_FRMCTR3, b'\x01\x2c\x2d\x01\x2c\x2d'), # B3
209+
210+
# Column inversion
211+
(_INVCTR, b'\x07'), # B4
212+
213+
# Power Sequence
214+
(_PWCTR1, b'\xa2\x02\x84'), # C0
215+
(_PWCTR2, b'\xc5'), # C1
216+
(_PWCTR3, b'\x0a\x00'), # C2
217+
(_PWCTR4, b'\x8a\x2a'), # C3
218+
(_PWCTR5, b'\x8a\xee'), # C4
219+
220+
# VCOM
221+
(_VMCTR1, b'\x0e'), # C5
222+
223+
# Gamma
224+
(_GMCTRP1, b'\x0f\x1a\x0f\x18\x2f\x28\x20\x22' # E0
225+
b'\x1f\x1b\x23\x37\x00\x07\x02\x10'),
226+
227+
(_GMCTRN1, b'\x0f\x1b\x0f\x17\x33\x2c\x29\x2e' # E1
228+
b'\x30\x30\x39\x3f\x00\x07\x03\x10'),
229+
# Enable test command
230+
(_TSTCMD1, b'\x01'), # F0
231+
# Disable ram power save mode
232+
(_DISRPSM1, b'\x00'), # F6
233+
# 65k mode
234+
(_COLMOD, b'\x05'), # 3A
235+
# set scan direction: up to down, right to left
236+
(_MADCTL, b'\x60'), # 36
237+
)
238+
239+
#pylint: disable-msg=useless-super-delegation, too-many-arguments
240+
def __init__(self, spi, dc, cs, bl, rst=None, width=128, height=160,
241+
baudrate=16000000, polarity=0, phase=0, *,
242+
x_offset=2, y_offset=1, rotation=0, bgr=False):
243+
self._bl = bl
244+
# Turn on backlight
245+
print('turn on backlight')
246+
self._bl.switch_to_output(value=1)
247+
super().__init__(spi, dc, cs, rst, width, height,
248+
baudrate=baudrate, polarity=polarity, phase=phase,
249+
x_offset=x_offset, y_offset=y_offset, rotation=rotation)
250+
251+
# def reset(self):
252+
# print('reset')
253+
# self.rst.value = 1
254+
# time.sleep(0.100)
255+
# self.rst.value = 0
256+
# time.sleep(0.100)
257+
# self.rst.value = 1
258+
# time.sleep(0.100)
259+
260+
def init(self):
261+
262+
super().init()
263+
print('last commands of init')
264+
265+
# cols = struct.pack('>HH', 0, self.width - 1)
266+
# rows = struct.pack('>HH', 0, self.height - 1)
267+
268+
# for command, data in (
269+
# (_CASET, cols),
270+
# (_RASET, rows),
271+
# (_NORON, None),
272+
# (_DISPON, None),
273+
# ):
274+
# self.write(command, data)
275+
time.sleep(0.200)
276+
self.write(_SLPOUT)
277+
time.sleep(0.120)
278+
self.write(_DISPON)

0 commit comments

Comments
 (0)