Skip to content

Commit df3b5e0

Browse files
committed
initial add of SSD1308
1 parent 51fdef1 commit df3b5e0

File tree

2 files changed

+175
-16
lines changed

2 files changed

+175
-16
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: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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'
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, bytearray([self._width-1, (self._width-1) >> 8, 0x00]))
114+
# Set dummy line period
115+
self.command(_SSD1608_WRITE_DUMMY, bytearray([0x1B]))
116+
# Set gate line width
117+
self.command(_SSD1608_WRITE_GATELINE, bytearray([0x0B]))
118+
# Data entry sequence
119+
self.command(_SSD1608_DATA_MODE, bytearray([0x03]))
120+
# Set ram X start/end postion
121+
self.command(_SSD1608_SET_RAMXPOS, bytearray([0x00, self._height//8 - 1]))
122+
# Set ram Y start/end postion
123+
self.command(_SSD1608_SET_RAMYPOS, bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]))
124+
# Vcom Voltage
125+
self.command(_SSD1608_WRITE_VCOM, bytearray([0x70]))
126+
# LUT
127+
self.command(_SSD1608_WRITE_LUT, _LUT_DATA)
128+
self.busy_wait()
129+
130+
def power_down(self):
131+
"""Power down the display - required when not actively displaying!"""
132+
self.command(_SSD1608_DEEP_SLEEP, bytearray([0x01]))
133+
time.sleep(0.1)
134+
135+
def update(self):
136+
"""Update the display from internal memory"""
137+
self.command(_SSD1608_DISP_CTRL2, bytearray([0xC7]))
138+
self.command(_SSD1608_MASTER_ACTIVATE)
139+
self.busy_wait()
140+
if not self._busy:
141+
time.sleep(3) # wait 3 seconds
142+
143+
def write_ram(self, index):
144+
"""Send the one byte command for starting the RAM write process. Returns
145+
the byte read at the same time over SPI. index is the RAM buffer, can be
146+
0 or 1 for tri-color displays."""
147+
if index == 0:
148+
return self.command(_SSD1608_WRITE_RAM, end=False)
149+
raise RuntimeError("RAM index must be 0")
150+
151+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
152+
"""Set the RAM address location, not used on this chipset but required by
153+
the superclass"""
154+
# Set RAM X address counter
155+
self.command(_SSD1608_SET_RAMXCOUNT, bytearray([x]))
156+
# Set RAM Y address counter
157+
self.command(_SSD1608_SET_RAMYCOUNT, bytearray([y>>8, y]))

0 commit comments

Comments
 (0)