Skip to content

Commit e695787

Browse files
committed
add 2.7" tricolor and single byte transfer support for weird chips
1 parent 42de3be commit e695787

File tree

2 files changed

+195
-17
lines changed

2 files changed

+195
-17
lines changed

adafruit_epd/epd.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def __init__(self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy
6868

6969
# SPI interface (required)
7070
self.spi_device = spi
71+
self._spibuf = bytearray(1)
72+
self._single_byte_tx = False
7173

7274
self.sram = None
7375
if sramcs_pin:
@@ -100,21 +102,19 @@ def display(self):
100102

101103
#first data byte from SRAM will be transfered in at the
102104
#same time as the EPD command is transferred out
103-
cmd = self.write_ram(0)
105+
databyte = self.write_ram(0)
104106

105107
while not self.spi_device.try_lock():
106108
pass
107109
self._dc.value = True
108110

109111
if self.sram:
110-
xfer = bytearray([cmd])
111-
outbuf = bytearray(1)
112112
for _ in range(self._buffer1_size):
113-
outbuf[0] = xfer[0]
114-
self.spi_device.write_readinto(outbuf, xfer)
113+
databyte = self._spi_transfer(databyte)
115114
self.sram.cs_pin.value = True
116115
else:
117-
self.spi_device.write(self._buffer1)
116+
for databyte in self._buffer1:
117+
self._spi_transfer(databyte)
118118

119119
self._cs.value = True
120120
self.spi_device.unlock()
@@ -135,21 +135,19 @@ def display(self):
135135

136136
#first data byte from SRAM will be transfered in at the
137137
#same time as the EPD command is transferred out
138-
cmd = self.write_ram(1)
138+
databyte = self.write_ram(1)
139139

140140
while not self.spi_device.try_lock():
141141
pass
142142
self._dc.value = True
143143

144144
if self.sram:
145-
xfer = bytearray([cmd])
146-
outbuf = bytearray(1)
147-
for _ in range(self._buffer1_size):
148-
outbuf[0] = xfer[0]
149-
self.spi_device.write_readinto(outbuf, xfer)
145+
for _ in range(self._buffer2_size):
146+
databyte = self._spi_transfer(databyte)
150147
self.sram.cs_pin.value = True
151148
else:
152-
self.spi_device.write(self._buffer2)
149+
for databyte in self._buffer2:
150+
self._spi_transfer(databyte)
153151

154152
self._cs.value = True
155153
self.spi_device.unlock()
@@ -169,20 +167,30 @@ def command(self, cmd, data=None, end=True):
169167
self._cs.value = True
170168
self._dc.value = False
171169
self._cs.value = False
172-
outbuf = bytearray(1)
173170

174171
while not self.spi_device.try_lock():
175172
pass
176-
self.spi_device.write_readinto(bytearray([cmd]), outbuf)
173+
ret = self._spi_transfer(cmd)
177174

178175
if data is not None:
179176
self._dc.value = True
180-
self.spi_device.write(data)
177+
for b in data:
178+
self._spi_transfer(b)
181179
if end:
182180
self._cs.value = True
183181
self.spi_device.unlock()
184182

185-
return outbuf[0]
183+
return ret
184+
185+
def _spi_transfer(self, databyte):
186+
"""Transfer one byte, toggling the cs pin if required by the EPD chipset"""
187+
self._spibuf[0] = databyte
188+
if self._single_byte_tx:
189+
self._cs.value = False
190+
self.spi_device.write_readinto(self._spibuf, self._spibuf)
191+
if self._single_byte_tx:
192+
self._cs.value = True
193+
return self._spibuf[0]
186194

187195
def power_up(self):
188196
"""Power up the display in preparation for writing RAM and updating.

adafruit_epd/il91874.py

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2018 Dean Miller for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_epd.il91874` - Adafruit IL91874 - ePaper display driver
24+
====================================================================================
25+
CircuitPython driver for Adafruit IL91874 display breakouts
26+
* Author(s): Dean Miller, Ladyada
27+
"""
28+
29+
import time
30+
from micropython import const
31+
import adafruit_framebuf
32+
from adafruit_epd.epd import Adafruit_EPD
33+
34+
_IL91874_PANEL_SETTING = const(0x00)
35+
_IL91874_POWER_SETTING = const(0x01)
36+
_IL91874_POWER_OFF = const(0x02)
37+
_IL91874_POWER_OFF_SEQUENCE = const(0x03)
38+
_IL91874_POWER_ON = const(0x04)
39+
_IL91874_POWER_ON_MEASURE = const(0x05)
40+
_IL91874_BOOSTER_SOFT_START = const(0x06)
41+
_IL91874_DEEP_SLEEP = const(0x07)
42+
_IL91874_DTM1 = const(0x10)
43+
_IL91874_DATA_STOP = const(0x11)
44+
_IL91874_DISPLAY_REFRESH = const(0x12)
45+
_IL91874_DTM2 = const(0x13)
46+
_IL91874_PDTM1 = const(0x14)
47+
_IL91874_PDTM2 = const(0x15)
48+
_IL91874_PDRF = const(0x16)
49+
_IL91874_LUT1 = const(0x20)
50+
_IL91874_LUTWW = const(0x21)
51+
_IL91874_LUTBW = const(0x22)
52+
_IL91874_LUTWB = const(0x23)
53+
_IL91874_LUTBB = const(0x24)
54+
_IL91874_PLL = const(0x30)
55+
_IL91874_CDI = const(0x50)
56+
_IL91874_RESOLUTION = const(0x61)
57+
_IL91874_VCM_DC_SETTING = const(0x82)
58+
59+
_LUT_VCOMDC = b'\x00\x00\x00\x1a\x1a\x00\x00\x01\x00\n\n\x00\x00\x08\x00\x0e\x01\x0e\x01\x10\x00\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01'
60+
_LUT_WW = b'\x90\x1a\x1a\x00\x00\x01@\n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x80\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01'
61+
_LUT_BW = b'\xa0\x1a\x1a\x00\x00\x01\x00\n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x90\n\n\x00\x00\x08\xb0\x04\x10\x00\x00\x05\xb0\x03\x0e\x00\x00\n\xc0#\x00\x00\x00\x01'
62+
_LUT_BB = b'\x90\x1a\x1a\x00\x00\x01@\n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x80\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01'
63+
_LUT_WB = b'\x90\x1a\x1a\x00\x00\x01 \n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x10\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01'
64+
65+
class Adafruit_IL91874(Adafruit_EPD):
66+
"""driver class for Adafruit IL91874 ePaper display breakouts"""
67+
# pylint: disable=too-many-arguments
68+
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
69+
super(Adafruit_IL91874, self).__init__(width, height, spi, cs_pin, dc_pin,
70+
sramcs_pin, rst_pin, busy_pin)
71+
72+
self._buffer1_size = int(width * height / 8)
73+
self._buffer2_size = int(width * height / 8)
74+
75+
if sramcs_pin:
76+
self._buffer1 = self.sram.get_view(0)
77+
self._buffer2 = self.sram.get_view(self._buffer1_size)
78+
else:
79+
self._buffer1 = bytearray((width * height) // 8)
80+
self._buffer2 = bytearray((width * height) // 8)
81+
# since we have *two* framebuffers - one for red and one for black
82+
# we dont subclass but manage manually
83+
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
84+
buf_format=adafruit_framebuf.MHMSB)
85+
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
86+
buf_format=adafruit_framebuf.MHMSB)
87+
self.black_invert = True
88+
self.red_invert = False
89+
self._single_byte_tx = True
90+
91+
def begin(self, reset=True):
92+
"""Begin communication with the display and set basic settings"""
93+
if reset:
94+
self.hardware_reset()
95+
96+
self.power_down()
97+
98+
def busy_wait(self):
99+
"""Wait for display to be done with current task, either by polling the
100+
busy pin, or pausing"""
101+
if self._busy:
102+
while not self._busy.value:
103+
pass
104+
else:
105+
time.sleep(0.5)
106+
107+
def power_up(self):
108+
"""Power up the display in preparation for writing RAM and updating"""
109+
self.hardware_reset()
110+
time.sleep(0.2)
111+
self.command(_IL91874_POWER_ON)
112+
self.busy_wait()
113+
114+
self.command(_IL91874_PANEL_SETTING, bytearray([0xAF]))
115+
self.command(_IL91874_PLL, bytearray([0x3A]))
116+
self.command(_IL91874_POWER_SETTING, bytearray([0x03, 0x00, 0x2b, 0x2b, 0x09]))
117+
self.command(_IL91874_BOOSTER_SOFT_START, bytearray([0x07, 0x07, 0x17]))
118+
119+
self.command(0xF8, bytearray([0x60, 0xA5])) # mystery command in example code
120+
self.command(0xF8, bytearray([0x89, 0xA5])) # mystery command in example code
121+
self.command(0xF8, bytearray([0x90, 0x00])) # mystery command in example code
122+
self.command(0xF8, bytearray([0x93, 0xA2])) # mystery command in example code
123+
self.command(0xF8, bytearray([0x73, 0x41])) # mystery command in example code
124+
125+
self.command(_IL91874_VCM_DC_SETTING, bytearray([0x12]))
126+
self.command(_IL91874_CDI, bytearray([0x87]))
127+
128+
# Look Up Tables
129+
self.command(_IL91874_LUT1, _LUT_VCOMDC);
130+
self.command(_IL91874_LUTWW, _LUT_WW);
131+
self.command(_IL91874_LUTBW, _LUT_BW);
132+
self.command(_IL91874_LUTWB, _LUT_WB);
133+
self.command(_IL91874_LUTBB, _LUT_BB);
134+
135+
_b0 = (self._width >> 8) & 0xFF
136+
_b1 = self._width & 0xFF
137+
_b2 = (self._height >> 8) & 0xFF
138+
_b3 = self._height & 0xFF
139+
self.command(_IL91874_RESOLUTION, bytearray([_b0, _b1, _b2, _b3]))
140+
self.command(_IL91874_PDRF, bytearray([0x00]))
141+
142+
def power_down(self):
143+
"""Power down the display - required when not actively displaying!"""
144+
self.command(_IL91874_POWER_OFF, bytearray([0x17]))
145+
self.busy_wait()
146+
147+
if self._rst: # Only deep sleep if we can get out of it
148+
self.command(_IL91874_DEEP_SLEEP, bytearray([0xA5]))
149+
150+
def update(self):
151+
"""Update the display from internal memory"""
152+
self.command(_IL91874_DISPLAY_REFRESH)
153+
self.busy_wait()
154+
if not self._busy:
155+
time.sleep(16) # wait 16 seconds
156+
157+
def write_ram(self, index):
158+
"""Send the one byte command for starting the RAM write process. Returns
159+
the byte read at the same time over SPI. index is the RAM buffer, can be
160+
0 or 1 for tri-color displays."""
161+
if index == 0:
162+
return self.command(_IL91874_DTM1, end=False)
163+
if index == 1:
164+
return self.command(_IL91874_DTM2, end=False)
165+
raise RuntimeError("RAM index must be 0 or 1")
166+
167+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
168+
"""Set the RAM address location, not used on this chipset but required by
169+
the superclass"""
170+
return # on this chip it does nothing

0 commit comments

Comments
 (0)