Skip to content

Commit fe0fb74

Browse files
authored
Merge pull request #12 from tannewt/grayscale
Add grayscale support
2 parents a016391 + d3597b3 commit fe0fb74

File tree

3 files changed

+126
-3
lines changed

3 files changed

+126
-3
lines changed

adafruit_il0373.py

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,61 @@
5555
b"\x01\x05\x03\x00\x2b\x2b\x09" # power setting
5656
b"\x06\x03\x17\x17\x17" # booster soft start
5757
b"\x04\x80\xc8" # power on and wait 200 ms
58-
b"\x00\x01\xcf" # panel setting
58+
b"\x00\x01\x0f" # panel setting. Further filled in below.
5959
b"\x50\x01\x37" # CDI setting
60-
b"\x30\x01\x29" # PLL
60+
b"\x30\x01\x29" # PLL set to 150 Hz
6161
b"\x61\x03\x00\x00\x00" # Resolution
6262
b"\x82\x81\x32\x0a" # VCM DC and delay 50ms
6363
)
6464

65+
_GRAYSCALE_LUT = (
66+
# Common voltage
67+
b"\x20\x2a"
68+
b"\x00\x0A\x00\x00\x00\x01"
69+
b"\x60\x14\x14\x00\x00\x01"
70+
b"\x00\x14\x00\x00\x00\x01"
71+
b"\x00\x13\x0A\x01\x00\x01"
72+
b"\x00\x00\x00\x00\x00\x00"
73+
b"\x00\x00\x00\x00\x00\x00"
74+
b"\x00\x00\x00\x00\x00\x00"
75+
# White to White
76+
b"\x21\x2a"
77+
b"\x40\x0A\x00\x00\x00\x01"
78+
b"\x90\x14\x14\x00\x00\x01"
79+
b"\x10\x14\x0A\x00\x00\x01"
80+
b"\xA0\x13\x01\x00\x00\x01"
81+
b"\x00\x00\x00\x00\x00\x00"
82+
b"\x00\x00\x00\x00\x00\x00"
83+
b"\x00\x00\x00\x00\x00\x00"
84+
# Black to White
85+
b"\x22\x2a"
86+
b"\x40\x0A\x00\x00\x00\x01"
87+
b"\x90\x14\x14\x00\x00\x01"
88+
b"\x00\x14\x0A\x00\x00\x01"
89+
b"\x99\x0C\x01\x03\x04\x01"
90+
b"\x00\x00\x00\x00\x00\x00"
91+
b"\x00\x00\x00\x00\x00\x00"
92+
b"\x00\x00\x00\x00\x00\x00"
93+
# White to Black
94+
b"\x23\x2a"
95+
b"\x40\x0A\x00\x00\x00\x01"
96+
b"\x90\x14\x14\x00\x00\x01"
97+
b"\x00\x14\x0A\x00\x00\x01"
98+
b"\x99\x0B\x04\x04\x01\x01"
99+
b"\x00\x00\x00\x00\x00\x00"
100+
b"\x00\x00\x00\x00\x00\x00"
101+
b"\x00\x00\x00\x00\x00\x00"
102+
# Black to Black
103+
b"\x24\x2a"
104+
b"\x80\x0A\x00\x00\x00\x01"
105+
b"\x90\x14\x14\x00\x00\x01"
106+
b"\x20\x14\x0A\x00\x00\x01"
107+
b"\x50\x13\x01\x00\x00\x01"
108+
b"\x00\x00\x00\x00\x00\x00"
109+
b"\x00\x00\x00\x00\x00\x00"
110+
b"\x00\x00\x00\x00\x00\x00"
111+
)
112+
65113
_STOP_SEQUENCE = (
66114
b"\x50\x01\x17" # CDI setting
67115
b"\x82\x01\x00" # VCM DC and delay 50ms
@@ -90,7 +138,12 @@ class IL0373(displayio.EPaperDisplay):
90138
"""
91139

92140
def __init__(self, bus, swap_rams=False, **kwargs):
93-
start_sequence = bytearray(_START_SEQUENCE)
141+
if kwargs.get("grayscale", False):
142+
start_sequence = bytearray(len(_START_SEQUENCE) + len(_GRAYSCALE_LUT))
143+
start_sequence[: len(_START_SEQUENCE)] = _START_SEQUENCE
144+
start_sequence[len(_START_SEQUENCE) :] = _GRAYSCALE_LUT
145+
else:
146+
start_sequence = bytearray(_START_SEQUENCE)
94147

95148
width = kwargs["width"]
96149
height = kwargs["height"]
@@ -109,6 +162,25 @@ def __init__(self, bus, swap_rams=False, **kwargs):
109162
write_color_ram_command = 0x13
110163
color_bits_inverted = kwargs.pop("color_bits_inverted", True)
111164
black_bits_inverted = kwargs.pop("black_bits_inverted", False)
165+
if "highlight_color" not in kwargs:
166+
start_sequence[17] |= 1 << 4 # Set BWR to only do black and white.
167+
if kwargs.get("grayscale", False):
168+
start_sequence[17] |= (
169+
1 << 5
170+
) # Set REG_EN to use the LUT sequence from the registers.
171+
start_sequence[6] = 0x13 # Boost the voltage
172+
start_sequence[23] = 0x3C # PLL set to 50 Hz (M = 7, N = 4)
173+
174+
# Set the resolution to scan
175+
if width > 128:
176+
start_sequence[17] |= 0b11 << 5 # 160x296
177+
elif height > 252 or width > 96:
178+
start_sequence[17] |= 0b10 << 5 # 128x296
179+
elif height > 230:
180+
start_sequence[17] |= 0b01 << 5 # 96x252
181+
else:
182+
pass # 0b00 is 96x230
183+
112184
super().__init__(
113185
bus,
114186
start_sequence,

examples/display-ruler.bmp

16 Bytes
Binary file not shown.

examples/il0373_2.9_grayscale.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Simple test script for 2.9" 296x128 grayscale display.
2+
3+
Supported products:
4+
* Adafruit 2.9" Grayscale
5+
* https://www.adafruit.com/product/4777
6+
"""
7+
8+
import time
9+
import busio
10+
import board
11+
import displayio
12+
import adafruit_il0373
13+
14+
displayio.release_displays()
15+
16+
# This pinout works on a Feather M4 and may need to be altered for other boards.
17+
spi = busio.SPI(board.SCK, board.MOSI) # Uses SCK and MOSI
18+
epd_cs = board.D9
19+
epd_dc = board.D10
20+
21+
display_bus = displayio.FourWire(
22+
spi, command=epd_dc, chip_select=epd_cs, baudrate=1000000
23+
)
24+
time.sleep(1)
25+
26+
display = adafruit_il0373.IL0373(
27+
display_bus,
28+
width=296,
29+
height=128,
30+
rotation=270,
31+
black_bits_inverted=False,
32+
color_bits_inverted=False,
33+
grayscale=True,
34+
refresh_time=1,
35+
)
36+
37+
g = displayio.Group()
38+
39+
f = open("/display-ruler.bmp", "rb")
40+
41+
pic = displayio.OnDiskBitmap(f)
42+
t = displayio.TileGrid(pic, pixel_shader=displayio.ColorConverter())
43+
g.append(t)
44+
45+
display.show(g)
46+
47+
display.refresh()
48+
49+
print("refreshed")
50+
51+
time.sleep(120)

0 commit comments

Comments
 (0)