Skip to content

Commit 093e53f

Browse files
matemaciekrm-hullGadgetoid
authored
Add support for ST7789 (#141)
* Documentation * ST7789 support (#92) Co-authored-by: Richard Hull <rm_hull@yahoo.co.uk> * Move from numpy to python for `st7789.display` * Make `flake` happy * Add tests for st7789, change implementation to more in line with other displays * QA remarks * Contrast test * Review remarks addressed * Performance improvement for st7789 Co-authored-by: Richard Hull <rm_hull@yahoo.co.uk> Co-authored-by: Philip Howard <phil@gadgetoid.com>
1 parent a7925cf commit 093e53f

File tree

12 files changed

+186
-11
lines changed

12 files changed

+186
-11
lines changed

CONTRIBUTING.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ Contributors
2424
* Kevin Stone (@kevinastone)
2525
* Dhrone (@dhrone)
2626
* Matthew Lovell (@mattblovell)
27+
* Maciej Sokolowski (@matemaciek)

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ luma.lcd **|**
88

99
luma.lcd
1010
========
11-
**HD44780, PCD8544, ST7735, ST7567, HT1621, UC1701X, ILI9341 Display Drivers**
11+
**HD44780, PCD8544, ST7735, ST7789, ST7567, HT1621, UC1701X, ILI9341 Display Drivers**
1212

1313
.. image:: https://github.com/rm-hull/luma.lcd/workflows/luma.lcd/badge.svg?branch=master
1414
:target: https://github.com/rm-hull/luma.lcd/actions?workflow=luma.lcd

doc/hardware.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Device Pin Name Remarks RPi Pin RPi Function
180180
* If you're already using the listed GPIO pins for Data/Command and/or Reset,
181181
you can select other pins and pass :py:attr:`gpio_DC` and/or :py:attr:`gpio_RST`
182182
argument specifying the new *GPIO* pin numbers in your serial interface create
183-
call (this applies to PCD8544, ST7567 and ST7735).
183+
call (this applies to PCD8544, ST7567, ST7735 and ST7789).
184184

185185
* Because CE is connected to CE0, the display is available on SPI port 0. You
186186
can connect it to CE1 to have it available on port 1. If so, pass

doc/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Luma.LCD: Display drivers for PCD8544, ST7735, ST7567, HT1621, UC1701X, ILI9341, HD44780
2-
========================================================================================
1+
Luma.LCD: Display drivers for PCD8544, ST7735, ST7789, ST7567, HT1621, UC1701X, ILI9341, HD44780
2+
================================================================================================
33
.. image:: https://github.com/rm-hull/luma.lcd/workflows/luma.lcd/badge.svg?branch=master
44
:target: https://github.com/rm-hull/luma.lcd/actions?workflow=luma.lcd
55

doc/intro.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ The ST7567 display supports a resolution of 128 x 64 monochrome pixels:
7070

7171
- :download:`PCD8544 <tech-spec/PCD8544.pdf>`
7272
- :download:`ST7735 <tech-spec/ST7735.pdf>`
73+
- :download:`ST7789 <tech-spec/ST7789.pdf>`
7374
- :download:`HT1621 <tech-spec/HT1621.pdf>`
7475
- :download:`UC1701X <tech-spec/UC1701X.pdf>`
7576
- :download:`ILI9341 <tech-spec/ILI9341.pdf>`

doc/python-usage.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ In this example, we are using an SPI interface with a pcd8544 display.
1414
1515
from luma.core.interface.serial import i2c, spi, parallel, pcf8574
1616
from luma.core.render import canvas
17-
from luma.lcd.device import pcd8544, st7735, st7567, uc1701x, ili9341, ili9486, hd44780
17+
from luma.lcd.device import pcd8544, st7735, st7789, st7567, uc1701x, ili9341, ili9486, hd44780
1818
1919
serial = spi(port=0, device=0, gpio_DC=23, gpio_RST=24)
2020
device = pcd8544(serial)
2121
2222
The display device should now be properly configured.
2323

24-
The :py:class:`~luma.lcd.device.pcd8544`, :py:class:`~luma.lcd.device.st7735`,
24+
The :py:class:`~luma.lcd.device.pcd8544`, :py:class:`~luma.lcd.device.st7735`, :py:class:`~luma.lcd.device.st7789`,
2525
:py:class:`~luma.lcd.device.st7567`, :py:class:`~luma.lcd.device.uc1701x`, :py:class:`~luma.lcd.device.ili9341`,
2626
:py:class:`~luma.lcd.device.ili9486` and :py:class:`~luma.lcd.device.hd44780`
2727
classes all expose a :py:meth:`~luma.lcd.device.pcd8544.display` method which
@@ -69,13 +69,13 @@ effect (see the *3d_box.py* example, below).
6969
with canvas(device, dither=True) as draw:
7070
draw.rectangle((10, 10, 30, 30), outline="white", fill="red")
7171
72-
The ST7735 and ILI9341 devices can display 262K colour RGB images. When supplying
72+
The ST7735, ST7789 and ILI9341 devices can display 262K colour RGB images. When supplying
7373
24-bit RGB images, they are automatically downscaled to 18-bit RGB to fit
7474
these device's 262K color-space.
7575

7676
Landscape / Portrait Orientation
7777
--------------------------------
78-
By default the PCD8544, ST7735, UC1701X and ILI9341 displays will all be oriented
78+
By default the PCD8544, ST7735, ST7789, UC1701X and ILI9341 displays will all be oriented
7979
in landscape mode (84x48, 160x128, 128x64 and 320x240 pixels respectively). Should
8080
you have an application that requires the display to be mounted in a portrait
8181
aspect, then add a :py:attr:`rotate=N` parameter when creating the device:

doc/tech-spec/ST7789.pdf

2.99 MB
Binary file not shown.

luma/lcd/const.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class uc1701x(object):
3838
DISPLAYOFF = 0xAE
3939

4040

41+
class st7789(object):
42+
DISPLAYON = 0x29
43+
DISPLAYOFF = 0x28
44+
45+
4146
class hd44780(object):
4247
"""
4348
Values to be used by the hd44780 class during initialization of the display.

luma/lcd/device.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from luma.core.virtual import character
4848
from luma.core.bitmap_font import embedded_fonts
4949

50-
__all__ = ["pcd8544", "st7735", "ht1621", "uc1701x", "st7567", "ili9341", "ili9486", "hd44780"]
50+
__all__ = ["pcd8544", "st7735", "st7789", "ht1621", "uc1701x", "st7567", "ili9341", "ili9486", "hd44780"]
5151

5252

5353
class GPIOBacklight:
@@ -292,6 +292,64 @@ def contrast(self, value):
292292
self.command(0x21, 0x14, value | 0x80, 0x20)
293293

294294

295+
class st7789(backlit_device):
296+
"""
297+
Serial interface to a colour ST7789 240x240 pixel LCD display.
298+
299+
.. versionadded:: 2.9.0
300+
"""
301+
def __init__(self, serial_interface=None, rotate=0, **kwargs):
302+
super(st7789, self).__init__(luma.lcd.const.st7789, serial_interface, **kwargs)
303+
self.capabilities(240, 240, rotate, mode="RGB")
304+
305+
self.command(0x36, 0x70) # MADCTL (36h): Memory Data Access Control: Bottom to Top, Right to Left, Reverse Mode
306+
self.command(0x3A, 0x06) # COLMOD (3Ah): Interface Pixel Format: 18bit/pixel
307+
self.command(0xB2, # PORCTRL (B2h): Porch Setting: Disable separate porch control, 0xC in normal mode, 0x3 in idle and partial modes
308+
0x0C, 0x0C, 0x00, 0x33, 0x33)
309+
self.command(0xB7, 0x35) # GCTRL (B7h): Gate Control: VGH = 13.26V, VGL = -10.43V
310+
self.command(0xBB, 0x19) # VCOMS (BBh): VCOM Setting: 0.725V
311+
self.command(0xC0, 0x2C) # LCMCTRL (C0h): LCM Control: XBGR, XMX, XMH
312+
self.command(0xC2, 0x01) # VDVVRHEN (C2h): VDV and VRH Command Enable: VDV and VRH register value comes from command write
313+
self.command(0xC3, 0x12) # VRHS (C3h): VRH Set: 4.45V + (vcom + vcom offset + vdv)
314+
self.command(0xC4, 0x20) # VDVS (C4h): VDV Set: 0V
315+
self.command(0xC6, 0x0F) # FRCTRL2 (C6h): Frame Rate Control in Normal Mode: 60Hz
316+
self.command(0xD0, # PWCTRL1 (D0h): Power Control 1: AVDD = 6.8V, AVCL = -4.8V, VDDS = 2.3V
317+
0xA4, 0xA1)
318+
self.command(0xE0, # PVGAMCTRL (E0h): Positive Voltage Gamma Control
319+
0xD0, 0x04, 0x0D, 0x11, 0x13, 0x2B, 0x3F, 0x54, 0x4C, 0x18, 0x0D, 0x0B, 0x1F, 0x23)
320+
self.command(0xE1, # NVGAMCTRL (E1h): Negative Voltage Gamma Control
321+
0xD0, 0x04, 0x0C, 0x11, 0x13, 0x2C, 0x3F, 0x44, 0x51, 0x2F, 0x1F, 0x1F, 0x20, 0x23)
322+
self.command(0x21) # INVON (21h): Display Inversion On
323+
self.command(0x11) # SLPOUT (11h): Sleep Out
324+
self.command(0x29) # DISPON (29h): Display On
325+
326+
self.clear()
327+
self.show()
328+
329+
def set_window(self, x1, y1, x2, y2):
330+
self.command(0x2A, # CASET (2Ah): Column Address Set
331+
x1 >> 8, x1 & 0xFF, (x2 - 1) >> 8, (x2 - 1) & 0xFF)
332+
self.command(0x2B, # RASET (2Bh): Row Address Set
333+
y1 >> 8, y1 & 0xFF, (y2 - 1) >> 8, (y2 - 1) & 0xFF)
334+
self.command(0x2C) # RAMWR (2Ch): Memory Write
335+
336+
def display(self, image):
337+
w, h = 240, 240
338+
self.set_window(0, 0, w, h)
339+
340+
image = self.preprocess(image)
341+
self.data(list(image.convert("RGB").tobytes()))
342+
343+
def contrast(self, level):
344+
"""
345+
NOT SUPPORTED
346+
347+
:param level: Desired contrast level in the range of 0-255.
348+
:type level: int
349+
"""
350+
assert(0 <= level <= 255)
351+
352+
295353
class st7567(backlit_device):
296354
"""
297355
Serial interface to a monochrome ST7567 128x64 pixel LCD display.

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[metadata]
22
name = luma.lcd
33
version = attr: luma.lcd.__version__
4-
description = A library to drive PCD8544, HT1621, ST7735, ST7567, UC1701X and ILI9341-based LCD displays
4+
description = A library to drive PCD8544, HT1621, ST7735, ST7789, ST7567, UC1701X and ILI9341-based LCD displays
55
long_description = file: README.rst, CONTRIBUTING.rst, CHANGES.rst
66
long_description_content_type = text/x-rst
7-
keywords = raspberry pi, rpi, lcd, display, screen, rgb, monochrome, greyscale, color, nokia 5110, pcd8544, st7735, uc1701x, ht1621, ili9341, hd44780, spi, i2c, parallel, bitbang6800, pcf8574
7+
keywords = raspberry pi, rpi, lcd, display, screen, rgb, monochrome, greyscale, color, nokia 5110, pcd8544, st7735, st7789, uc1701x, ht1621, ili9341, hd44780, spi, i2c, parallel, bitbang6800, pcf8574
88
author = Richard Hull
99
author_email = richard.hull@destructuring-bind.org
1010
url = https://github.com/rm-hull/luma.lcd

0 commit comments

Comments
 (0)