Skip to content

Commit 3f3f7bd

Browse files
authored
Merge pull request #4 from HDR/main
Implement grayscale support
2 parents bb11cd4 + 42c745b commit 3f3f7bd

File tree

2 files changed

+125
-1
lines changed

2 files changed

+125
-1
lines changed

adafruit_uc8151d.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,58 @@
3838
b"\x50\x01\x97" # CDI setting
3939
)
4040

41+
_GRAYSCALE_START_SEQUENCE = (
42+
b"\x04\x80\xc8" # Power on
43+
b"\x00\x01\xbf" # Panel setting
44+
b"\x50\x01\x97" # CDI setting
45+
# Common voltage
46+
b"\x20\x2a"
47+
b"\x00\x0A\x00\x00\x00\x01"
48+
b"\x60\x14\x14\x00\x00\x01"
49+
b"\x00\x14\x00\x00\x00\x01"
50+
b"\x00\x13\x0A\x01\x00\x01"
51+
b"\x00\x00\x00\x00\x00\x00"
52+
b"\x00\x00\x00\x00\x00\x00"
53+
b"\x00\x00\x00\x00\x00\x00"
54+
# White to White
55+
b"\x21\x2a"
56+
b"\x40\x0A\x00\x00\x00\x01"
57+
b"\x90\x14\x14\x00\x00\x01"
58+
b"\x10\x14\x0A\x00\x00\x01"
59+
b"\xA0\x13\x01\x00\x00\x01"
60+
b"\x00\x00\x00\x00\x00\x00"
61+
b"\x00\x00\x00\x00\x00\x00"
62+
b"\x00\x00\x00\x00\x00\x00"
63+
# Black to White
64+
b"\x22\x2a"
65+
b"\x40\x0A\x00\x00\x00\x01"
66+
b"\x90\x14\x14\x00\x00\x01"
67+
b"\x00\x14\x0A\x00\x00\x01"
68+
b"\x99\x0B\x04\x04\x01\x01"
69+
b"\x00\x00\x00\x00\x00\x00"
70+
b"\x00\x00\x00\x00\x00\x00"
71+
b"\x00\x00\x00\x00\x00\x00"
72+
# White to Black
73+
b"\x23\x2a"
74+
b"\x40\x0A\x00\x00\x00\x01"
75+
b"\x90\x14\x14\x00\x00\x01"
76+
b"\x00\x14\x0A\x00\x00\x01"
77+
b"\x99\x0C\x01\x03\x04\x01"
78+
b"\x00\x00\x00\x00\x00\x00"
79+
b"\x00\x00\x00\x00\x00\x00"
80+
b"\x00\x00\x00\x00\x00\x00"
81+
# Black to Black
82+
b"\x24\x2a"
83+
b"\x80\x0A\x00\x00\x00\x01"
84+
b"\x90\x14\x14\x00\x00\x01"
85+
b"\x20\x14\x0A\x00\x00\x01"
86+
b"\x50\x13\x01\x00\x00\x01"
87+
b"\x00\x00\x00\x00\x00\x00"
88+
b"\x00\x00\x00\x00\x00\x00"
89+
b"\x00\x00\x00\x00\x00\x00"
90+
)
91+
92+
4193
_STOP_SEQUENCE = b"\x50\x01\xf7" b"\x07\x01\xA5" # CDI setting # Deep Sleep
4294
# pylint: disable=too-few-public-methods
4395
class UC8151D(displayio.EPaperDisplay):
@@ -57,14 +109,18 @@ class UC8151D(displayio.EPaperDisplay):
57109
"""
58110

59111
def __init__(self, bus, **kwargs):
112+
if kwargs.get("grayscale", False):
113+
start_sequence = bytearray(_GRAYSCALE_START_SEQUENCE)
114+
else:
115+
start_sequence = bytearray(_START_SEQUENCE)
60116
width = kwargs["width"]
61117
height = kwargs["height"]
62118
if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
63119
width, height = height, width
64120

65121
super().__init__(
66122
bus,
67-
_START_SEQUENCE,
123+
start_sequence,
68124
_STOP_SEQUENCE,
69125
**kwargs,
70126
ram_width=128,

examples/uc8151d_grayscale_test.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2022 Martin Refseth, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
"""Simple test script for 1.54" 152x152 grayscale display.
6+
7+
Supported products:
8+
* 1.54" Grayscale Display (GDEW0154T8D)
9+
"""
10+
# pylint: disable=no-member
11+
12+
import time
13+
import board
14+
import displayio
15+
import busio
16+
import adafruit_uc8151d
17+
18+
displayio.release_displays()
19+
20+
# Pinout intended for use with a Raspberry Pi Pico
21+
clk = board.GP10
22+
si = board.GP11
23+
dc = board.GP8
24+
cs = board.GP9
25+
rst = board.GP12
26+
busy = board.GP13
27+
28+
display_bus = displayio.FourWire(
29+
busio.SPI(clk, si), command=dc, chip_select=cs, reset=rst, baudrate=1000000
30+
)
31+
32+
time.sleep(1)
33+
34+
display = adafruit_uc8151d.UC8151D(
35+
display_bus, width=152, height=152, busy_pin=busy, rotation=180, grayscale=True
36+
)
37+
38+
39+
bitmap = displayio.Bitmap(152, 152, 4)
40+
41+
# Draw Black
42+
for x in range(0, 152):
43+
for y in range(0, 38):
44+
bitmap[x, y] = 0
45+
# Draw Dark Gray
46+
for x in range(0, 152):
47+
for y in range(38, 76):
48+
bitmap[x, y] = 1
49+
# Draw Light Gray
50+
for x in range(0, 152):
51+
for y in range(76, 114):
52+
bitmap[x, y] = 2
53+
# Draw White
54+
for x in range(0, 152):
55+
for y in range(114, 152):
56+
bitmap[x, y] = 3
57+
58+
palette = displayio.Palette(4)
59+
palette[0] = 0x000000 # Black
60+
palette[1] = 0x404040 # Dark Gray
61+
palette[2] = 0x808080 # Light Gray
62+
palette[3] = 0xFFFFFF # White
63+
64+
g = displayio.Group()
65+
t = displayio.TileGrid(bitmap, pixel_shader=palette)
66+
g.append(t)
67+
display.show(g)
68+
display.refresh()

0 commit comments

Comments
 (0)