Skip to content

Commit 66fdd9a

Browse files
committed
Fix partial update coordinates
The addresses are little endian. CircuitPython 8.1.0+ is needed for this to work.
1 parent 79903ca commit 66fdd9a

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

adafruit_ssd1681.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
6969
start_sequence[21] = (width - 1) & 0xFF
7070
start_sequence[22] = ((width >> 8) - 1) & 0xFF
7171

72+
# RAM is actually only 200 bits high but we use 296 to match the 9 bits
73+
# (and therefore two bytes) used to address height.
7274
super().__init__(
7375
bus,
7476
start_sequence,
@@ -86,4 +88,5 @@ def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
8688
set_current_row_command=0x4F,
8789
refresh_display_command=0x20,
8890
always_toggle_chip_select=True,
91+
address_little_endian=True
8992
)

examples/ssd1681_four_corners.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Scott Shawcroft for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: Unlicense
5+
6+
"""Test partial updates by moving a simple label around each of the four corners."""
7+
8+
# The top left is 0 or 4, top right is 1 or 5, bottom left is 2 or 6 and bottom
9+
# right is 3 or 7. (It does % 8 for the label and % 4 for position.)
10+
# pylint: disable=no-member
11+
12+
import time
13+
import board
14+
import busio
15+
import displayio
16+
import digitalio
17+
import terminalio
18+
import adafruit_ssd1681
19+
20+
displayio.release_displays()
21+
22+
# This pinout works on a Feather RP2040 EPD and may need to be altered for other
23+
# boards. The 200x200px SSD1681 display with "SYX 2024" on the ribbon cable (tricolor) or
24+
# "SYX 2118" (bicolor) is connected directly via the ribbon cable.
25+
spi = busio.SPI(board.EPD_SCK, board.EPD_MOSI) # Uses SCK and MOSI
26+
epd_cs = board.EPD_CS
27+
epd_dc = board.EPD_DC
28+
epd_reset = board.EPD_RESET
29+
epd_busy = board.EPD_BUSY
30+
31+
display_bus = displayio.FourWire(
32+
spi,
33+
command=epd_dc,
34+
chip_select=epd_cs,
35+
reset=epd_reset,
36+
baudrate=1000000
37+
)
38+
display = adafruit_ssd1681.SSD1681(
39+
display_bus,
40+
width=200,
41+
height=200,
42+
busy_pin=epd_busy,
43+
highlight_color=0xFF0000,
44+
rotation=180,
45+
seconds_per_frame=15
46+
)
47+
48+
# Make the display context
49+
main_group = displayio.Group()
50+
display.show(main_group)
51+
52+
palette = displayio.Palette(2)
53+
palette[0] = 0x000000
54+
palette[1] = 0xffffff
55+
56+
zero_glyph = terminalio.FONT.get_glyph(ord('0'))
57+
58+
padding = max(zero_glyph.height, zero_glyph.width) + 1
59+
label = displayio.TileGrid(terminalio.FONT.bitmap, pixel_shader=palette, tile_width=zero_glyph.width, tile_height=zero_glyph.height)
60+
main_group.append(label)
61+
62+
# Number each of the 4 corners
63+
i = 0
64+
while True:
65+
if i % 2 == 0:
66+
label.x = padding
67+
else:
68+
label.x = display.width - padding - zero_glyph.width
69+
if (i % 4) // 2 == 0:
70+
label.y = padding
71+
else:
72+
label.y = display.height - padding - zero_glyph.height
73+
74+
label[0] = zero_glyph.tile_index + i
75+
76+
# update text property to change the text showing on the display
77+
sleep_time = display.time_to_refresh
78+
print(f"Sleeping {sleep_time} seconds")
79+
time.sleep(sleep_time + 0.1)
80+
81+
print(f"{i % 8} @ ({label.x}, {label.y})")
82+
display.refresh()
83+
84+
i += 1
85+
i %= 8

0 commit comments

Comments
 (0)