Skip to content

Commit 2696ca5

Browse files
committed
Tested
1 parent 3234a71 commit 2696ca5

File tree

2 files changed

+172
-12
lines changed

2 files changed

+172
-12
lines changed

adafruit_jd79661.py

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
`adafruit_jd79661`
77
================================================================================
88
9-
CircuitPython library for the JD79661 e-paper driver IC
9+
CircuitPython `displayio` driver for JD79661-based ePaper displays
1010
1111
1212
* Author(s): Scott Shawcroft
@@ -16,22 +16,124 @@
1616
1717
**Hardware:**
1818
19-
.. todo:: Add links to any specific hardware product page(s), or category page(s).
20-
Use unordered list & hyperlink rST inline format: "* `Link Text <url>`_"
19+
* JD79661-based 4-color ePaper displays (128x250 resolution) - Black, White, Red, Yellow
2120
2221
**Software and Dependencies:**
2322
2423
* Adafruit CircuitPython firmware for the supported boards:
25-
https://circuitpython.org/downloads
24+
https://github.com/adafruit/circuitpython/releases
2625
27-
.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies
28-
based on the library's use of either.
29-
30-
# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
31-
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
3226
"""
3327

34-
# imports
28+
from epaperdisplay import EPaperDisplay
29+
30+
try:
31+
import typing
32+
33+
from fourwire import FourWire
34+
except ImportError:
35+
pass
36+
3537

3638
__version__ = "0.0.0+auto.0"
3739
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_JD79661.git"
40+
41+
# JD79661 Command definitions
42+
_JD79661_PANEL_SETTING = 0x00
43+
_JD79661_POWER_SETTING = 0x01
44+
_JD79661_POWER_OFF = 0x02
45+
_JD79661_POWER_ON = 0x04
46+
_JD79661_BOOSTER_SOFTSTART = 0x06
47+
_JD79661_DEEP_SLEEP = 0x07
48+
_JD79661_DATA_START_XMIT = 0x10
49+
_JD79661_DISPLAY_REFRESH = 0x12
50+
_JD79661_CDI = 0x50
51+
_JD79661_PLL_CONTROL = 0x60
52+
_JD79661_RESOLUTION = 0x61
53+
54+
_START_SEQUENCE = (
55+
b"\x4d\x01\x78" # Set register 0x4D to 0x78
56+
b"\x00\x02\x8f\x29" # Panel setting (128x250 resolution)
57+
b"\x01\x02\x07\x00" # Power setting
58+
b"\x03\x03\x10\x54\x44" # Power offset
59+
b"\x06\x07\x05\x00\x3F\x0A\x25\x12\x1A" # Booster soft start
60+
b"\x50\x01\x37" # CDI
61+
b"\x60\x02\x02\x02" # TCON
62+
b"\x61\x04\x00\x80\x00\xfa" # Resolution (0, 128, 0, 250)
63+
b"\xe7\x01\x1c" # Additional config register
64+
b"\xe3\x01\x22" # Additional config register
65+
b"\xb4\x01\xd0" # Additional config register
66+
b"\xb5\x01\x03" # Additional config register
67+
b"\xe9\x01\x01" # Additional config register
68+
b"\x30\x01\x08" # PLL Control
69+
b"\x04\x00" # Power on and wait
70+
)
71+
72+
_STOP_SEQUENCE = (
73+
b"\x02\x80\x00" # Power off and wait
74+
b"\x07\x01\xa5" # Deep sleep
75+
)
76+
77+
_REFRESH_SEQUENCE = (
78+
b"\x12\x01\x00" # Display refresh
79+
)
80+
81+
# pylint: disable=too-few-public-methods
82+
class JD79661(EPaperDisplay):
83+
r"""JD79661 driver
84+
85+
:param bus: The data bus the display is on
86+
:param \**kwargs:
87+
See below
88+
89+
:Keyword Arguments:
90+
* *width* (``int``) --
91+
Display width
92+
* *height* (``int``) --
93+
Display height
94+
* *rotation* (``int``) --
95+
Display rotation
96+
"""
97+
98+
def __init__(self, bus: FourWire, **kwargs) -> None:
99+
stop_sequence = bytearray(_STOP_SEQUENCE)
100+
try:
101+
bus.reset()
102+
except RuntimeError:
103+
# No reset pin defined, so no deep sleeping
104+
stop_sequence = b""
105+
106+
start_sequence = bytearray(_START_SEQUENCE )
107+
108+
width = kwargs.get("width", 128)
109+
height = kwargs.get("height", 250)
110+
if "rotation" in kwargs and kwargs["rotation"] % 180 != 90:
111+
width, height = height, width
112+
113+
# Update resolution in start sequence (bytes at position for resolution command)
114+
# Find the resolution command in the sequence and update it
115+
res_pos = start_sequence.find(b'\x61\x04')
116+
if res_pos != -1:
117+
if height % 4 != 0:
118+
height += 4 - height % 4
119+
start_sequence[res_pos + 2] = (height >> 8) & 0xFF
120+
start_sequence[res_pos + 3] = height & 0xFF
121+
start_sequence[res_pos + 4] = (width >> 8) & 0xFF
122+
start_sequence[res_pos + 5] = width & 0xFF
123+
124+
print(start_sequence.hex(" "))
125+
126+
super().__init__(
127+
bus,
128+
start_sequence,
129+
stop_sequence,
130+
**kwargs,
131+
ram_width=128,
132+
ram_height=250,
133+
busy_state=False,
134+
write_black_ram_command=_JD79661_DATA_START_XMIT,
135+
write_color_ram_command=None, # JD79661 uses single RAM with 2-bit pixels
136+
refresh_display_command=_REFRESH_SEQUENCE,
137+
always_toggle_chip_select=True,
138+
address_little_endian=False
139+
)

examples/jd79661_simpletest.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2-
# SPDX-FileCopyrightText: Copyright (c) 2025 Scott Shawcroft for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2025 Scott Shawcroft, written for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries
33
#
44
# SPDX-License-Identifier: Unlicense
5+
6+
"""Simple test script for 2.9" 296x128 display. This example runs it in mono mode."""
7+
8+
import time
9+
10+
import board
11+
import busio
12+
import displayio
13+
from fourwire import FourWire
14+
15+
import adafruit_jd79661
16+
17+
displayio.release_displays()
18+
19+
# This pinout works on a MagTag with the newer screen and may need to be altered for other boards.
20+
spi = busio.SPI(board.EPD_SCK, board.EPD_MOSI) # Uses SCK and MOSI
21+
epd_cs = board.EPD_CS
22+
epd_dc = board.EPD_DC
23+
epd_reset = board.EPD_RESET
24+
epd_busy = board.EPD_BUSY
25+
26+
display_bus = FourWire(spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000)
27+
time.sleep(1)
28+
29+
display = adafruit_jd79661.JD79661(
30+
display_bus,
31+
width=250,
32+
height=122,
33+
busy_pin=epd_busy,
34+
rotation=270,
35+
colstart=0,
36+
highlight_color=0x00FF00,
37+
highlight_color2=0xFF0000,
38+
)
39+
40+
g = displayio.Group()
41+
42+
pic = displayio.OnDiskBitmap("/display-ruler-640x360.bmp")
43+
t = displayio.TileGrid(pic, pixel_shader=pic.pixel_shader)
44+
g.append(t)
45+
46+
display.root_group = g
47+
48+
display.refresh()
49+
50+
print("refreshed")
51+
52+
time.sleep(display.time_to_refresh + 5)
53+
# Always refresh a little longer. It's not a problem to refresh
54+
# a few seconds more, but it's terrible to refresh too early
55+
# (the display will throw an exception when if the refresh
56+
# is too soon)
57+
print("waited correct time")
58+
59+
60+
# Keep the display the same
61+
while True:
62+
time.sleep(10)

0 commit comments

Comments
 (0)