Skip to content

Commit 1598e48

Browse files
authored
Merge pull request #10 from ladyada/master
Add two more chipsets - SSD1675 and SSD1608
2 parents c974cec + 83abd0a commit 1598e48

File tree

5 files changed

+397
-39
lines changed

5 files changed

+397
-39
lines changed

adafruit_epd/epd.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,25 @@ def display(self): # pylint: disable=too-many-branches
133133
self.spi_device.write(self._buf, end=3)
134134
self.spi_device.unlock()
135135

136-
#first data byte from SRAM will be transfered in at the
137-
#same time as the EPD command is transferred out
138-
databyte = self.write_ram(1)
136+
if self._buffer2_size != 0:
137+
#first data byte from SRAM will be transfered in at the
138+
#same time as the EPD command is transferred out
139+
databyte = self.write_ram(1)
139140

140-
while not self.spi_device.try_lock():
141-
pass
142-
self._dc.value = True
141+
while not self.spi_device.try_lock():
142+
pass
143+
self._dc.value = True
143144

144-
if self.sram:
145-
for _ in range(self._buffer2_size):
146-
databyte = self._spi_transfer(databyte)
147-
self.sram.cs_pin.value = True
148-
else:
149-
for databyte in self._buffer2:
150-
self._spi_transfer(databyte)
145+
if self.sram:
146+
for _ in range(self._buffer2_size):
147+
databyte = self._spi_transfer(databyte)
148+
self.sram.cs_pin.value = True
149+
else:
150+
for databyte in self._buffer2:
151+
self._spi_transfer(databyte)
151152

152-
self._cs.value = True
153-
self.spi_device.unlock()
153+
self._cs.value = True
154+
self.spi_device.unlock()
154155
self.update()
155156

156157

@@ -305,7 +306,8 @@ def rotation(self):
305306
@rotation.setter
306307
def rotation(self, val):
307308
self._framebuf1.rotation = val
308-
self._framebuf2.rotation = val
309+
if self._framebuf2:
310+
self._framebuf2.rotation = val
309311

310312
def hline(self, x, y, width, color):
311313
"""draw a horizontal line"""

