Skip to content

Add grayscale support #12

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 3 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
78 changes: 75 additions & 3 deletions adafruit_il0373.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,61 @@
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 200 ms
b"\x00\x01\xcf" # panel setting
b"\x00\x01\x0f" # panel setting. Further filled in below.
b"\x50\x01\x37" # CDI setting
b"\x30\x01\x29" # PLL
b"\x30\x01\x29" # PLL set to 150 Hz
b"\x61\x03\x00\x00\x00" # Resolution
b"\x82\x81\x32\x0a" # VCM DC and delay 50ms
)

_GRAYSCALE_LUT = (
# 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\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"
# 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\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"
# 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\x17" # CDI setting
b"\x82\x01\x00" # VCM DC and delay 50ms
Expand Down Expand Up @@ -90,7 +138,12 @@ class IL0373(displayio.EPaperDisplay):
"""

def __init__(self, bus, swap_rams=False, **kwargs):
start_sequence = bytearray(_START_SEQUENCE)
if kwargs.get("grayscale", False):
start_sequence = bytearray(len(_START_SEQUENCE) + len(_GRAYSCALE_LUT))
start_sequence[: len(_START_SEQUENCE)] = _START_SEQUENCE
start_sequence[len(_START_SEQUENCE) :] = _GRAYSCALE_LUT
else:
start_sequence = bytearray(_START_SEQUENCE)

width = kwargs["width"]
height = kwargs["height"]
Expand All @@ -109,6 +162,25 @@ def __init__(self, bus, swap_rams=False, **kwargs):
write_color_ram_command = 0x13
color_bits_inverted = kwargs.pop("color_bits_inverted", True)
black_bits_inverted = kwargs.pop("black_bits_inverted", False)
if "highlight_color" not in kwargs:
start_sequence[17] |= 1 << 4 # Set BWR to only do black and white.
if kwargs.get("grayscale", False):
start_sequence[17] |= (
1 << 5
) # Set REG_EN to use the LUT sequence from the registers.
start_sequence[6] = 0x13 # Boost the voltage
start_sequence[23] = 0x3C # PLL set to 50 Hz (M = 7, N = 4)

# Set the resolution to scan
if width > 128:
start_sequence[17] |= 0b11 << 5 # 160x296
elif height > 252 or width > 96:
start_sequence[17] |= 0b10 << 5 # 128x296
elif height > 230:
start_sequence[17] |= 0b01 << 5 # 96x252
else:
pass # 0b00 is 96x230

super().__init__(
bus,
start_sequence,
Expand Down
Binary file modified examples/display-ruler.bmp
Binary file not shown.
51 changes: 51 additions & 0 deletions examples/il0373_2.9_grayscale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Simple test script for 2.9" 296x128 grayscale display.

Supported products:
* Adafruit 2.9" Grayscale
* https://www.adafruit.com/product/4777
"""

import time
import busio
import board
import displayio
import adafruit_il0373

displayio.release_displays()

# This pinout works on a Feather M4 and may need to be altered for other boards.
spi = busio.SPI(board.SCK, board.MOSI) # Uses SCK and MOSI
epd_cs = board.D9
epd_dc = board.D10

display_bus = displayio.FourWire(
spi, command=epd_dc, chip_select=epd_cs, baudrate=1000000
)
time.sleep(1)

display = adafruit_il0373.IL0373(
display_bus,
width=296,
height=128,
rotation=270,
black_bits_inverted=False,
color_bits_inverted=False,
grayscale=True,
refresh_time=1,
)

g = displayio.Group()

f = open("/display-ruler.bmp", "rb")

pic = displayio.OnDiskBitmap(f)
t = displayio.TileGrid(pic, pixel_shader=displayio.ColorConverter())
g.append(t)

display.show(g)

display.refresh()

print("refreshed")

time.sleep(120)