From 96dbaf1e84af49f89a3cda3323721ccf1e79b1d8 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Apr 2023 13:45:39 -0700 Subject: [PATCH 1/2] Fix partial update coordinates The addresses are little endian. CircuitPython 8.1.0+ is needed for this to work. --- adafruit_ssd1680.py | 4 +- examples/ssd1680_four_corners.py | 86 ++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 examples/ssd1680_four_corners.py diff --git a/adafruit_ssd1680.py b/adafruit_ssd1680.py index 3a0428d..186317a 100755 --- a/adafruit_ssd1680.py +++ b/adafruit_ssd1680.py @@ -98,5 +98,7 @@ def __init__(self, bus: displayio.Fourwire, **kwargs) -> None: set_current_column_command=0x4E, set_current_row_command=0x4F, refresh_display_command=0x20, - always_toggle_chip_select=True, + always_toggle_chip_select=False, + address_little_endian=True ) + diff --git a/examples/ssd1680_four_corners.py b/examples/ssd1680_four_corners.py new file mode 100644 index 0000000..160816f --- /dev/null +++ b/examples/ssd1680_four_corners.py @@ -0,0 +1,86 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +"""Test partial updates by moving a simple label around each of the four corners.""" + +# The top left is 0 or 4, top right is 1 or 5, bottom left is 2 or 6 and bottom +# right is 3 or 7. (It does % 8 for the label and % 4 for position.) +# pylint: disable=no-member + +import time +import board +import busio +import displayio +import digitalio +import terminalio +import adafruit_ssd1680 + +displayio.release_displays() + +# This pinout works on a Feather RP2040 EPD and may need to be altered for other +# boards. The newer SSD1680 version with FPC on the ribbon cable 2.13" dual color +# is connected directly via the ribbon cable. +spi = busio.SPI(board.EPD_SCK, board.EPD_MOSI) # Uses SCK and MOSI +epd_cs = board.EPD_CS +epd_dc = board.EPD_DC +epd_reset = board.EPD_RESET +epd_busy = board.EPD_BUSY + +display_bus = displayio.FourWire( + spi, + command=epd_dc, + chip_select=epd_cs, + reset=epd_reset, + baudrate=1000000 +) +display = adafruit_ssd1680.SSD1680( + display_bus, + colstart=8, + width=250, + height=122, + busy_pin=epd_busy, + highlight_color=0xFFFFFF, + rotation=270, + seconds_per_frame=10 +) + +# Make the display context +main_group = displayio.Group() +display.show(main_group) + +palette = displayio.Palette(2) +palette[0] = 0x000000 +palette[1] = 0xffffff + +zero_glyph = terminalio.FONT.get_glyph(ord('0')) + +padding = max(zero_glyph.height, zero_glyph.width) + 1 +label = displayio.TileGrid(terminalio.FONT.bitmap, pixel_shader=palette, tile_width=zero_glyph.width, tile_height=zero_glyph.height) +main_group.append(label) + +# Number each of the 4 corners +i = 0 +while True: + if i % 2 == 0: + label.x = padding + else: + label.x = display.width - padding - zero_glyph.width + if (i % 4) // 2 == 0: + label.y = padding + else: + label.y = display.height - padding - zero_glyph.height + + label[0] = zero_glyph.tile_index + i + + # update text property to change the text showing on the display + sleep_time = display.time_to_refresh + print(f"Sleeping {sleep_time} seconds") + time.sleep(sleep_time) + + print(f"{i % 8} @ ({label.x}, {label.y})") + display.refresh() + + i += 1 + i %= 8 From a2423d5e578efd8753529690c591319763250430 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Apr 2023 14:10:12 -0700 Subject: [PATCH 2/2] Lint + black --- adafruit_ssd1680.py | 1 - examples/ssd1680_four_corners.py | 42 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/adafruit_ssd1680.py b/adafruit_ssd1680.py index 186317a..83804ab 100755 --- a/adafruit_ssd1680.py +++ b/adafruit_ssd1680.py @@ -101,4 +101,3 @@ def __init__(self, bus: displayio.Fourwire, **kwargs) -> None: always_toggle_chip_select=False, address_little_endian=True ) - diff --git a/examples/ssd1680_four_corners.py b/examples/ssd1680_four_corners.py index 160816f..28f9a76 100644 --- a/examples/ssd1680_four_corners.py +++ b/examples/ssd1680_four_corners.py @@ -13,7 +13,6 @@ import board import busio import displayio -import digitalio import terminalio import adafruit_ssd1680 @@ -29,21 +28,17 @@ epd_busy = board.EPD_BUSY display_bus = displayio.FourWire( - spi, - command=epd_dc, - chip_select=epd_cs, - reset=epd_reset, - baudrate=1000000 + spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000 ) display = adafruit_ssd1680.SSD1680( - display_bus, - colstart=8, - width=250, - height=122, - busy_pin=epd_busy, - highlight_color=0xFFFFFF, - rotation=270, - seconds_per_frame=10 + display_bus, + colstart=8, + width=250, + height=122, + busy_pin=epd_busy, + highlight_color=0xFFFFFF, + rotation=270, + seconds_per_frame=10, ) # Make the display context @@ -52,25 +47,30 @@ palette = displayio.Palette(2) palette[0] = 0x000000 -palette[1] = 0xffffff +palette[1] = 0xFFFFFF -zero_glyph = terminalio.FONT.get_glyph(ord('0')) +zero_glyph = terminalio.FONT.get_glyph(ord("0")) padding = max(zero_glyph.height, zero_glyph.width) + 1 -label = displayio.TileGrid(terminalio.FONT.bitmap, pixel_shader=palette, tile_width=zero_glyph.width, tile_height=zero_glyph.height) +label = displayio.TileGrid( + terminalio.FONT.bitmap, + pixel_shader=palette, + tile_width=zero_glyph.width, + tile_height=zero_glyph.height, +) main_group.append(label) # Number each of the 4 corners i = 0 while True: if i % 2 == 0: - label.x = padding + label.x = padding else: - label.x = display.width - padding - zero_glyph.width + label.x = display.width - padding - zero_glyph.width if (i % 4) // 2 == 0: - label.y = padding + label.y = padding else: - label.y = display.height - padding - zero_glyph.height + label.y = display.height - padding - zero_glyph.height label[0] = zero_glyph.tile_index + i