adafruit_epd/ssd1608.py

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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.ssd1608` - Adafruit SSD1608 - ePaper display driver
24+
====================================================================================
25+
CircuitPython driver for Adafruit SSD1608 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+
_SSD1608_DRIVER_CONTROL = const(0x01)
35+
_SSD1608_GATE_VOLTAGE = const(0x03)
36+
_SSD1608_SOURCE_VOLTAGE = const(0x04)
37+
_SSD1608_DISPLAY_CONTROL = const(0x07)
38+
_SSD1608_NON_OVERLAP = const(0x0B)
39+
_SSD1608_BOOSTER_SOFT_START = const(0x0C)
40+
_SSD1608_GATE_SCAN_START = const(0x0F)
41+
_SSD1608_DEEP_SLEEP = const(0x10)
42+
_SSD1608_DATA_MODE = const(0x11)
43+
_SSD1608_SW_RESET = const(0x12)
44+
_SSD1608_TEMP_WRITE = const(0x1A)
45+
_SSD1608_TEMP_READ = const(0x1B)
46+
_SSD1608_TEMP_CONTROL = const(0x1C)
47+
_SSD1608_TEMP_LOAD = const(0x1D)
48+
_SSD1608_MASTER_ACTIVATE = const(0x20)
49+
_SSD1608_DISP_CTRL1 = const(0x21)
50+
_SSD1608_DISP_CTRL2 = const(0x22)
51+
_SSD1608_WRITE_RAM = const(0x24)
52+
_SSD1608_READ_RAM = const(0x25)
53+
_SSD1608_VCOM_SENSE = const(0x28)
54+
_SSD1608_VCOM_DURATION = const(0x29)
55+
_SSD1608_WRITE_VCOM = const(0x2C)
56+
_SSD1608_READ_OTP = const(0x2D)
57+
_SSD1608_WRITE_LUT = const(0x32)
58+
_SSD1608_WRITE_DUMMY = const(0x3A)
59+
_SSD1608_WRITE_GATELINE = const(0x3B)
60+
_SSD1608_WRITE_BORDER = const(0x3C)
61+
_SSD1608_SET_RAMXPOS = const(0x44)
62+
_SSD1608_SET_RAMYPOS = const(0x45)
63+
_SSD1608_SET_RAMXCOUNT = const(0x4E)
64+
_SSD1608_SET_RAMYCOUNT = const(0x4F)
65+
_SSD1608_NOP = const(0xFF)
66+
_LUT_DATA = b'\x02\x02\x01\x11\x12\x12""fiiYX\x99\x99\x88\x00\x00\x00\x00\xf8\xb4\x13Q5QQ\x19\x01\x00' # pylint: disable=line-too-long
67+
68+
class Adafruit_SSD1608(Adafruit_EPD):
69+
"""driver class for Adafruit SSD1608 ePaper display breakouts"""
70+
# pylint: disable=too-many-arguments
71+
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
72+
super(Adafruit_SSD1608, self).__init__(width, height, spi, cs_pin, dc_pin,
73+
sramcs_pin, rst_pin, busy_pin)
74+
75+
if height % 8 != 0:
76+
height += (8 - height % 8)
77+
self._height = height
78+
79+
self._buffer1_size = int(width * height / 8)
80+
81+
if sramcs_pin:
82+
self._buffer1 = self.sram.get_view(0)
83+
else:
84+
self._buffer1 = bytearray((width * height) // 8)
85+
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
86+
buf_format=adafruit_framebuf.MHMSB)
87+
self.set_black_buffer(0, True)
88+
self.set_color_buffer(0, True)
89+
# pylint: enable=too-many-arguments
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+
self.power_down()
96+
97+
def busy_wait(self):
98+
"""Wait for display to be done with current task, either by polling the
99+
busy pin, or pausing"""
100+
if self._busy:
101+
while self._busy.value:
102+
time.sleep(0.01)
103+
else:
104+
time.sleep(0.5)
105+
106+
def power_up(self):
107+
"""Power up the display in preparation for writing RAM and updating"""
108+
self.hardware_reset()
109+
self.busy_wait()
110+
self.command(_SSD1608_SW_RESET)
111+
self.busy_wait()
112+
# driver output control
113+
self.command(_SSD1608_DRIVER_CONTROL,
114+
bytearray([self._width-1, (self._width-1) >> 8, 0x00]))
115+
# Set dummy line period
116+
self.command(_SSD1608_WRITE_DUMMY, bytearray([0x1B]))
117+
# Set gate line width
118+
self.command(_SSD1608_WRITE_GATELINE, bytearray([0x0B]))
119+
# Data entry sequence
120+
self.command(_SSD1608_DATA_MODE, bytearray([0x03]))
121+
# Set ram X start/end postion
122+
self.command(_SSD1608_SET_RAMXPOS, bytearray([0x00, self._height//8 - 1]))
123+
# Set ram Y start/end postion
124+
self.command(_SSD1608_SET_RAMYPOS,
125+
bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]))
126+
# Vcom Voltage
127+
self.command(_SSD1608_WRITE_VCOM, bytearray([0x70]))
128+
# LUT
129+
self.command(_SSD1608_WRITE_LUT, _LUT_DATA)
130+
self.busy_wait()
131+
132+
def power_down(self):
133+
"""Power down the display - required when not actively displaying!"""
134+
self.command(_SSD1608_DEEP_SLEEP, bytearray([0x01]))
135+
time.sleep(0.1)
136+
137+
def update(self):
138+
"""Update the display from internal memory"""
139+
self.command(_SSD1608_DISP_CTRL2, bytearray([0xC7]))
140+
self.command(_SSD1608_MASTER_ACTIVATE)
141+
self.busy_wait()
142+
if not self._busy:
143+
time.sleep(3) # wait 3 seconds
144+
145+
def write_ram(self, index):
146+
"""Send the one byte command for starting the RAM write process. Returns
147+
the byte read at the same time over SPI. index is the RAM buffer, can be
148+
0 or 1 for tri-color displays."""
149+
if index == 0:
150+
return self.command(_SSD1608_WRITE_RAM, end=False)
151+
raise RuntimeError("RAM index must be 0")
152+
153+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
154+
"""Set the RAM address location, not used on this chipset but required by
155+
the superclass"""
156+
# Set RAM X address counter
157+
self.command(_SSD1608_SET_RAMXCOUNT, bytearray([x]))
158+
# Set RAM Y address counter
159+
self.command(_SSD1608_SET_RAMYCOUNT, bytearray([y>>8, y]))

adafruit_epd/ssd1675.py

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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.ssd1675` - Adafruit SSD1675 - ePaper display driver
24+
====================================================================================
25+
CircuitPython driver for Adafruit SSD1675 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+
_SSD1675_DRIVER_CONTROL = const(0x01)
35+
_SSD1675_GATE_VOLTAGE = const(0x03)
36+
_SSD1675_SOURCE_VOLTAGE = const(0x04)
37+
_SSD1675_DEEP_SLEEP = const(0x10)
38+
_SSD1675_DATA_MODE = const(0x11)
39+
_SSD1675_SW_RESET = const(0x12)
40+
_SSD1675_HV_READY = const(0x14)
41+
_SSD1675_VCI_READY = const(0x15)
42+
_SSD1675_TEMP_WRITE = const(0x1A)
43+
_SSD1675_MASTER_ACTIVATE = const(0x20)
44+
_SSD1675_DISP_CTRL1 = const(0x21)
45+
_SSD1675_DISP_CTRL2 = const(0x22)
46+
_SSD1675_WRITE_RAM1 = const(0x24)
47+
_SSD1675_WRITE_RAM2 = const(0x26)
48+
_SSD1675_WRITE_VCOM = const(0x2C)
49+
_SSD1675_READ_OTP = const(0x2D)
50+
_SSD1675_WRITE_LUT = const(0x32)
51+
_SSD1675_WRITE_DUMMY = const(0x3A)
52+
_SSD1675_WRITE_GATELINE = const(0x3B)
53+
_SSD1675_WRITE_BORDER = const(0x3C)
54+
_SSD1675_SET_RAMXPOS = const(0x44)
55+
_SSD1675_SET_RAMYPOS = const(0x45)
56+
_SSD1675_SET_RAMXCOUNT = const(0x4E)
57+
_SSD1675_SET_RAMYCOUNT = const(0x4F)
58+
_SSD1675_SET_ANALOGBLOCK = const(0x74)
59+
_SSD1675_SET_DIGITALBLOCK = const(0x7E)
60+
_LUT_DATA = b'\x80`@\x00\x00\x00\x00\x10` \x00\x00\x00\x00\x80`@\x00\x00\x00\x00\x10` \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x03\x00\x00\x02\t\t\x00\x00\x02\x03\x03\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15A\xa820\n' # pylint: disable=line-too-long
61+
62+
class Adafruit_SSD1675(Adafruit_EPD):
63+
"""driver class for Adafruit SSD1675 ePaper display breakouts"""
64+
# pylint: disable=too-many-arguments
65+
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
66+
super(Adafruit_SSD1675, self).__init__(width, height, spi, cs_pin, dc_pin,
67+
sramcs_pin, rst_pin, busy_pin)
68+
if width % 8 != 0:
69+
width += (8 - width % 8)
70+
71+
self._buffer1_size = int(width * height / 8)
72+
self._buffer2_size = self._buffer1_size
73+
74+
if sramcs_pin:
75+
self._buffer1 = self.sram.get_view(0)
76+
self._buffer2 = self.sram.get_view(self._buffer1_size)
77+
else:
78+
self._buffer1 = bytearray(self._buffer1_size)
79+
self._buffer2 = bytearray(self._buffer2_size)
80+
# since we have *two* framebuffers - one for red and one for black
81+
# we dont subclass but manage manually
82+
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
83+
buf_format=adafruit_framebuf.MHMSB)
84+
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
85+
buf_format=adafruit_framebuf.MHMSB)
86+
self.set_black_buffer(0, True)
87+
self.set_color_buffer(0, True)
88+
# pylint: enable=too-many-arguments
89+
90+
def begin(self, reset=True):
91+
"""Begin communication with the display and set basic settings"""
92+
if reset:
93+
self.hardware_reset()
94+
self.power_down()
95+
96+
def busy_wait(self):
97+
"""Wait for display to be done with current task, either by polling the
98+
busy pin, or pausing"""
99+
if self._busy:
100+
while self._busy.value:
101+
time.sleep(0.01)
102+
else:
103+
time.sleep(0.5)
104+
105+
def power_up(self):
106+
"""Power up the display in preparation for writing RAM and updating"""
107+
self.hardware_reset()
108+
time.sleep(0.1)
109+
self.busy_wait()
110+
111+
self.command(_SSD1675_SW_RESET)
112+
self.busy_wait()
113+
114+
# set analog block control
115+
self.command(_SSD1675_SET_ANALOGBLOCK, bytearray([0x54]))
116+
# set digital block control
117+
self.command(_SSD1675_SET_DIGITALBLOCK, bytearray([0x3B]))
118+
119+
# driver output control
120+
self.command(_SSD1675_DRIVER_CONTROL,
121+
bytearray([0xFA, 0x01, 0x00]))
122+
# Data entry sequence
123+
self.command(_SSD1675_DATA_MODE, bytearray([0x03]))
124+
# Set ram X start/end postion
125+
self.command(_SSD1675_SET_RAMXPOS, bytearray([0x00, 0x0F]))
126+
# Set ram Y start/end postion
127+
self.command(_SSD1675_SET_RAMYPOS, bytearray([0, 0, 0xF9, 0]))
128+
# Border color
129+
self.command(_SSD1675_WRITE_BORDER, bytearray([0x03]))
130+
# Vcom Voltage
131+
self.command(_SSD1675_WRITE_VCOM, bytearray([0x70]))
132+
# Set gate voltage
133+
self.command(_SSD1675_GATE_VOLTAGE, _LUT_DATA[70:71])
134+
# Set gate voltage
135+
self.command(_SSD1675_SOURCE_VOLTAGE, _LUT_DATA[71:74])
136+
# Set dummy line period
137+
self.command(_SSD1675_WRITE_DUMMY, _LUT_DATA[74:75])
138+
# Set gate line width
139+
self.command(_SSD1675_WRITE_GATELINE, _LUT_DATA[75:76])
140+
# LUT
141+
self.command(_SSD1675_WRITE_LUT, _LUT_DATA[0:70])
142+
143+
self.command(_SSD1675_SET_RAMXCOUNT, bytearray([0]))
144+
# Set RAM Y address counter
145+
self.command(_SSD1675_SET_RAMYCOUNT, bytearray([0xF9, 0]))
146+
147+
self.busy_wait()
148+
149+
def power_down(self):
150+
"""Power down the display - required when not actively displaying!"""
151+
self.command(_SSD1675_DEEP_SLEEP, bytearray([0x01]))
152+
time.sleep(0.1)
153+
154+
def update(self):
155+
"""Update the display from internal memory"""
156+
self.command(_SSD1675_DISP_CTRL2, bytearray([0xC7]))
157+
self.command(_SSD1675_MASTER_ACTIVATE)
158+
self.busy_wait()
159+
if not self._busy:
160+
time.sleep(3) # wait 3 seconds
161+
162+
def write_ram(self, index):
163+
"""Send the one byte command for starting the RAM write process. Returns
164+
the byte read at the same time over SPI. index is the RAM buffer, can be
165+
0 or 1 for tri-color displays."""
166+
if index == 0:
167+
return self.command(_SSD1675_WRITE_RAM1, end=False)
168+
if index == 1:
169+
return self.command(_SSD1675_WRITE_RAM2, end=False)
170+
raise RuntimeError("RAM index must be 0 or 1")
171+
172+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
173+
"""Set the RAM address location, not used on this chipset but required by
174+
the superclass"""
175+
self.command(_SSD1675_SET_RAMXCOUNT, bytearray([x]))
176+
self.command(_SSD1675_SET_RAMYCOUNT, bytearray([y, y>>8]))

0 commit comments

Comments
 (0)