Skip to content

Commit da1a8ef

Browse files
committed
rough beginnings of an ssd1375b driver
1 parent 24a7c80 commit da1a8ef

File tree

1 file changed

+215
-0
lines changed

1 file changed

+215
-0
lines changed

adafruit_epd/ssd1675b.py

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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+
__version__ = "0.0.0-auto.0"
35+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
36+
37+
_SSD1675B_DRIVER_CONTROL = const(0x01)
38+
_SSD1675B_GATE_VOLTAGE = const(0x03)
39+
_SSD1675B_SOURCE_VOLTAGE = const(0x04)
40+
_SSD1675B_INIT_SETTING = const(0x08)
41+
_SSD1675B_INIT_WRITE_REG = const(0x09)
42+
_SSD1675B_INIT_READ_REG = const(0x0A)
43+
_SSD1675B_BOOSTER_SOFT_START = const(0x0C)
44+
_SSD1675B_GATESCAN_START = const(0x0F)
45+
_SSD1675B_DEEP_SLEEP = const(0x10)
46+
_SSD1675B_DATA_MODE = const(0x11)
47+
_SSD1675B_SW_RESET = const(0x12)
48+
_SSD1675B_HV_READY = const(0x14)
49+
_SSD1675B_VCI_READY = const(0x15)
50+
_SSD1675B_TEMP_CONTROL = const(0x18)
51+
_SSD1675B_TEMP_WRITE = const(0x1A)
52+
_SSD1675B_TEMP_READ = const(0x1B)
53+
_SSD1675B_EXTTEMP_WRITE = const(0x1C)
54+
_SSD1675B_MASTER_ACTIVATE = const(0x20)
55+
_SSD1675B_DISP_CTRL1 = const(0x21)
56+
_SSD1675B_DISP_CTRL2 = const(0x22)
57+
_SSD1675B_WRITE_RAM1 = const(0x24)
58+
_SSD1675B_WRITE_RAM2 = const(0x26)
59+
_SSD1675B_READ_RAM = const(0x27)
60+
_SSD1675B_VCOM_SENSE = const(0x28)
61+
_SSD1675B_VCOM_DURATION = const(0x29)
62+
_SSD1675B_WRITE_VCOM_OTP = const(0x2A)
63+
_SSD1675B_WRITE_VCOM_CTRL = const(0x2B)
64+
_SSD1675B_WRITE_VCOM_REG = const(0x2C)
65+
_SSD1675B_READ_OTP = const(0x2D)
66+
_SSD1675B_READ_USERID = const(0x2E)
67+
_SSD1675B_READ_STATUS = const(0x2F)
68+
_SSD1675B_WRITE_WS_OTP = const(0x30)
69+
_SSD1675B_LOAD_WS_OTP = const(0x31)
70+
_SSD1675B_WRITE_LUT = const(0x32)
71+
_SSD1675B_CRC_CALC = const(0x34)
72+
_SSD1675B_CRC_READ = const(0x35)
73+
_SSD1675B_PROG_OTP = const(0x36)
74+
_SSD1675B_WRITE_DISPLAY_OPT = const(0x37)
75+
_SSD1675B_WRITE_USERID = const(0x38)
76+
_SSD1675B_OTP_PROGMODE = const(0x39)
77+
_SSD1675B_WRITE_DUMMY = const(0x3A)
78+
_SSD1675B_WRITE_GATELINE = const(0x3B)
79+
_SSD1675B_WRITE_BORDER = const(0x3C)
80+
_SSD1675B_READ_RAM = const(0x41)
81+
_SSD1675B_SET_RAMXPOS = const(0x44)
82+
_SSD1675B_SET_RAMYPOS = const(0x45)
83+
_SSD1675B_AUTOWRITE_RED = const(0x46)
84+
_SSD1675B_AUTOWRITE_BW = const(0x47)
85+
_SSD1675B_SET_RAMXCOUNT = const(0x4E)
86+
_SSD1675B_SET_RAMYCOUNT = const(0x4F)
87+
_SSD1675B_SET_ANALOGBLOCK = const(0x74)
88+
_SSD1675B_SET_DIGITALBLOCK = const(0x7E)
89+
_SSD1675B_NOP = const(0xFF)
90+
_LUT_DATA = b'\xa0\x90P\x00\x00\x00\x00\x00\x00\x00P\x90\xa0\x00\x00\x00\x00\x00\x00\x00\xa0\x90P\x00\x00\x00\x00\x00\x00\x00P\x90\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x0f\x00\x00\x00\x0f\x0f\x00\x00\x03\x0f\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15A\xa82P,\x0b' # pylint: disable=line-too-long
91+
92+
93+
class Adafruit_SSD1675B(Adafruit_EPD):
94+
"""driver class for Adafruit SSD1675B ePaper display breakouts"""
95+
# pylint: disable=too-many-arguments
96+
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
97+
super(Adafruit_SSD1675B, self).__init__(width, height, spi, cs_pin, dc_pin,
98+
sramcs_pin, rst_pin, busy_pin)
99+
if width % 8 != 0:
100+
width += (8 - width % 8)
101+
102+
self._buffer1_size = int(width * height / 8)
103+
self._buffer2_size = self._buffer1_size
104+
105+
if sramcs_pin:
106+
self._buffer1 = self.sram.get_view(0)
107+
self._buffer2 = self.sram.get_view(self._buffer1_size)
108+
else:
109+
self._buffer1 = bytearray(self._buffer1_size)
110+
self._buffer2 = bytearray(self._buffer2_size)
111+
# since we have *two* framebuffers - one for red and one for black
112+
# we dont subclass but manage manually
113+
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
114+
buf_format=adafruit_framebuf.MHMSB)
115+
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
116+
buf_format=adafruit_framebuf.MHMSB)
117+
self.set_black_buffer(0, True)
118+
self.set_color_buffer(1, True)
119+
# pylint: enable=too-many-arguments
120+
121+
def begin(self, reset=True):
122+
"""Begin communication with the display and set basic settings"""
123+
if reset:
124+
self.hardware_reset()
125+
self.power_down()
126+
127+
def busy_wait(self):
128+
"""Wait for display to be done with current task, either by polling the
129+
busy pin, or pausing"""
130+
if self._busy:
131+
while self._busy.value:
132+
time.sleep(0.01)
133+
else:
134+
time.sleep(0.5)
135+
136+
def power_up(self):
137+
"""Power up the display in preparation for writing RAM and updating"""
138+
self.hardware_reset()
139+
time.sleep(0.1)
140+
self.busy_wait()
141+
142+
self.command(_SSD1675B_SW_RESET)
143+
self.busy_wait()
144+
145+
# set analog block control
146+
self.command(_SSD1675B_SET_ANALOGBLOCK, bytearray([0x54]))
147+
# set digital block control
148+
self.command(_SSD1675B_SET_DIGITALBLOCK, bytearray([0x3B]))
149+
150+
# driver output control
151+
self.command(_SSD1675B_DRIVER_CONTROL,
152+
bytearray([0xF9, 0x00, 0x00]))
153+
154+
# Data entry sequence
155+
self.command(_SSD1675B_DATA_MODE, bytearray([0x01]))
156+
157+
# Set ram X start/end postion
158+
self.command(_SSD1675B_SET_RAMXPOS, bytearray([0x00, 0x0F]))
159+
# Set ram Y start/end postion
160+
self.command(_SSD1675B_SET_RAMYPOS, bytearray([0xF9, 0x0, 0x0, 0x0]))
161+
162+
# Border color
163+
self.command(_SSD1675B_WRITE_BORDER, bytearray([0x01]))
164+
165+
# Vcom Voltage
166+
self.command(_SSD1675B_WRITE_VCOM_REG, bytearray([0x50]))
167+
# Set gate voltage
168+
self.command(_SSD1675B_GATE_VOLTAGE, _LUT_DATA[100:101])
169+
# Set source voltage
170+
self.command(_SSD1675B_SOURCE_VOLTAGE, _LUT_DATA[101:104])
171+
# Set dummy line period
172+
self.command(_SSD1675B_WRITE_DUMMY, _LUT_DATA[105:106])
173+
# Set gate line width
174+
self.command(_SSD1675B_WRITE_GATELINE, _LUT_DATA[106:107])
175+
# LUT
176+
self.command(_SSD1675B_WRITE_LUT, _LUT_DATA[0:100])
177+
178+
# Set temperature control
179+
#self.command(_SSD1675B_TEMP_CONTROL, bytearray([0x80]))
180+
181+
# Set RAM X address counter
182+
self.command(_SSD1675B_SET_RAMXCOUNT, bytearray([0]))
183+
# Set RAM Y address counter
184+
self.command(_SSD1675B_SET_RAMYCOUNT, bytearray([0xF9, 0]))
185+
186+
self.busy_wait()
187+
188+
def power_down(self):
189+
"""Power down the display - required when not actively displaying!"""
190+
self.command(_SSD1675B_DEEP_SLEEP, bytearray([0x01]))
191+
time.sleep(0.1)
192+
193+
def update(self):
194+
"""Update the display from internal memory"""
195+
self.command(_SSD1675B_DISP_CTRL2, bytearray([0xFF]))
196+
self.command(_SSD1675B_MASTER_ACTIVATE)
197+
self.busy_wait()
198+
if not self._busy:
199+
time.sleep(3) # wait 3 seconds
200+
201+
def write_ram(self, index):
202+
"""Send the one byte command for starting the RAM write process. Returns
203+
the byte read at the same time over SPI. index is the RAM buffer, can be
204+
0 or 1 for tri-color displays."""
205+
if index == 0:
206+
return self.command(_SSD1675B_WRITE_RAM1, end=False)
207+
if index == 1:
208+
return self.command(_SSD1675B_WRITE_RAM2, end=False)
209+
raise RuntimeError("RAM index must be 0 or 1")
210+
211+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
212+
"""Set the RAM address location, not used on this chipset but required by
213+
the superclass"""
214+
self.command(_SSD1675B_SET_RAMXCOUNT, bytearray([x]))
215+
self.command(_SSD1675B_SET_RAMYCOUNT, bytearray([y, y>>8]))

0 commit comments

Comments
 (0)