Skip to content

Commit 8209cb7

Browse files
committed
Copy ssd1680.py -> ssd1680b.py with updated constants and docstrings
- no logic changes from the vanilla SSD1680 driver -- will be applied in the next commit for diff clarity - update copyright/author sections - remove unnecessary pylint directives
1 parent 47837b6 commit 8209cb7

File tree

1 file changed

+217
-0
lines changed

1 file changed

+217
-0
lines changed

adafruit_epd/ssd1680b.py

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2024 Joel Miller for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
"""
7+
`adafruit_epd.ssd1680b` - Adafruit SSD1680B - ePaper display driver
8+
====================================================================================
9+
CircuitPython driver for Adafruit SSD1680B displays (GDEY0213B74 display module)
10+
* Author(s): Melissa LeBlanc-Williams, Joel Miller
11+
"""
12+
13+
import time
14+
from micropython import const
15+
import adafruit_framebuf
16+
from adafruit_epd.epd import Adafruit_EPD
17+
18+
try:
19+
"""Needed for type annotations"""
20+
# pylint: disable=unused-import
21+
import typing
22+
from typing_extensions import Literal
23+
from busio import SPI
24+
from digitalio import DigitalInOut
25+
except ImportError:
26+
pass
27+
28+
__version__ = "0.0.0+auto.0"
29+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
30+
31+
_SSD1680B_DRIVER_CONTROL = const(0x01)
32+
_SSD1680B_GATE_VOLTAGE = const(0x03)
33+
_SSD1680B_SOURCE_VOLTAGE = const(0x04)
34+
_SSD1680B_INIT_SETTING = const(0x08)
35+
_SSD1680B_INIT_WRITE_REG = const(0x09)
36+
_SSD1680B_INIT_READ_REG = const(0x0A)
37+
_SSD1680B_BOOSTER_SOFT_START = const(0x0C)
38+
_SSD1680B_DEEP_SLEEP = const(0x10)
39+
_SSD1680B_DATA_MODE = const(0x11)
40+
_SSD1680B_SW_RESET = const(0x12)
41+
_SSD1680B_HV_DETECT = const(0x14)
42+
_SSD1680B_VCI_DETECT = const(0x15)
43+
_SSD1680B_TEMP_CONTROL = const(0x18)
44+
_SSD1680B_TEMP_WRITE = const(0x1A)
45+
_SSD1680B_TEMP_READ = const(0x1B)
46+
_SSD1680B_EXTTEMP_WRITE = const(0x1C)
47+
_SSD1680B_MASTER_ACTIVATE = const(0x20)
48+
_SSD1680B_DISP_CTRL1 = const(0x21)
49+
_SSD1680B_DISP_CTRL2 = const(0x22)
50+
_SSD1680B_WRITE_BWRAM = const(0x24)
51+
_SSD1680B_WRITE_REDRAM = const(0x26)
52+
_SSD1680B_READ_RAM = const(0x27)
53+
_SSD1680B_VCOM_SENSE = const(0x28)
54+
_SSD1680B_VCOM_DURATION = const(0x29)
55+
_SSD1680B_WRITE_VCOM_OTP = const(0x2A)
56+
_SSD1680B_WRITE_VCOM_CTRL = const(0x2B)
57+
_SSD1680B_WRITE_VCOM_REG = const(0x2C)
58+
_SSD1680B_READ_OTP = const(0x2D)
59+
_SSD1680B_READ_USERID = const(0x2E)
60+
_SSD1680B_READ_STATUS = const(0x2F)
61+
_SSD1680B_WRITE_WS_OTP = const(0x30)
62+
_SSD1680B_LOAD_WS_OTP = const(0x31)
63+
_SSD1680B_WRITE_LUT = const(0x32)
64+
_SSD1680B_CRC_CALC = const(0x34)
65+
_SSD1680B_CRC_READ = const(0x35)
66+
_SSD1680B_PROG_OTP = const(0x36)
67+
_SSD1680B_WRITE_DISPLAY_OPT = const(0x37)
68+
_SSD1680B_WRITE_USERID = const(0x38)
69+
_SSD1680B_OTP_PROGMODE = const(0x39)
70+
_SSD1680B_WRITE_BORDER = const(0x3C)
71+
_SSD1680B_END_OPTION = const(0x3F)
72+
_SSD1680B_SET_RAMXPOS = const(0x44)
73+
_SSD1680B_SET_RAMYPOS = const(0x45)
74+
_SSD1680B_AUTOWRITE_RED = const(0x46)
75+
_SSD1680B_AUTOWRITE_BW = const(0x47)
76+
_SSD1680B_SET_RAMXCOUNT = const(0x4E)
77+
_SSD1680B_SET_RAMYCOUNT = const(0x4F)
78+
_SSD1680B_NOP = const(0xFF)
79+
80+
81+
class Adafruit_SSD1680B(Adafruit_EPD):
82+
"""
83+
Driver class for Adafruit SSD1680 "B" ePaper displays. This class is meant
84+
to be used with Adafruit boards equipped with an SSD1680 driver chip paired
85+
with a GDEY0213B74 display module.
86+
"""
87+
88+
def __init__(
89+
self,
90+
width: int,
91+
height: int,
92+
spi: SPI,
93+
*,
94+
cs_pin: DigitalInOut,
95+
dc_pin: DigitalInOut,
96+
sramcs_pin: DigitalInOut,
97+
rst_pin: DigitalInOut,
98+
busy_pin: DigitalInOut,
99+
) -> None:
100+
super().__init__(
101+
width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
102+
)
103+
104+
stride = width
105+
if stride % 8 != 0:
106+
stride += 8 - stride % 8
107+
108+
self._buffer1_size = int(stride * height / 8)
109+
self._buffer2_size = self._buffer1_size
110+
111+
if sramcs_pin:
112+
self._buffer1 = self.sram.get_view(0)
113+
self._buffer2 = self.sram.get_view(self._buffer1_size)
114+
else:
115+
self._buffer1 = bytearray(self._buffer1_size)
116+
self._buffer2 = bytearray(self._buffer2_size)
117+
118+
self._framebuf1 = adafruit_framebuf.FrameBuffer(
119+
self._buffer1,
120+
width,
121+
height,
122+
stride=stride,
123+
buf_format=adafruit_framebuf.MHMSB,
124+
)
125+
self._framebuf2 = adafruit_framebuf.FrameBuffer(
126+
self._buffer2,
127+
width,
128+
height,
129+
stride=stride,
130+
buf_format=adafruit_framebuf.MHMSB,
131+
)
132+
self.set_black_buffer(0, True)
133+
self.set_color_buffer(1, False)
134+
135+
def begin(self, reset: bool = True) -> None:
136+
"""Begin communication with the display and set basic settings"""
137+
if reset:
138+
self.hardware_reset()
139+
self.power_down()
140+
141+
def busy_wait(self) -> None:
142+
"""
143+
Wait for display to be done with current task, either by polling the
144+
busy pin, or pausing
145+
"""
146+
if self._busy:
147+
while self._busy.value:
148+
time.sleep(0.01)
149+
else:
150+
time.sleep(0.5)
151+
152+
def power_up(self) -> None:
153+
"""Power up the display in preparation for writing RAM and updating"""
154+
self.hardware_reset()
155+
self.busy_wait()
156+
self.command(_SSD1680B_SW_RESET)
157+
self.busy_wait()
158+
# driver output control
159+
self.command(
160+
_SSD1680B_DRIVER_CONTROL,
161+
bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]),
162+
)
163+
# data entry mode
164+
self.command(_SSD1680B_DATA_MODE, bytearray([0x03]))
165+
166+
# Set voltages
167+
self.command(_SSD1680B_WRITE_VCOM_REG, bytearray([0x36]))
168+
self.command(_SSD1680B_GATE_VOLTAGE, bytearray([0x17]))
169+
self.command(_SSD1680B_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32]))
170+
171+
# Set ram X start/end postion
172+
self.command(_SSD1680B_SET_RAMXPOS, bytearray([0x01, 0x10]))
173+
# Set ram Y start/end postion
174+
self.command(
175+
_SSD1680B_SET_RAMYPOS,
176+
bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]),
177+
)
178+
# Set border waveform
179+
self.command(_SSD1680B_WRITE_BORDER, bytearray([0x05]))
180+
181+
# Set ram X count
182+
self.command(_SSD1680B_SET_RAMXCOUNT, bytearray([0x01]))
183+
# Set ram Y count
184+
self.command(_SSD1680B_SET_RAMYCOUNT, bytearray([self._height - 1, 0]))
185+
self.busy_wait()
186+
187+
def power_down(self) -> None:
188+
"""Power down the display - required when not actively displaying!"""
189+
self.command(_SSD1680B_DEEP_SLEEP, bytearray([0x01]))
190+
time.sleep(0.1)
191+
192+
def update(self) -> None:
193+
"""Update the display from internal memory"""
194+
self.command(_SSD1680B_DISP_CTRL2, bytearray([0xF4]))
195+
self.command(_SSD1680B_MASTER_ACTIVATE)
196+
self.busy_wait()
197+
if not self._busy:
198+
time.sleep(3) # wait 3 seconds
199+
200+
def write_ram(self, index: Literal[0, 1]) -> int:
201+
"""
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
204+
be 0 or 1 for tri-color displays.
205+
"""
206+
if index == 0:
207+
return self.command(_SSD1680B_WRITE_BWRAM, end=False)
208+
if index == 1:
209+
return self.command(_SSD1680B_WRITE_REDRAM, end=False)
210+
raise RuntimeError("RAM index must be 0 or 1")
211+
212+
def set_ram_address(self, x: int, y: int) -> None:
213+
"""Set the RAM address location"""
214+
# Set RAM X address counter
215+
self.command(_SSD1680B_SET_RAMXCOUNT, bytearray([x + 1]))
216+
# Set RAM Y address counter
217+
self.command(_SSD1680B_SET_RAMYCOUNT, bytearray([y, y >> 8]))

0 commit comments

Comments
 (0)