Merge pull request #8 from makermelissa/main

Added tri-color support
This commit is contained in:
Melissa LeBlanc-Williams 2022-11-18 14:23:18 -08:00 committed by GitHub
commit b6d9f852f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 6 deletions

24
adafruit_uc8151d.py Normal file → Executable file
View file

@ -17,6 +17,7 @@ Implementation Notes
**Hardware:**
* `Adafruit Flexible 2.9" Black and White <https://www.adafruit.com/product/4262>`_
* `Adafruit Tri-Color 2.9" <https://www.adafruit.com/product/1028>`_
**Software and Dependencies:**
@ -33,11 +34,18 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_UC8151D.git"
_START_SEQUENCE = (
# b"\x01\x05\x03\x00\x2b\x2b\x09" # power setting
# b"\x06\x03\x17\x17\x17" # booster soft start
b"\x04\x80\xc8" # power on and wait 10 ms
b"\x04\x80\xc8" # power on and wait 200 ms
b"\x00\x01\x1f" # panel setting. Further filled in below.
b"\x50\x01\x97" # CDI setting
)
_COLOR_START_SEQUENCE = (
b"\x04\x80\xc8" # power on and wait 200 ms
b"\x00\x02\x0f\x89" # panel setting. Further filled in below.
b"\x61\x03\x80\x01\x28" # Set Display Resolution
b"\x50\x01\x77" # CDI setting
)
_GRAYSCALE_START_SEQUENCE = (
b"\x04\x80\xc8" # Power on
b"\x00\x01\xbf" # Panel setting
@ -89,7 +97,6 @@ _GRAYSCALE_START_SEQUENCE = (
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):
@ -109,8 +116,16 @@ class UC8151D(displayio.EPaperDisplay):
"""
def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
color_bits_inverted = kwargs.pop("color_bits_inverted", False)
write_color_ram_command = 0x10
write_black_ram_command = 0x13
if kwargs.get("grayscale", False):
start_sequence = bytearray(_GRAYSCALE_START_SEQUENCE)
elif kwargs.get("highlight_color", False):
write_color_ram_command = 0x13
write_black_ram_command = 0x10
color_bits_inverted = kwargs.pop("color_bits_inverted", True)
start_sequence = bytearray(_COLOR_START_SEQUENCE)
else:
start_sequence = bytearray(_START_SEQUENCE)
width = kwargs["width"]
@ -126,7 +141,8 @@ class UC8151D(displayio.EPaperDisplay):
ram_width=128,
ram_height=296,
busy_state=False,
write_black_ram_command=0x13,
write_color_ram_command=0x10,
write_black_ram_command=write_black_ram_command,
write_color_ram_command=write_color_ram_command,
color_bits_inverted=color_bits_inverted,
refresh_display_command=0x12,
)

View file

@ -1,8 +1,19 @@
Simple test
------------
Ensure your device works with this simple test.
Ensure your device works with this simple test. This simple test is for the 2.9" Flexible Monochrome display.
.. literalinclude:: ../examples/uc8151d_simpletest.py
:caption: examples/uc8151d_simpletest.py
:linenos:
Device Specific Examples
------------------------
.. literalinclude:: ../examples/uc8151d_1.54_grayscale.py
:caption: examples/uc8151d_1.54_grayscale.py
:linenos:
.. literalinclude:: ../examples/uc8151d_2.9_color.py
:caption: examples/uc8151d_2.9_color.py
:linenos:

View file

@ -6,7 +6,7 @@
Supported products:
* 1.54" Grayscale Display (GDEW0154T8D)
"""
"""
# pylint: disable=no-member
import time

View file

@ -0,0 +1,65 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""Simple test script for Adafruit 2.9" 296x128 tri-color display
Supported products:
* Adafruit 2.9" Tri-Color Display Breakout
* https://www.adafruit.com/product/1028
"""
import time
import board
import displayio
import adafruit_uc8151d
# Used to ensure the display is free in CircuitPython
displayio.release_displays()
# Define the pins needed for display use
# This pinout is for a Feather M4 and may be different for other boards
spi = board.SPI() # Uses SCK and MOSI
epd_cs = board.D9
epd_dc = board.D10
epd_reset = board.D5
epd_busy = board.D6
# Create the displayio connection to the display pins
display_bus = displayio.FourWire(
spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000
)
time.sleep(1) # Wait a bit
# Create the display object - the third color is red (0xff0000)
display = adafruit_uc8151d.UC8151D(
display_bus,
width=296,
height=128,
rotation=270,
busy_pin=epd_busy,
highlight_color=0xFF0000,
)
# Create a display group for our screen objects
g = displayio.Group()
# Display a ruler graphic from the root directory of the CIRCUITPY drive
with open("/display-ruler.bmp", "rb") as f:
pic = displayio.OnDiskBitmap(f)
# Create a Tilegrid with the bitmap and put in the displayio group
# CircuitPython 6 & 7 compatible
t = displayio.TileGrid(
pic, pixel_shader=getattr(pic, "pixel_shader", displayio.ColorConverter())
)
# CircuitPython 7 compatible only
# t = displayio.TileGrid(pic, pixel_shader=pic.pixel_shader)
g.append(t)
# Place the display group on the screen
display.show(g)
# Refresh the display to have it actually show the image
# NOTE: Do not refresh eInk displays sooner than 180 seconds
display.refresh()
print("refreshed")
time.sleep(180)