Skip to content

Commit eb8fe05

Browse files
committed
add tri-color 4.2"
1 parent d37b643 commit eb8fe05

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

adafruit_epd/il0398.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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.il0398` - Adafruit IL0398 - ePaper display driver
24+
====================================================================================
25+
CircuitPython driver for Adafruit IL0398 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+
_IL0398_PANEL_SETTING = const(0x00)
35+
_IL0398_POWER_SETTING = const(0x01)
36+
_IL0398_POWER_OFF = const(0x02)
37+
_IL0398_POWER_OFF_SEQUENCE = const(0x03)
38+
_IL0398_POWER_ON = const(0x04)
39+
_IL0398_POWER_ON_MEASURE = const(0x05)
40+
_IL0398_BOOSTER_SOFT_START = const(0x06)
41+
_IL0398_DEEP_SLEEP = const(0x07)
42+
_IL0398_DTM1 = const(0x10)
43+
_IL0398_DATA_STOP = const(0x11)
44+
_IL0398_DISPLAY_REFRESH = const(0x12)
45+
_IL0398_DTM2 = const(0x13)
46+
_IL0398_PDTM1 = const(0x14)
47+
_IL0398_PDTM2 = const(0x15)
48+
_IL0398_PDRF = const(0x16)
49+
_IL0398_LUT1 = const(0x20)
50+
_IL0398_LUTWW = const(0x21)
51+
_IL0398_LUTBW = const(0x22)
52+
_IL0398_LUTWB = const(0x23)
53+
_IL0398_LUTBB = const(0x24)
54+
_IL0398_PLL = const(0x30)
55+
_IL0398_CDI = const(0x50)
56+
_IL0398_RESOLUTION = const(0x61)
57+
_IL0398_GETSTATUS = const(0x71)
58+
_IL0398_VCM_DC_SETTING = const(0x82)
59+
60+
class Adafruit_IL0398(Adafruit_EPD):
61+
"""driver class for Adafruit IL0373 ePaper display breakouts"""
62+
# pylint: disable=too-many-arguments
63+
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
64+
super(Adafruit_IL0398, self).__init__(width, height, spi, cs_pin, dc_pin,
65+
sramcs_pin, rst_pin, busy_pin)
66+
67+
self._buffer1_size = int(width * height / 8)
68+
self._buffer2_size = int(width * height / 8)
69+
70+
if sramcs_pin:
71+
self._buffer1 = self.sram.get_view(0)
72+
self._buffer2 = self.sram.get_view(self._buffer1_size)
73+
else:
74+
self._buffer1 = bytearray((width * height) // 8)
75+
self._buffer2 = bytearray((width * height) // 8)
76+
# since we have *two* framebuffers - one for red and one for black
77+
# we dont subclass but manage manually
78+
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
79+
buf_format=adafruit_framebuf.MHMSB)
80+
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
81+
buf_format=adafruit_framebuf.MHMSB)
82+
self.set_black_buffer(0, True)
83+
self.set_color_buffer(1, True)
84+
# pylint: enable=too-many-arguments
85+
86+
def begin(self, reset=True):
87+
"""Begin communication with the display and set basic settings"""
88+
if reset:
89+
self.hardware_reset()
90+
self.power_down()
91+
92+
def busy_wait(self):
93+
"""Wait for display to be done with current task, either by polling the
94+
busy pin, or pausing"""
95+
if self._busy:
96+
while not self._busy.value:
97+
#self.command(_IL0398_GETSTATUS)
98+
time.sleep(0.01)
99+
else:
100+
time.sleep(0.5)
101+
102+
def power_up(self):
103+
"""Power up the display in preparation for writing RAM and updating"""
104+
self.hardware_reset()
105+
self.busy_wait()
106+
107+
self.command(_IL0398_BOOSTER_SOFT_START, bytearray([0x17, 0x17, 0x17]))
108+
self.command(_IL0398_POWER_ON)
109+
110+
self.busy_wait()
111+
time.sleep(0.2)
112+
113+
self.command(_IL0398_PANEL_SETTING, bytearray([0x0F]))
114+
_b0 = (self._width >> 8) & 0xFF
115+
_b1 = self._width & 0xFF
116+
_b2 = (self._height >> 8) & 0xFF
117+
_b3 = self._height & 0xFF
118+
self.command(_IL0398_RESOLUTION, bytearray([_b0, _b1, _b2, _b3]))
119+
time.sleep(0.05)
120+
121+
def power_down(self):
122+
"""Power down the display - required when not actively displaying!"""
123+
self.command(_IL0398_CDI, bytearray([0xF7]))
124+
self.command(_IL0398_POWER_OFF)
125+
self.busy_wait();
126+
self.command(_IL0398_DEEP_SLEEP, bytearray([0xA5]))
127+
128+
def update(self):
129+
"""Update the display from internal memory"""
130+
self.command(_IL0398_DISPLAY_REFRESH)
131+
time.sleep(0.1)
132+
self.busy_wait()
133+
if not self._busy:
134+
time.sleep(15) # wait 15 seconds
135+
136+
def write_ram(self, index):
137+
"""Send the one byte command for starting the RAM write process. Returns
138+
the byte read at the same time over SPI. index is the RAM buffer, can be
139+
0 or 1 for tri-color displays."""
140+
if index == 0:
141+
return self.command(_IL0398_DTM1, end=False)
142+
if index == 1:
143+
return self.command(_IL0398_DTM2, end=False)
144+
raise RuntimeError("RAM index must be 0 or 1")
145+
146+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
147+
"""Set the RAM address location, not used on this chipset but required by
148+
the superclass"""
149+
return # on this chip it does nothing

0 commit comments

Comments
 (0)