Skip to content

Implement grayscale support #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 22, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions adafruit_uc8151d.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,65 @@
b"\x50\x01\x97" # CDI setting
)

_GRAYSCALE_START_SEQUENCE = (
b"\x04\x80\xc8" # Power on
b"\x00\x01\xbf" # Panel setting
b"\x50\x01\x97" # CDI setting
# Common voltage
b"\x20\x2a"
b"\x00\x0A\x00\x00\x00\x01"
b"\x60\x14\x14\x00\x00\x01"
b"\x00\x14\x00\x00\x00\x01"
b"\x00\x13\x0A\x01\x00\x01"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
# White to White
b"\x21\x2a"
b"\x40\x0A\x00\x00\x00\x01"
b"\x90\x14\x14\x00\x00\x01"
b"\x10\x14\x0A\x00\x00\x01"
b"\xA0\x13\x01\x00\x00\x01"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
# Black to White
b"\x22\x2a"
b"\x40\x0A\x00\x00\x00\x01"
b"\x90\x14\x14\x00\x00\x01"
b"\x00\x14\x0A\x00\x00\x01"
b"\x99\x0B\x04\x04\x01\x01"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
# White to Black
b"\x23\x2a"
b"\x40\x0A\x00\x00\x00\x01"
b"\x90\x14\x14\x00\x00\x01"
b"\x00\x14\x0A\x00\x00\x01"
b"\x99\x0C\x01\x03\x04\x01"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
# Black to Black
b"\x24\x2a"
b"\x80\x0A\x00\x00\x00\x01"
b"\x90\x14\x14\x00\x00\x01"
b"\x20\x14\x0A\x00\x00\x01"
b"\x50\x13\x01\x00\x00\x01"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00"
)


_STOP_SEQUENCE = b"\x50\x01\xf7" b"\x07\x01\xA5" # CDI setting # Deep Sleep
# pylint: disable=too-few-public-methods
class UC8151D(displayio.EPaperDisplay):
r"""UC8151D driver

:param bus: The data bus the display is on
:param \**kwargs:
See below

:Keyword Arguments:
* *width* (``int``) --
Display width
Expand All @@ -57,14 +107,18 @@ class UC8151D(displayio.EPaperDisplay):
"""

def __init__(self, bus, **kwargs):
if kwargs.get("grayscale", False):
start_sequence = bytearray(_GRAYSCALE_START_SEQUENCE)
else:
start_sequence = bytearray(_START_SEQUENCE)
width = kwargs["width"]
height = kwargs["height"]
if "rotation" in kwargs and kwargs["rotation"] % 180 != 0:
width, height = height, width

super().__init__(
bus,
_START_SEQUENCE,
start_sequence,
_STOP_SEQUENCE,
**kwargs,
ram_width=128,
Expand Down