Skip to content

Commit 10c49b9

Browse files
authored
Merge pull request #11 from tannewt/little_endian
Fix partial update coordinates
2 parents ec8650b + e230589 commit 10c49b9

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 terminalio
17+
import adafruit_ssd1681
18+
19+
displayio.release_displays()
20+
21+
# This pinout works on a Feather RP2040 EPD and may need to be altered for other
22+
# boards. The 200x200px SSD1681 display with "SYX 2024" on the ribbon cable (tricolor) or
23+
# "SYX 2118" (bicolor) is connected directly via the ribbon cable.
24+
spi = busio.SPI(board.EPD_SCK, board.EPD_MOSI) # Uses SCK and MOSI
25+
epd_cs = board.EPD_CS
26+
epd_dc = board.EPD_DC
27+
epd_reset = board.EPD_RESET
28+
epd_busy = board.EPD_BUSY
29+
30+
display_bus = displayio.FourWire(
31+
spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000
32+
)
33+
display = adafruit_ssd1681.SSD1681(
34+
display_bus,
35+
width=200,
36+
height=200,
37+
busy_pin=epd_busy,
38+
highlight_color=0xFF0000,
39+
rotation=180,
40+
seconds_per_frame=15,
41+
)
42+
43+
# Make the display context
44+
main_group = displayio.Group()
45+
display.show(main_group)
46+
47+
palette = displayio.Palette(2)
48+
palette[0] = 0x000000
49+
palette[1] = 0xFFFFFF
50+
51+
zero_glyph = terminalio.FONT.get_glyph(ord("0"))
52+
53+
padding = max(zero_glyph.height, zero_glyph.width) + 1
54+
label = displayio.TileGrid(
55+
terminalio.FONT.bitmap,
56+
pixel_shader=palette,
57+
tile_width=zero_glyph.width,
58+
tile_height=zero_glyph.height,
59+
)
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)