Compare commits
21 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45a24db357 | ||
|
|
cd138e9d5d | ||
|
|
4fb198d031 | ||
|
|
9c88f82310 | ||
|
|
18be7bba54 | ||
|
|
f064871305 | ||
|
|
c69536e083 | ||
|
|
7c669c774b | ||
|
|
0be196a266 | ||
|
|
6b19e3e906 | ||
|
|
6044f1110f | ||
|
|
5ea27cf74b | ||
|
|
a04a6a8d48 | ||
|
|
6ba7fd3369 | ||
|
|
dc6bda8a81 | ||
|
|
04032f3b2b | ||
|
|
3ebcc90725 | ||
|
|
be77207255 | ||
|
|
711012ec84 | ||
|
|
18d480d6b2 | ||
|
|
298eeb6c9d |
10 changed files with 1069 additions and 32 deletions
467
adafruit_epd/jd79661.py
Normal file
467
adafruit_epd/jd79661.py
Normal file
|
|
@ -0,0 +1,467 @@
|
||||||
|
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
"""
|
||||||
|
`adafruit_epd.jd79661` - Adafruit JD79661 - quad-color ePaper display driver
|
||||||
|
====================================================================================
|
||||||
|
CircuitPython driver for Adafruit JD79661 quad-color display breakouts
|
||||||
|
* Author(s): Liz Clark
|
||||||
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
import adafruit_framebuf
|
||||||
|
from micropython import const
|
||||||
|
|
||||||
|
from adafruit_epd.epd import Adafruit_EPD
|
||||||
|
|
||||||
|
try:
|
||||||
|
"""Needed for type annotations"""
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from busio import SPI
|
||||||
|
from circuitpython_typing.pil import Image
|
||||||
|
from digitalio import DigitalInOut
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
__version__ = "0.0.0+auto.0"
|
||||||
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
|
||||||
|
|
||||||
|
# Command constants
|
||||||
|
_JD79661_PANEL_SETTING = const(0x00)
|
||||||
|
_JD79661_POWER_SETTING = const(0x01)
|
||||||
|
_JD79661_POWER_OFF = const(0x02)
|
||||||
|
_JD79661_POWER_ON = const(0x04)
|
||||||
|
_JD79661_BOOSTER_SOFTSTART = const(0x06)
|
||||||
|
_JD79661_DEEP_SLEEP = const(0x07)
|
||||||
|
_JD79661_DATA_START_XMIT = const(0x10)
|
||||||
|
_JD79661_DISPLAY_REFRESH = const(0x12)
|
||||||
|
_JD79661_PLL_CONTROL = const(0x30)
|
||||||
|
_JD79661_CDI = const(0x50)
|
||||||
|
_JD79661_RESOLUTION = const(0x61)
|
||||||
|
|
||||||
|
# Color constants for internal use (2-bit values)
|
||||||
|
_JD79661_BLACK = const(0b00)
|
||||||
|
_JD79661_WHITE = const(0b01)
|
||||||
|
_JD79661_YELLOW = const(0b10)
|
||||||
|
_JD79661_RED = const(0b11)
|
||||||
|
|
||||||
|
# Other command constants from init sequence
|
||||||
|
_JD79661_POFS = const(0x03)
|
||||||
|
_JD79661_TCON = const(0x60)
|
||||||
|
_JD79661_CMD_E7 = const(0xE7)
|
||||||
|
_JD79661_CMD_E3 = const(0xE3)
|
||||||
|
_JD79661_CMD_B4 = const(0xB4)
|
||||||
|
_JD79661_CMD_B5 = const(0xB5)
|
||||||
|
_JD79661_CMD_E9 = const(0xE9)
|
||||||
|
_JD79661_CMD_4D = const(0x4D)
|
||||||
|
|
||||||
|
|
||||||
|
class Adafruit_JD79661(Adafruit_EPD):
|
||||||
|
"""Driver for the JD79661 quad-color ePaper display breakouts"""
|
||||||
|
|
||||||
|
BLACK = const(0) # 0b00 in the display buffer
|
||||||
|
WHITE = const(1) # 0b01 in the display buffer
|
||||||
|
YELLOW = const(2) # 0b10 in the display buffer
|
||||||
|
RED = const(3) # 0b11 in the display buffer
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
width: int,
|
||||||
|
height: int,
|
||||||
|
spi: SPI,
|
||||||
|
*,
|
||||||
|
cs_pin: DigitalInOut,
|
||||||
|
dc_pin: DigitalInOut,
|
||||||
|
sramcs_pin: DigitalInOut,
|
||||||
|
rst_pin: DigitalInOut,
|
||||||
|
busy_pin: DigitalInOut,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the quad-color display driver.
|
||||||
|
|
||||||
|
Note: This driver uses a different buffer architecture than the parent class.
|
||||||
|
Instead of separate black and color buffers, it uses a single buffer with
|
||||||
|
2 bits per pixel to represent 4 colors.
|
||||||
|
"""
|
||||||
|
super().__init__(width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin)
|
||||||
|
|
||||||
|
stride = width
|
||||||
|
if stride % 8 != 0:
|
||||||
|
stride += 8 - stride % 8
|
||||||
|
|
||||||
|
self._buffer1_size = int(stride * height / 4)
|
||||||
|
self._buffer2_size = 0 # No second buffer for this display
|
||||||
|
|
||||||
|
if sramcs_pin:
|
||||||
|
self._buffer1 = self.sram.get_view(0)
|
||||||
|
self._buffer2 = self._buffer1
|
||||||
|
else:
|
||||||
|
self._buffer1 = bytearray(self._buffer1_size)
|
||||||
|
self._buffer2 = self._buffer1
|
||||||
|
|
||||||
|
self._framebuf1 = adafruit_framebuf.FrameBuffer(
|
||||||
|
self._buffer1,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
stride=stride,
|
||||||
|
buf_format=adafruit_framebuf.MHMSB,
|
||||||
|
)
|
||||||
|
self._framebuf2 = self._framebuf1 # Same framebuffer for compatibility
|
||||||
|
|
||||||
|
# Set single byte transactions
|
||||||
|
self._single_byte_tx = True
|
||||||
|
|
||||||
|
# Set up buffer references for parent class compatibility
|
||||||
|
# Both point to the same buffer since we don't have separate color planes
|
||||||
|
self.set_black_buffer(0, False)
|
||||||
|
self.set_color_buffer(0, False)
|
||||||
|
|
||||||
|
# Initialize with default fill
|
||||||
|
self.fill(Adafruit_JD79661.WHITE)
|
||||||
|
|
||||||
|
def begin(self, reset: bool = True) -> None:
|
||||||
|
"""Begin communication with the display and set basic settings"""
|
||||||
|
if reset:
|
||||||
|
self.hardware_reset()
|
||||||
|
time.sleep(0.1)
|
||||||
|
self.power_down()
|
||||||
|
|
||||||
|
def busy_wait(self) -> None:
|
||||||
|
"""Wait for display to be done with current task, either by polling the
|
||||||
|
busy pin, or pausing. Note: JD79661 busy is HIGH when busy"""
|
||||||
|
if self._busy:
|
||||||
|
while not self._busy.value: # Wait for busy HIGH
|
||||||
|
time.sleep(0.01)
|
||||||
|
else:
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
def power_up(self) -> None:
|
||||||
|
"""Power up the display in preparation for writing RAM and updating"""
|
||||||
|
self.hardware_reset()
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
# Send initialization sequence
|
||||||
|
time.sleep(0.01) # Wait 10ms
|
||||||
|
|
||||||
|
self.command(_JD79661_CMD_4D, bytearray([0x78]))
|
||||||
|
self.command(
|
||||||
|
_JD79661_PANEL_SETTING, bytearray([0x8F, 0x29])
|
||||||
|
) # PSR, Display resolution is 128x250
|
||||||
|
self.command(_JD79661_POWER_SETTING, bytearray([0x07, 0x00])) # PWR
|
||||||
|
self.command(_JD79661_POFS, bytearray([0x10, 0x54, 0x44])) # POFS
|
||||||
|
self.command(
|
||||||
|
_JD79661_BOOSTER_SOFTSTART, bytearray([0x05, 0x00, 0x3F, 0x0A, 0x25, 0x12, 0x1A])
|
||||||
|
)
|
||||||
|
self.command(_JD79661_CDI, bytearray([0x37])) # CDI
|
||||||
|
self.command(_JD79661_TCON, bytearray([0x02, 0x02])) # TCON
|
||||||
|
self.command(_JD79661_RESOLUTION, bytearray([0, 128, 0, 250])) # TRES
|
||||||
|
self.command(_JD79661_CMD_E7, bytearray([0x1C]))
|
||||||
|
self.command(_JD79661_CMD_E3, bytearray([0x22]))
|
||||||
|
self.command(_JD79661_CMD_B4, bytearray([0xD0]))
|
||||||
|
self.command(_JD79661_CMD_B5, bytearray([0x03]))
|
||||||
|
self.command(_JD79661_CMD_E9, bytearray([0x01]))
|
||||||
|
self.command(_JD79661_PLL_CONTROL, bytearray([0x08]))
|
||||||
|
self.command(_JD79661_POWER_ON)
|
||||||
|
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
def power_down(self) -> None:
|
||||||
|
"""Power down the display - required when not actively displaying!"""
|
||||||
|
if self._rst:
|
||||||
|
self.command(_JD79661_POWER_OFF, bytearray([0x00]))
|
||||||
|
self.busy_wait()
|
||||||
|
self.command(_JD79661_DEEP_SLEEP, bytearray([0xA5]))
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
def update(self) -> None:
|
||||||
|
"""Update the display from internal memory"""
|
||||||
|
self.command(_JD79661_DISPLAY_REFRESH, bytearray([0x00]))
|
||||||
|
self.busy_wait()
|
||||||
|
if not self._busy:
|
||||||
|
time.sleep(1) # Wait 1 second if no busy pin
|
||||||
|
|
||||||
|
def write_ram(self, index: Literal[0, 1]) -> int:
|
||||||
|
"""Send the one byte command for starting the RAM write process."""
|
||||||
|
# JD79661 uses same command for all data
|
||||||
|
return self.command(_JD79661_DATA_START_XMIT, end=False)
|
||||||
|
|
||||||
|
def set_ram_address(self, x: int, y: int) -> None:
|
||||||
|
"""Set the RAM address location."""
|
||||||
|
# Not used for JD79661
|
||||||
|
pass
|
||||||
|
|
||||||
|
def fill(self, color: int) -> None:
|
||||||
|
"""Fill the entire display with the specified color.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
color: Color value (BLACK, WHITE, YELLOW, or RED)
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: If an invalid color is specified
|
||||||
|
"""
|
||||||
|
# Map colors to fill patterns (4 pixels per byte)
|
||||||
|
color_map = {
|
||||||
|
Adafruit_JD79661.BLACK: 0x00, # 0b00000000 - all pixels black
|
||||||
|
Adafruit_JD79661.WHITE: 0x55, # 0b01010101 - all pixels white
|
||||||
|
Adafruit_JD79661.YELLOW: 0xAA, # 0b10101010 - all pixels yellow
|
||||||
|
Adafruit_JD79661.RED: 0xFF, # 0b11111111 - all pixels red
|
||||||
|
}
|
||||||
|
|
||||||
|
if color not in color_map:
|
||||||
|
raise ValueError(
|
||||||
|
f"Invalid color: {color}. Use BLACK (0), WHITE (1), YELLOW (2), or RED (3)."
|
||||||
|
)
|
||||||
|
|
||||||
|
fill_byte = color_map[color]
|
||||||
|
|
||||||
|
if self.sram:
|
||||||
|
self.sram.erase(0x00, self._buffer1_size, fill_byte)
|
||||||
|
else:
|
||||||
|
for i in range(self._buffer1_size):
|
||||||
|
self._buffer1[i] = fill_byte
|
||||||
|
|
||||||
|
def pixel(self, x: int, y: int, color: int) -> None:
|
||||||
|
"""Draw a single pixel in the display buffer.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x: X coordinate
|
||||||
|
y: Y coordinate
|
||||||
|
color: Color value (BLACK, WHITE, YELLOW, or RED)
|
||||||
|
"""
|
||||||
|
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):
|
||||||
|
return
|
||||||
|
|
||||||
|
# Handle rotation
|
||||||
|
if self.rotation == 1:
|
||||||
|
x, y = y, x
|
||||||
|
x = self._width - x - 1
|
||||||
|
if self._width % 8 != 0:
|
||||||
|
x -= self._width % 8
|
||||||
|
elif self.rotation == 2:
|
||||||
|
x = self._width - x - 1
|
||||||
|
y = self._height - y - 1
|
||||||
|
if self._width % 8 != 0:
|
||||||
|
x += self._width % 8
|
||||||
|
elif self.rotation == 3:
|
||||||
|
x, y = y, x
|
||||||
|
y = self._height - y - 1
|
||||||
|
|
||||||
|
# Calculate stride (width adjusted to be divisible by 8)
|
||||||
|
stride = self._width
|
||||||
|
if stride % 8 != 0:
|
||||||
|
stride += 8 - stride % 8
|
||||||
|
|
||||||
|
# Map color constants to 2-bit values
|
||||||
|
color_map = {
|
||||||
|
Adafruit_JD79661.BLACK: _JD79661_BLACK,
|
||||||
|
Adafruit_JD79661.WHITE: _JD79661_WHITE,
|
||||||
|
Adafruit_JD79661.YELLOW: _JD79661_YELLOW,
|
||||||
|
Adafruit_JD79661.RED: _JD79661_RED,
|
||||||
|
}
|
||||||
|
|
||||||
|
if color not in color_map:
|
||||||
|
# Default to white for invalid colors
|
||||||
|
pixel_color = _JD79661_WHITE
|
||||||
|
else:
|
||||||
|
pixel_color = color_map[color]
|
||||||
|
|
||||||
|
# Calculate byte address (4 pixels per byte)
|
||||||
|
addr = (x + y * stride) // 4
|
||||||
|
|
||||||
|
# Calculate bit offset within byte (2 bits per pixel)
|
||||||
|
# Pixels are packed left-to-right, MSB first
|
||||||
|
bit_offset = (3 - (x % 4)) * 2
|
||||||
|
|
||||||
|
# Create masks
|
||||||
|
byte_mask = 0x3 << bit_offset
|
||||||
|
byte_value = (pixel_color & 0x3) << bit_offset
|
||||||
|
|
||||||
|
# Read, modify, write
|
||||||
|
if self.sram:
|
||||||
|
current = self.sram.read8(addr)
|
||||||
|
current &= ~byte_mask
|
||||||
|
current |= byte_value
|
||||||
|
self.sram.write8(addr, current)
|
||||||
|
else:
|
||||||
|
self._buffer1[addr] &= ~byte_mask
|
||||||
|
self._buffer1[addr] |= byte_value
|
||||||
|
|
||||||
|
def rect(self, x: int, y: int, width: int, height: int, color: int) -> None:
|
||||||
|
"""Draw a rectangle.
|
||||||
|
|
||||||
|
Overridden to use the quad-color pixel method.
|
||||||
|
"""
|
||||||
|
for i in range(x, x + width):
|
||||||
|
self.pixel(i, y, color)
|
||||||
|
self.pixel(i, y + height - 1, color)
|
||||||
|
for j in range(y + 1, y + height - 1):
|
||||||
|
self.pixel(x, j, color)
|
||||||
|
self.pixel(x + width - 1, j, color)
|
||||||
|
|
||||||
|
def fill_rect(self, x: int, y: int, width: int, height: int, color: int) -> None:
|
||||||
|
"""Fill a rectangle with the passed color.
|
||||||
|
|
||||||
|
Overridden to use the quad-color pixel method.
|
||||||
|
"""
|
||||||
|
for i in range(x, x + width):
|
||||||
|
for j in range(y, y + height):
|
||||||
|
self.pixel(i, j, color)
|
||||||
|
|
||||||
|
def line(self, x_0: int, y_0: int, x_1: int, y_1: int, color: int) -> None:
|
||||||
|
"""Draw a line from (x_0, y_0) to (x_1, y_1) in passed color.
|
||||||
|
|
||||||
|
Overridden to use the quad-color pixel method.
|
||||||
|
"""
|
||||||
|
dx = abs(x_1 - x_0)
|
||||||
|
dy = abs(y_1 - y_0)
|
||||||
|
sx = 1 if x_0 < x_1 else -1
|
||||||
|
sy = 1 if y_0 < y_1 else -1
|
||||||
|
err = dx - dy
|
||||||
|
|
||||||
|
while True:
|
||||||
|
self.pixel(x_0, y_0, color)
|
||||||
|
if x_0 == x_1 and y_0 == y_1:
|
||||||
|
break
|
||||||
|
e2 = 2 * err
|
||||||
|
if e2 > -dy:
|
||||||
|
err -= dy
|
||||||
|
x_0 += sx
|
||||||
|
if e2 < dx:
|
||||||
|
err += dx
|
||||||
|
y_0 += sy
|
||||||
|
|
||||||
|
def text(
|
||||||
|
self,
|
||||||
|
string: str,
|
||||||
|
x: int,
|
||||||
|
y: int,
|
||||||
|
color: int,
|
||||||
|
*,
|
||||||
|
font_name: str = "font5x8.bin",
|
||||||
|
size: int = 1,
|
||||||
|
) -> None:
|
||||||
|
"""Write text string at location (x, y) in given color, using font file."""
|
||||||
|
color_map = {
|
||||||
|
Adafruit_JD79661.BLACK: _JD79661_BLACK,
|
||||||
|
Adafruit_JD79661.WHITE: _JD79661_WHITE,
|
||||||
|
Adafruit_JD79661.YELLOW: _JD79661_YELLOW,
|
||||||
|
Adafruit_JD79661.RED: _JD79661_RED,
|
||||||
|
}
|
||||||
|
if color not in color_map:
|
||||||
|
raise ValueError(
|
||||||
|
f"Invalid color: {color}. Use BLACK (0), WHITE (1), YELLOW (2), or RED (3)."
|
||||||
|
)
|
||||||
|
|
||||||
|
text_width = len(string) * 6 * size
|
||||||
|
text_height = 8 * size
|
||||||
|
|
||||||
|
text_width = min(text_width, self.width - x)
|
||||||
|
text_height = min(text_height, self.height - y)
|
||||||
|
|
||||||
|
if text_width <= 0 or text_height <= 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
temp_buf_width = ((text_width + 7) // 8) * 8
|
||||||
|
temp_buf = bytearray((temp_buf_width * text_height) // 8)
|
||||||
|
|
||||||
|
temp_fb = adafruit_framebuf.FrameBuffer(
|
||||||
|
temp_buf, temp_buf_width, text_height, buf_format=adafruit_framebuf.MHMSB
|
||||||
|
)
|
||||||
|
|
||||||
|
temp_fb.fill(0)
|
||||||
|
temp_fb.text(string, 0, 0, 1, font_name=font_name, size=size)
|
||||||
|
|
||||||
|
for j in range(text_height):
|
||||||
|
for i in range(text_width):
|
||||||
|
byte_index = (j * temp_buf_width + i) // 8
|
||||||
|
bit_index = 7 - ((j * temp_buf_width + i) % 8)
|
||||||
|
|
||||||
|
if byte_index < len(temp_buf):
|
||||||
|
if (temp_buf[byte_index] >> bit_index) & 1:
|
||||||
|
self.pixel(x + i, y + j, color)
|
||||||
|
|
||||||
|
def image(self, image: Image) -> None:
|
||||||
|
"""Set buffer to value of Python Imaging Library image. The image should
|
||||||
|
be in RGB mode and a size equal to the display size.
|
||||||
|
"""
|
||||||
|
imwidth, imheight = image.size
|
||||||
|
if imwidth != self.width or imheight != self.height:
|
||||||
|
raise ValueError(
|
||||||
|
f"Image must be same dimensions as display ({self.width}x{self.height})."
|
||||||
|
)
|
||||||
|
if self.sram:
|
||||||
|
raise RuntimeError("PIL image is not for use with SRAM assist")
|
||||||
|
|
||||||
|
# Grab all the pixels from the image, faster than getpixel.
|
||||||
|
pix = image.load()
|
||||||
|
|
||||||
|
# Clear out any display buffers (assuming white background)
|
||||||
|
self.fill(Adafruit_JD79661.WHITE)
|
||||||
|
|
||||||
|
if image.mode == "RGB": # RGB Mode
|
||||||
|
for y in range(image.size[1]):
|
||||||
|
for x in range(image.size[0]):
|
||||||
|
pixel = pix[x, y]
|
||||||
|
r, g, b = pixel[0], pixel[1], pixel[2]
|
||||||
|
|
||||||
|
# Calculate brightness/luminance for better color detection
|
||||||
|
brightness = (r + g + b) / 3
|
||||||
|
|
||||||
|
# Color detection logic with thresholds
|
||||||
|
if brightness >= 200: # Light colors -> White
|
||||||
|
# White is typically the default, so we might not need to set it
|
||||||
|
# self.pixel(x, y, Adafruit_EPD.WHITE)
|
||||||
|
pass
|
||||||
|
elif r >= 128 and g >= 128 and b < 80: # Yellow detection
|
||||||
|
# High red and green, low blue
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.YELLOW)
|
||||||
|
elif r >= 128 and g < 80 and b < 80: # Red detection
|
||||||
|
# High red, low green and blue
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.RED)
|
||||||
|
elif brightness < 80: # Dark colors -> Black
|
||||||
|
# All RGB values are low
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.BLACK)
|
||||||
|
elif r > g and r > b and r >= 100:
|
||||||
|
# Red-dominant
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.RED)
|
||||||
|
elif r >= 100 and g >= 100:
|
||||||
|
# Both red and green high -> Yellow
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.YELLOW)
|
||||||
|
elif brightness < 128:
|
||||||
|
# Medium-dark -> Black
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.BLACK)
|
||||||
|
# else: remains white (default)
|
||||||
|
|
||||||
|
elif image.mode == "L": # Grayscale Mode
|
||||||
|
for y in range(image.size[1]):
|
||||||
|
for x in range(image.size[0]):
|
||||||
|
pixel = pix[x, y]
|
||||||
|
|
||||||
|
# Map grayscale to 4 levels
|
||||||
|
if pixel < 64:
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.BLACK)
|
||||||
|
elif pixel < 128:
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.RED) # Or could use YELLOW
|
||||||
|
elif pixel < 192:
|
||||||
|
self.pixel(x, y, Adafruit_JD79661.YELLOW)
|
||||||
|
# else: pixel >= 192 -> WHITE (default)
|
||||||
|
|
||||||
|
elif image.mode == "P": # Palette Mode (optional, for indexed color)
|
||||||
|
# Convert to RGB first for easier processing
|
||||||
|
rgb_image = image.convert("RGB")
|
||||||
|
self.image(rgb_image) # Recursive call with RGB image
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError("Image must be in mode RGB, L, or P.")
|
||||||
|
|
||||||
|
def set_black_buffer(self, index: Literal[0, 1], inverted: bool) -> None:
|
||||||
|
"""Set the index for the black buffer data."""
|
||||||
|
super().set_black_buffer(index, inverted)
|
||||||
|
|
||||||
|
def set_color_buffer(self, index: Literal[0, 1], inverted: bool) -> None:
|
||||||
|
"""Set the index for the color buffer data."""
|
||||||
|
super().set_color_buffer(index, inverted)
|
||||||
|
|
@ -153,7 +153,7 @@ class Adafruit_SSD1680(Adafruit_EPD):
|
||||||
# driver output control
|
# driver output control
|
||||||
self.command(
|
self.command(
|
||||||
_SSD1680_DRIVER_CONTROL,
|
_SSD1680_DRIVER_CONTROL,
|
||||||
bytearray([self._height - 1, (self._height - 1) >> 8, 0x00]),
|
bytearray([(self._height - 1) & 0xFF, (self._height - 1) >> 8, 0x00]),
|
||||||
)
|
)
|
||||||
# data entry mode
|
# data entry mode
|
||||||
self.command(_SSD1680_DATA_MODE, bytearray([0x03]))
|
self.command(_SSD1680_DATA_MODE, bytearray([0x03]))
|
||||||
|
|
@ -163,20 +163,23 @@ class Adafruit_SSD1680(Adafruit_EPD):
|
||||||
self.command(_SSD1680_GATE_VOLTAGE, bytearray([0x17]))
|
self.command(_SSD1680_GATE_VOLTAGE, bytearray([0x17]))
|
||||||
self.command(_SSD1680_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32]))
|
self.command(_SSD1680_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32]))
|
||||||
|
|
||||||
|
height = self._width
|
||||||
|
if height % 8 != 0:
|
||||||
|
height += 8 - (height % 8)
|
||||||
# Set ram X start/end postion
|
# Set ram X start/end postion
|
||||||
self.command(_SSD1680_SET_RAMXPOS, bytearray([0x01, 0x10]))
|
self.command(_SSD1680_SET_RAMXPOS, bytearray([0x00, (height // 8) - 1]))
|
||||||
# Set ram Y start/end postion
|
# Set ram Y start/end postion
|
||||||
self.command(
|
self.command(
|
||||||
_SSD1680_SET_RAMYPOS,
|
_SSD1680_SET_RAMYPOS,
|
||||||
bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]),
|
bytearray([0x00, 0x00, (self._height - 1) & 0xFF, (self._height - 1) >> 8]),
|
||||||
)
|
)
|
||||||
# Set border waveform
|
# Set border waveform
|
||||||
self.command(_SSD1680_WRITE_BORDER, bytearray([0x05]))
|
self.command(_SSD1680_WRITE_BORDER, bytearray([0x05]))
|
||||||
|
|
||||||
# Set ram X count
|
# Set ram X count
|
||||||
self.command(_SSD1680_SET_RAMXCOUNT, bytearray([0x01]))
|
self.command(_SSD1680_SET_RAMXCOUNT, bytearray([0x00]))
|
||||||
# Set ram Y count
|
# Set ram Y count
|
||||||
self.command(_SSD1680_SET_RAMYCOUNT, bytearray([self._height - 1, 0]))
|
self.command(_SSD1680_SET_RAMYCOUNT, bytearray([0x00, 0x00]))
|
||||||
self.busy_wait()
|
self.busy_wait()
|
||||||
|
|
||||||
def power_down(self) -> None:
|
def power_down(self) -> None:
|
||||||
|
|
@ -206,9 +209,9 @@ class Adafruit_SSD1680(Adafruit_EPD):
|
||||||
"""Set the RAM address location, not used on this chipset but required by
|
"""Set the RAM address location, not used on this chipset but required by
|
||||||
the superclass"""
|
the superclass"""
|
||||||
# Set RAM X address counter
|
# Set RAM X address counter
|
||||||
self.command(_SSD1680_SET_RAMXCOUNT, bytearray([x + 1]))
|
self.command(_SSD1680_SET_RAMXCOUNT, bytearray([0]))
|
||||||
# Set RAM Y address counter
|
# Set RAM Y address counter
|
||||||
self.command(_SSD1680_SET_RAMYCOUNT, bytearray([y, y >> 8]))
|
self.command(_SSD1680_SET_RAMYCOUNT, bytearray([0, 0]))
|
||||||
|
|
||||||
|
|
||||||
class Adafruit_SSD1680Z(Adafruit_SSD1680):
|
class Adafruit_SSD1680Z(Adafruit_SSD1680):
|
||||||
|
|
@ -239,7 +242,7 @@ class Adafruit_SSD1680Z(Adafruit_SSD1680):
|
||||||
|
|
||||||
self.command(
|
self.command(
|
||||||
_SSD1680_DRIVER_CONTROL,
|
_SSD1680_DRIVER_CONTROL,
|
||||||
bytearray([self._height, (self._height) >> 8, 0x00]),
|
bytearray([self._height & 0xFF, (self._height) >> 8, 0x00]),
|
||||||
)
|
)
|
||||||
self.command(_SSD1680_DATA_MODE, bytearray([0x03]))
|
self.command(_SSD1680_DATA_MODE, bytearray([0x03]))
|
||||||
|
|
||||||
|
|
@ -248,19 +251,19 @@ class Adafruit_SSD1680Z(Adafruit_SSD1680):
|
||||||
self.command(_SSD1680_GATE_VOLTAGE, bytearray([0x17]))
|
self.command(_SSD1680_GATE_VOLTAGE, bytearray([0x17]))
|
||||||
self.command(_SSD1680_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32]))
|
self.command(_SSD1680_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32]))
|
||||||
|
|
||||||
self.command(_SSD1680_SET_RAMXPOS, bytearray([0x00, (self._width // 8)]))
|
self.command(_SSD1680_SET_RAMXPOS, bytearray([0x00, (self._width // 8) - 1]))
|
||||||
self.command(
|
self.command(
|
||||||
_SSD1680_SET_RAMYPOS,
|
_SSD1680_SET_RAMYPOS,
|
||||||
bytearray([0x00, 0x00, self._height, (self._height) >> 8]),
|
bytearray([0x00, 0x00, (self._height - 1) & 0xFF, (self._height - 1) >> 8]),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set border waveform
|
# Set border waveform
|
||||||
self.command(_SSD1680_WRITE_BORDER, bytearray([0x05]))
|
self.command(_SSD1680_WRITE_BORDER, bytearray([0x05]))
|
||||||
|
|
||||||
# Set ram X count
|
# Set ram X count
|
||||||
self.command(_SSD1680_SET_RAMXCOUNT, bytearray([0x01]))
|
self.command(_SSD1680_SET_RAMXCOUNT, bytearray([0x00]))
|
||||||
# Set ram Y count
|
# Set ram Y count
|
||||||
self.command(_SSD1680_SET_RAMYCOUNT, bytearray([self._height, 0]))
|
self.command(_SSD1680_SET_RAMYCOUNT, bytearray([0x00, 0x00]))
|
||||||
self.busy_wait()
|
self.busy_wait()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ class Adafruit_SSD1681(Adafruit_EPD):
|
||||||
# driver output control
|
# driver output control
|
||||||
self.command(
|
self.command(
|
||||||
_SSD1681_DRIVER_CONTROL,
|
_SSD1681_DRIVER_CONTROL,
|
||||||
bytearray([self._width - 1, (self._width - 1) >> 8, 0x00]),
|
bytearray([(self._width - 1) & 0xFF, (self._width - 1) >> 8, 0x00]),
|
||||||
)
|
)
|
||||||
# data entry mode
|
# data entry mode
|
||||||
self.command(_SSD1681_DATA_MODE, bytearray([0x03]))
|
self.command(_SSD1681_DATA_MODE, bytearray([0x03]))
|
||||||
|
|
@ -152,7 +152,7 @@ class Adafruit_SSD1681(Adafruit_EPD):
|
||||||
# Set ram Y start/end postion
|
# Set ram Y start/end postion
|
||||||
self.command(
|
self.command(
|
||||||
_SSD1681_SET_RAMYPOS,
|
_SSD1681_SET_RAMYPOS,
|
||||||
bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]),
|
bytearray([0, 0, (self._height - 1) & 0xFF, (self._height - 1) >> 8]),
|
||||||
)
|
)
|
||||||
# Set border waveform
|
# Set border waveform
|
||||||
self.command(_SSD1681_WRITE_BORDER, bytearray([0x05]))
|
self.command(_SSD1681_WRITE_BORDER, bytearray([0x05]))
|
||||||
|
|
@ -190,4 +190,4 @@ class Adafruit_SSD1681(Adafruit_EPD):
|
||||||
# Set RAM X address counter
|
# Set RAM X address counter
|
||||||
self.command(_SSD1681_SET_RAMXCOUNT, bytearray([x]))
|
self.command(_SSD1681_SET_RAMXCOUNT, bytearray([x]))
|
||||||
# Set RAM Y address counter
|
# Set RAM Y address counter
|
||||||
self.command(_SSD1681_SET_RAMYCOUNT, bytearray([y, y >> 8]))
|
self.command(_SSD1681_SET_RAMYCOUNT, bytearray([y & 0xFF, y >> 8]))
|
||||||
|
|
|
||||||
262
adafruit_epd/ssd1683.py
Normal file
262
adafruit_epd/ssd1683.py
Normal file
|
|
@ -0,0 +1,262 @@
|
||||||
|
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
"""
|
||||||
|
`adafruit_epd.ssd1683` - Adafruit SSD1683 - ePaper display driver
|
||||||
|
====================================================================================
|
||||||
|
CircuitPython driver for Adafruit SSD1683 display breakouts
|
||||||
|
* Author(s): Liz Clark
|
||||||
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
import adafruit_framebuf
|
||||||
|
from micropython import const
|
||||||
|
|
||||||
|
from adafruit_epd.epd import Adafruit_EPD
|
||||||
|
|
||||||
|
try:
|
||||||
|
"""Needed for type annotations"""
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from busio import SPI
|
||||||
|
from digitalio import DigitalInOut
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
__version__ = "0.0.0+auto.0"
|
||||||
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
|
||||||
|
|
||||||
|
# Command constants
|
||||||
|
_SSD1683_DRIVER_CONTROL = const(0x01)
|
||||||
|
_SSD1683_GATE_VOLTAGE = const(0x03)
|
||||||
|
_SSD1683_SOURCE_VOLTAGE = const(0x04)
|
||||||
|
_SSD1683_PROGOTP_INITIAL = const(0x08)
|
||||||
|
_SSD1683_PROGREG_INITIAL = const(0x09)
|
||||||
|
_SSD1683_READREG_INITIAL = const(0x0A)
|
||||||
|
_SSD1683_BOOST_SOFTSTART = const(0x0C)
|
||||||
|
_SSD1683_DEEP_SLEEP = const(0x10)
|
||||||
|
_SSD1683_DATA_MODE = const(0x11)
|
||||||
|
_SSD1683_SW_RESET = const(0x12)
|
||||||
|
_SSD1683_HV_READY = const(0x14)
|
||||||
|
_SSD1683_VCI_DETECT = const(0x15)
|
||||||
|
_SSD1683_PROGRAM_WSOTP = const(0x16)
|
||||||
|
_SSD1683_PROGRAM_AUTO = const(0x17)
|
||||||
|
_SSD1683_TEMP_CONTROL = const(0x18)
|
||||||
|
_SSD1683_TEMP_WRITE = const(0x1A)
|
||||||
|
_SSD1683_TEMP_READ = const(0x1B)
|
||||||
|
_SSD1683_TEMP_CONTROLEXT = const(0x1C)
|
||||||
|
_SSD1683_MASTER_ACTIVATE = const(0x20)
|
||||||
|
_SSD1683_DISP_CTRL1 = const(0x21)
|
||||||
|
_SSD1683_DISP_CTRL2 = const(0x22)
|
||||||
|
_SSD1683_WRITE_RAM1 = const(0x24)
|
||||||
|
_SSD1683_WRITE_RAM2 = const(0x26)
|
||||||
|
_SSD1683_READ_RAM1 = const(0x27)
|
||||||
|
_SSD1683_SENSE_VCOM = const(0x28)
|
||||||
|
_SSD1683_SENSEDUR_VCOM = const(0x29)
|
||||||
|
_SSD1683_PROGOTP_VCOM = const(0x2A)
|
||||||
|
_SSD1683_WRITE_VCOM = const(0x2C)
|
||||||
|
_SSD1683_READ_OTP = const(0x2D)
|
||||||
|
_SSD1683_READ_USERID = const(0x2E)
|
||||||
|
_SSD1683_READ_STATUS = const(0x2F)
|
||||||
|
_SSD1683_WRITE_LUT = const(0x32)
|
||||||
|
_SSD1683_WRITE_BORDER = const(0x3C)
|
||||||
|
_SSD1683_END_OPTION = const(0x3F)
|
||||||
|
_SSD1683_SET_RAMXPOS = const(0x44)
|
||||||
|
_SSD1683_SET_RAMYPOS = const(0x45)
|
||||||
|
_SSD1683_SET_RAMXCOUNT = const(0x4E)
|
||||||
|
_SSD1683_SET_RAMYCOUNT = const(0x4F)
|
||||||
|
|
||||||
|
# Other constants
|
||||||
|
_EPD_RAM_BW = const(0x10)
|
||||||
|
_EPD_RAM_RED = const(0x13)
|
||||||
|
_BUSY_WAIT = const(500)
|
||||||
|
|
||||||
|
|
||||||
|
class Adafruit_SSD1683(Adafruit_EPD):
|
||||||
|
"""driver class for Adafruit SSD1683 ePaper display breakouts"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
width: int,
|
||||||
|
height: int,
|
||||||
|
spi: SPI,
|
||||||
|
*,
|
||||||
|
cs_pin: DigitalInOut,
|
||||||
|
dc_pin: DigitalInOut,
|
||||||
|
sramcs_pin: DigitalInOut,
|
||||||
|
rst_pin: DigitalInOut,
|
||||||
|
busy_pin: DigitalInOut,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin)
|
||||||
|
|
||||||
|
stride = width
|
||||||
|
if stride % 8 != 0:
|
||||||
|
stride += 8 - stride % 8
|
||||||
|
|
||||||
|
self._buffer1_size = int(stride * height / 8)
|
||||||
|
self._buffer2_size = self._buffer1_size
|
||||||
|
|
||||||
|
if sramcs_pin:
|
||||||
|
self._buffer1 = self.sram.get_view(0)
|
||||||
|
self._buffer2 = self.sram.get_view(self._buffer1_size)
|
||||||
|
else:
|
||||||
|
self._buffer1 = bytearray(self._buffer1_size)
|
||||||
|
self._buffer2 = bytearray(self._buffer2_size)
|
||||||
|
|
||||||
|
self._framebuf1 = adafruit_framebuf.FrameBuffer(
|
||||||
|
self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB
|
||||||
|
)
|
||||||
|
self._framebuf2 = adafruit_framebuf.FrameBuffer(
|
||||||
|
self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB
|
||||||
|
)
|
||||||
|
self.set_black_buffer(0, True)
|
||||||
|
self.set_color_buffer(1, False)
|
||||||
|
|
||||||
|
# Set single byte transactions flag
|
||||||
|
self._single_byte_tx = True
|
||||||
|
|
||||||
|
# Set the display update value
|
||||||
|
self._display_update_val = 0xF7
|
||||||
|
|
||||||
|
# Default initialization sequence (tri-color mode)
|
||||||
|
self._default_init_code = bytes(
|
||||||
|
[
|
||||||
|
_SSD1683_SW_RESET,
|
||||||
|
0, # Software reset
|
||||||
|
0xFF,
|
||||||
|
50, # Wait for busy (50ms delay)
|
||||||
|
_SSD1683_WRITE_BORDER,
|
||||||
|
1, # Border waveform control
|
||||||
|
0x05, # Border color/waveform
|
||||||
|
_SSD1683_TEMP_CONTROL,
|
||||||
|
1, # Temperature control
|
||||||
|
0x80, # Read temp
|
||||||
|
_SSD1683_DATA_MODE,
|
||||||
|
1, # Data entry mode
|
||||||
|
0x03, # Y decrement, X increment
|
||||||
|
0xFE, # End of initialization
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def begin(self, reset: bool = True) -> None:
|
||||||
|
"""Begin communication with the display and set basic settings"""
|
||||||
|
if reset:
|
||||||
|
self.hardware_reset()
|
||||||
|
self.power_down()
|
||||||
|
|
||||||
|
def busy_wait(self) -> None:
|
||||||
|
"""Wait for display to be done with current task, either by polling the
|
||||||
|
busy pin, or pausing"""
|
||||||
|
if self._busy:
|
||||||
|
while self._busy.value: # wait for busy low
|
||||||
|
time.sleep(0.01)
|
||||||
|
else:
|
||||||
|
time.sleep(_BUSY_WAIT / 1000.0) # Convert ms to seconds
|
||||||
|
|
||||||
|
def power_up(self) -> None:
|
||||||
|
"""Power up the display in preparation for writing RAM and updating"""
|
||||||
|
self.hardware_reset()
|
||||||
|
time.sleep(0.1)
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
# Use custom init code if provided, otherwise use default
|
||||||
|
init_code = self._default_init_code
|
||||||
|
if hasattr(self, "_epd_init_code") and self._epd_init_code is not None:
|
||||||
|
init_code = self._epd_init_code
|
||||||
|
|
||||||
|
# Send initialization sequence
|
||||||
|
self._send_command_list(init_code)
|
||||||
|
|
||||||
|
# Set RAM window
|
||||||
|
self.set_ram_window(0, 0, (self._width // 8) - 1, self._height - 1)
|
||||||
|
|
||||||
|
# Set RAM address to start position
|
||||||
|
self.set_ram_address(0, 0)
|
||||||
|
|
||||||
|
# Set LUT if we have one
|
||||||
|
if hasattr(self, "_epd_lut_code") and self._epd_lut_code:
|
||||||
|
self._send_command_list(self._epd_lut_code)
|
||||||
|
|
||||||
|
# Set display size and driver output control
|
||||||
|
_b0 = (self._height - 1) & 0xFF
|
||||||
|
_b1 = ((self._height - 1) >> 8) & 0xFF
|
||||||
|
_b2 = 0x00
|
||||||
|
self.command(_SSD1683_DRIVER_CONTROL, bytearray([_b0, _b1, _b2]))
|
||||||
|
|
||||||
|
def power_down(self) -> None:
|
||||||
|
"""Power down the display - required when not actively displaying!"""
|
||||||
|
# Only deep sleep if we can get out of it
|
||||||
|
if self._rst:
|
||||||
|
# deep sleep
|
||||||
|
self.command(_SSD1683_DEEP_SLEEP, bytearray([0x01]))
|
||||||
|
time.sleep(0.1)
|
||||||
|
else:
|
||||||
|
self.command(_SSD1683_SW_RESET)
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
def update(self) -> None:
|
||||||
|
"""Update the display from internal memory"""
|
||||||
|
# display update sequence
|
||||||
|
self.command(_SSD1683_DISP_CTRL2, bytearray([self._display_update_val]))
|
||||||
|
self.command(_SSD1683_MASTER_ACTIVATE)
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
if not self._busy:
|
||||||
|
time.sleep(1) # wait 1 second
|
||||||
|
|
||||||
|
def write_ram(self, index: Literal[0, 1]) -> int:
|
||||||
|
"""Send the one byte command for starting the RAM write process. Returns
|
||||||
|
the byte read at the same time over SPI. index is the RAM buffer, can be
|
||||||
|
0 or 1 for tri-color displays."""
|
||||||
|
if index == 0:
|
||||||
|
return self.command(_SSD1683_WRITE_RAM1, end=False)
|
||||||
|
if index == 1:
|
||||||
|
return self.command(_SSD1683_WRITE_RAM2, end=False)
|
||||||
|
raise RuntimeError("RAM index must be 0 or 1")
|
||||||
|
|
||||||
|
def set_ram_address(self, x: int, y: int) -> None:
|
||||||
|
"""Set the RAM address location"""
|
||||||
|
# set RAM x address count
|
||||||
|
self.command(_SSD1683_SET_RAMXCOUNT, bytearray([x & 0xFF]))
|
||||||
|
|
||||||
|
# set RAM y address count
|
||||||
|
self.command(_SSD1683_SET_RAMYCOUNT, bytearray([y & 0xFF, (y >> 8) & 0xFF]))
|
||||||
|
|
||||||
|
def set_ram_window(self, x1: int, y1: int, x2: int, y2: int) -> None:
|
||||||
|
"""Set the RAM window for partial updates"""
|
||||||
|
# Set ram X start/end position
|
||||||
|
self.command(_SSD1683_SET_RAMXPOS, bytearray([x1 & 0xFF, x2 & 0xFF]))
|
||||||
|
|
||||||
|
# Set ram Y start/end position
|
||||||
|
self.command(
|
||||||
|
_SSD1683_SET_RAMYPOS,
|
||||||
|
bytearray([y1 & 0xFF, (y1 >> 8) & 0xFF, y2 & 0xFF, (y2 >> 8) & 0xFF]),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _send_command_list(self, init_sequence: bytes) -> None:
|
||||||
|
"""Send a sequence of commands from an initialization list"""
|
||||||
|
i = 0
|
||||||
|
while i < len(init_sequence):
|
||||||
|
cmd = init_sequence[i]
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
if cmd == 0xFE: # End marker
|
||||||
|
break
|
||||||
|
elif cmd == 0xFF: # Delay marker
|
||||||
|
if i < len(init_sequence):
|
||||||
|
delay_ms = init_sequence[i]
|
||||||
|
i += 1
|
||||||
|
time.sleep(delay_ms / 1000.0)
|
||||||
|
elif i < len(init_sequence):
|
||||||
|
num_args = init_sequence[i]
|
||||||
|
i += 1
|
||||||
|
if num_args > 0 and (i + num_args) <= len(init_sequence):
|
||||||
|
args = init_sequence[i : i + num_args]
|
||||||
|
self.command(cmd, bytearray(args))
|
||||||
|
i += num_args
|
||||||
|
else:
|
||||||
|
self.command(cmd)
|
||||||
213
adafruit_epd/uc8179.py
Normal file
213
adafruit_epd/uc8179.py
Normal file
|
|
@ -0,0 +1,213 @@
|
||||||
|
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
"""
|
||||||
|
`adafruit_epd.uc8179` - Adafruit UC8179 - ePaper display driver
|
||||||
|
====================================================================================
|
||||||
|
CircuitPython driver for Adafruit UC8179 display breakouts
|
||||||
|
* Author(s): Liz Clark
|
||||||
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
import adafruit_framebuf
|
||||||
|
from micropython import const
|
||||||
|
|
||||||
|
from adafruit_epd.epd import Adafruit_EPD
|
||||||
|
|
||||||
|
try:
|
||||||
|
"""Needed for type annotations"""
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from busio import SPI
|
||||||
|
from digitalio import DigitalInOut
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
__version__ = "0.0.0+auto.0"
|
||||||
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
|
||||||
|
|
||||||
|
# UC8179 commands
|
||||||
|
_UC8179_PANELSETTING = const(0x00)
|
||||||
|
_UC8179_POWERSETTING = const(0x01)
|
||||||
|
_UC8179_POWEROFF = const(0x02)
|
||||||
|
_UC8179_POWERON = const(0x04)
|
||||||
|
_UC8179_DEEPSLEEP = const(0x07)
|
||||||
|
_UC8179_WRITE_RAM1 = const(0x10)
|
||||||
|
_UC8179_DATASTOP = const(0x11)
|
||||||
|
_UC8179_DISPLAYREFRESH = const(0x12)
|
||||||
|
_UC8179_WRITE_RAM2 = const(0x13)
|
||||||
|
_UC8179_DUALSPI = const(0x15)
|
||||||
|
_UC8179_WRITE_VCOM = const(0x50)
|
||||||
|
_UC8179_TCON = const(0x60)
|
||||||
|
_UC8179_TRES = const(0x61)
|
||||||
|
_UC8179_GET_STATUS = const(0x71)
|
||||||
|
|
||||||
|
BUSY_WAIT = const(500) # milliseconds
|
||||||
|
|
||||||
|
|
||||||
|
class Adafruit_UC8179(Adafruit_EPD):
|
||||||
|
"""driver class for Adafruit UC8179 ePaper display breakouts"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
width: int,
|
||||||
|
height: int,
|
||||||
|
spi: SPI,
|
||||||
|
*,
|
||||||
|
cs_pin: DigitalInOut,
|
||||||
|
dc_pin: DigitalInOut,
|
||||||
|
sramcs_pin: DigitalInOut,
|
||||||
|
rst_pin: DigitalInOut,
|
||||||
|
busy_pin: DigitalInOut,
|
||||||
|
) -> None:
|
||||||
|
# Adjust height to be divisible by 8 (direct from Arduino)
|
||||||
|
if (height % 8) != 0:
|
||||||
|
height += 8 - (height % 8)
|
||||||
|
|
||||||
|
super().__init__(width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin)
|
||||||
|
|
||||||
|
# Calculate buffer sizes exactly as Arduino does: width * height / 8
|
||||||
|
self._buffer1_size = width * height // 8
|
||||||
|
self._buffer2_size = self._buffer1_size
|
||||||
|
|
||||||
|
if sramcs_pin:
|
||||||
|
# Using external SRAM
|
||||||
|
self._buffer1 = self.sram.get_view(0)
|
||||||
|
self._buffer2 = self.sram.get_view(self._buffer1_size)
|
||||||
|
else:
|
||||||
|
# Using internal RAM
|
||||||
|
self._buffer1 = bytearray(self._buffer1_size)
|
||||||
|
self._buffer2 = bytearray(self._buffer2_size)
|
||||||
|
|
||||||
|
# Create frame buffers
|
||||||
|
self._framebuf1 = adafruit_framebuf.FrameBuffer(
|
||||||
|
self._buffer1,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
buf_format=adafruit_framebuf.MHMSB,
|
||||||
|
)
|
||||||
|
self._framebuf2 = adafruit_framebuf.FrameBuffer(
|
||||||
|
self._buffer2,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
buf_format=adafruit_framebuf.MHMSB,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set up which frame buffer is which color
|
||||||
|
self.set_black_buffer(0, True)
|
||||||
|
self.set_color_buffer(1, False)
|
||||||
|
|
||||||
|
# UC8179 uses single byte transactions
|
||||||
|
self._single_byte_tx = False
|
||||||
|
|
||||||
|
# Default refresh delay (from Adafruit_EPD base class in Arduino)
|
||||||
|
self.default_refresh_delay = 15 # seconds
|
||||||
|
# pylint: enable=too-many-arguments
|
||||||
|
|
||||||
|
def begin(self, reset: bool = True) -> None:
|
||||||
|
"""Begin communication with the display and set basic settings"""
|
||||||
|
if reset:
|
||||||
|
self.hardware_reset()
|
||||||
|
self.power_down()
|
||||||
|
|
||||||
|
def busy_wait(self) -> None:
|
||||||
|
"""Wait for display to be done with current task, either by polling the
|
||||||
|
busy pin, or pausing"""
|
||||||
|
if self._busy:
|
||||||
|
# Wait for busy pin to go HIGH
|
||||||
|
while not self._busy.value:
|
||||||
|
self.command(_UC8179_GET_STATUS)
|
||||||
|
time.sleep(0.1)
|
||||||
|
else:
|
||||||
|
# No busy pin, just wait
|
||||||
|
time.sleep(BUSY_WAIT / 1000.0)
|
||||||
|
# Additional delay after busy signal
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
def power_up(self) -> None:
|
||||||
|
"""Power up the display in preparation for writing RAM and updating"""
|
||||||
|
self.hardware_reset()
|
||||||
|
|
||||||
|
# Power setting
|
||||||
|
self.command(
|
||||||
|
_UC8179_POWERSETTING,
|
||||||
|
bytearray(
|
||||||
|
[
|
||||||
|
0x07, # VGH=20V
|
||||||
|
0x07, # VGL=-20V
|
||||||
|
0x3F, # VDH=15V
|
||||||
|
0x3F, # VDL=-15V
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Power on
|
||||||
|
self.command(_UC8179_POWERON)
|
||||||
|
time.sleep(0.1) # 100ms delay
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
# Panel setting
|
||||||
|
self.command(_UC8179_PANELSETTING, bytearray([0b011111])) # BW OTP LUT
|
||||||
|
|
||||||
|
# Resolution setting
|
||||||
|
self.command(
|
||||||
|
_UC8179_TRES,
|
||||||
|
bytearray(
|
||||||
|
[self._width >> 8, self._width & 0xFF, self._height >> 8, self._height & 0xFF]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Dual SPI setting
|
||||||
|
self.command(_UC8179_DUALSPI, bytearray([0x00]))
|
||||||
|
|
||||||
|
# VCOM setting
|
||||||
|
self.command(_UC8179_WRITE_VCOM, bytearray([0x10, 0x07]))
|
||||||
|
|
||||||
|
# TCON setting
|
||||||
|
self.command(_UC8179_TCON, bytearray([0x22]))
|
||||||
|
|
||||||
|
def power_down(self) -> None:
|
||||||
|
"""Power down the display - required when not actively displaying!"""
|
||||||
|
self.command(_UC8179_POWEROFF)
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
# Only deep sleep if we have a reset pin to wake it up
|
||||||
|
if self._rst:
|
||||||
|
self.command(_UC8179_DEEPSLEEP, bytearray([0x05]))
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
def update(self) -> None:
|
||||||
|
"""Update the display from internal memory"""
|
||||||
|
self.command(_UC8179_DISPLAYREFRESH)
|
||||||
|
time.sleep(0.1) # 100ms delay
|
||||||
|
self.busy_wait()
|
||||||
|
|
||||||
|
if not self._busy:
|
||||||
|
# If no busy pin, use default refresh delay
|
||||||
|
time.sleep(self.default_refresh_delay)
|
||||||
|
|
||||||
|
def write_ram(self, index: Literal[0, 1]) -> int:
|
||||||
|
"""Send the one byte command for starting the RAM write process. Returns
|
||||||
|
the byte read at the same time over SPI. index is the RAM buffer, can be
|
||||||
|
0 or 1 for tri-color displays."""
|
||||||
|
if index == 0:
|
||||||
|
return self.command(_UC8179_WRITE_RAM1, end=False)
|
||||||
|
if index == 1:
|
||||||
|
return self.command(_UC8179_WRITE_RAM2, end=False)
|
||||||
|
raise RuntimeError("RAM index must be 0 or 1")
|
||||||
|
|
||||||
|
def set_ram_address(self, x: int, y: int) -> None: # noqa: PLR6301, F841
|
||||||
|
"""Set the RAM address location, not used on this chipset but required by
|
||||||
|
the superclass"""
|
||||||
|
# Not used in UC8179 chip
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set_ram_window(self, x1: int, y1: int, x2: int, y2: int) -> None: # noqa: PLR6301, F841
|
||||||
|
"""Set the RAM window, not used on this chipset but required by
|
||||||
|
the superclass"""
|
||||||
|
# Not used in UC8179 chip
|
||||||
|
pass
|
||||||
|
|
@ -14,7 +14,9 @@ from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
||||||
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
||||||
from adafruit_epd.ssd1680 import Adafruit_SSD1680
|
from adafruit_epd.ssd1680 import Adafruit_SSD1680
|
||||||
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
||||||
|
from adafruit_epd.ssd1683 import Adafruit_SSD1683
|
||||||
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
||||||
|
from adafruit_epd.uc8179 import Adafruit_UC8179
|
||||||
|
|
||||||
# create the spi device and pins we will need
|
# create the spi device and pins we will need
|
||||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||||
|
|
@ -34,8 +36,11 @@ print("Creating display")
|
||||||
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
||||||
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
||||||
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
||||||
|
# display = Adafruit_UC8179(648, 480, # 5.83" mono 648x480 display
|
||||||
|
# display = Adafruit_UC8179(800, 480, # 7.5" mono 800x480 display
|
||||||
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
||||||
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
||||||
|
# display = Adafruit_SSD1683(400, 300, # 4.2" 300x400 Tri-Color display
|
||||||
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
||||||
display = Adafruit_IL0373(
|
display = Adafruit_IL0373(
|
||||||
104,
|
104,
|
||||||
|
|
@ -48,7 +53,9 @@ display = Adafruit_IL0373(
|
||||||
busy_pin=busy,
|
busy_pin=busy,
|
||||||
)
|
)
|
||||||
|
|
||||||
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
|
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY OR!
|
||||||
|
# UC8179 5.83" or 7.5" displays
|
||||||
|
# uncomment these lines!
|
||||||
# display.set_black_buffer(1, False)
|
# display.set_black_buffer(1, False)
|
||||||
# display.set_color_buffer(1, False)
|
# display.set_color_buffer(1, False)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,15 @@ from adafruit_epd.epd import Adafruit_EPD
|
||||||
from adafruit_epd.il0373 import Adafruit_IL0373
|
from adafruit_epd.il0373 import Adafruit_IL0373
|
||||||
from adafruit_epd.il0398 import Adafruit_IL0398
|
from adafruit_epd.il0398 import Adafruit_IL0398
|
||||||
from adafruit_epd.il91874 import Adafruit_IL91874
|
from adafruit_epd.il91874 import Adafruit_IL91874
|
||||||
|
from adafruit_epd.jd79661 import Adafruit_JD79661
|
||||||
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
||||||
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
||||||
from adafruit_epd.ssd1675b import Adafruit_SSD1675B
|
from adafruit_epd.ssd1675b import Adafruit_SSD1675B
|
||||||
from adafruit_epd.ssd1680 import Adafruit_SSD1680
|
from adafruit_epd.ssd1680 import Adafruit_SSD1680
|
||||||
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
||||||
|
from adafruit_epd.ssd1683 import Adafruit_SSD1683
|
||||||
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
||||||
|
from adafruit_epd.uc8179 import Adafruit_UC8179
|
||||||
# create the spi device and pins we will need
|
|
||||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
|
||||||
|
|
||||||
# create the spi device and pins we will need
|
# create the spi device and pins we will need
|
||||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||||
|
|
@ -32,14 +32,18 @@ busy = digitalio.DigitalInOut(board.D7) # can be None to not use this pin
|
||||||
|
|
||||||
# give them all to our driver
|
# give them all to our driver
|
||||||
print("Creating display")
|
print("Creating display")
|
||||||
|
# display = Adafruit_JD79661(122, 150, # 2.13" Quad-color display
|
||||||
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
||||||
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color display
|
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color display
|
||||||
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
|
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
|
||||||
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
||||||
|
# display = Adafruit_SSD1683(400, 300, # 4.2" 300x400 Tri-Color display
|
||||||
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
|
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
|
||||||
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
||||||
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
||||||
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
||||||
|
# display = Adafruit_UC8179(648, 480, # 5.83" mono 648x480 display
|
||||||
|
# display = Adafruit_UC8179(800, 480, # 7.5" mono 800x480 display
|
||||||
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
|
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
|
||||||
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
||||||
# display = Adafruit_IL0373(104, 212, # 2.13" Tri-color display
|
# display = Adafruit_IL0373(104, 212, # 2.13" Tri-color display
|
||||||
|
|
@ -54,7 +58,9 @@ display = Adafruit_SSD1675B(
|
||||||
busy_pin=busy,
|
busy_pin=busy,
|
||||||
)
|
)
|
||||||
|
|
||||||
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
|
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY OR!
|
||||||
|
# UC8179 5.83" or 7.5" displays
|
||||||
|
# uncomment these lines!
|
||||||
# display.set_black_buffer(1, False)
|
# display.set_black_buffer(1, False)
|
||||||
# display.set_color_buffer(1, False)
|
# display.set_color_buffer(1, False)
|
||||||
|
|
||||||
|
|
@ -70,6 +76,7 @@ height = display.height
|
||||||
image = Image.new("RGB", (width, height))
|
image = Image.new("RGB", (width, height))
|
||||||
|
|
||||||
WHITE = (0xFF, 0xFF, 0xFF)
|
WHITE = (0xFF, 0xFF, 0xFF)
|
||||||
|
YELLOW = (0xFF, 0xFF, 0x00)
|
||||||
RED = (0xFF, 0x00, 0x00)
|
RED = (0xFF, 0x00, 0x00)
|
||||||
BLACK = (0x00, 0x00, 0x00)
|
BLACK = (0x00, 0x00, 0x00)
|
||||||
|
|
||||||
|
|
@ -118,9 +125,15 @@ font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20)
|
||||||
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
|
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
|
||||||
# font = ImageFont.truetype('Minecraftia.ttf', 8)
|
# font = ImageFont.truetype('Minecraftia.ttf', 8)
|
||||||
|
|
||||||
|
if type(display) == Adafruit_JD79661:
|
||||||
|
# for quad color, test yellow
|
||||||
|
fill = YELLOW
|
||||||
|
else:
|
||||||
|
# otherwise, text is red
|
||||||
|
fill = RED
|
||||||
# Write two lines of text.
|
# Write two lines of text.
|
||||||
draw.text((x, top), "Hello", font=font, fill=RED)
|
draw.text((x, top), "Hello", font=font, fill=fill)
|
||||||
draw.text((x, top + 20), "World!", font=font, fill=RED)
|
draw.text((x, top + 20), "World!", font=font, fill=fill)
|
||||||
|
|
||||||
# Display image.
|
# Display image.
|
||||||
display.image(image)
|
display.image(image)
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,14 @@ from adafruit_epd.ek79686 import Adafruit_EK79686
|
||||||
from adafruit_epd.il0373 import Adafruit_IL0373
|
from adafruit_epd.il0373 import Adafruit_IL0373
|
||||||
from adafruit_epd.il0398 import Adafruit_IL0398
|
from adafruit_epd.il0398 import Adafruit_IL0398
|
||||||
from adafruit_epd.il91874 import Adafruit_IL91874
|
from adafruit_epd.il91874 import Adafruit_IL91874
|
||||||
|
from adafruit_epd.jd79661 import Adafruit_JD79661
|
||||||
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
||||||
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
||||||
from adafruit_epd.ssd1680 import Adafruit_SSD1680, Adafruit_SSD1680Z
|
from adafruit_epd.ssd1680 import Adafruit_SSD1680, Adafruit_SSD1680Z
|
||||||
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
||||||
|
from adafruit_epd.ssd1683 import Adafruit_SSD1683
|
||||||
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
||||||
|
from adafruit_epd.uc8179 import Adafruit_UC8179
|
||||||
|
|
||||||
# First define some color constants
|
# First define some color constants
|
||||||
WHITE = (0xFF, 0xFF, 0xFF)
|
WHITE = (0xFF, 0xFF, 0xFF)
|
||||||
|
|
@ -42,6 +45,7 @@ rst = digitalio.DigitalInOut(board.D27)
|
||||||
busy = digitalio.DigitalInOut(board.D17)
|
busy = digitalio.DigitalInOut(board.D17)
|
||||||
|
|
||||||
# give them all to our driver
|
# give them all to our driver
|
||||||
|
# display = Adafruit_JD79661(122, 150, # 2.13" Quad-color display
|
||||||
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
||||||
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
||||||
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color or mono display
|
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color or mono display
|
||||||
|
|
@ -51,8 +55,11 @@ busy = digitalio.DigitalInOut(board.D17)
|
||||||
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
||||||
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
||||||
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
||||||
|
# display = Adafruit_UC8179(648, 480, # 5.83" mono 648x480 display
|
||||||
|
# display = Adafruit_UC8179(800, 480, # 7.5" mono 800x480 display
|
||||||
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
||||||
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
||||||
|
# display = Adafruit_SSD1683(400, 300, # 4.2" 300x400 Tri-Color display
|
||||||
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
||||||
display = Adafruit_IL0373(
|
display = Adafruit_IL0373(
|
||||||
104,
|
104,
|
||||||
|
|
@ -65,7 +72,9 @@ display = Adafruit_IL0373(
|
||||||
busy_pin=busy,
|
busy_pin=busy,
|
||||||
)
|
)
|
||||||
|
|
||||||
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
|
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY OR!
|
||||||
|
# UC8179 5.83" or 7.5" displays
|
||||||
|
# uncomment these lines!
|
||||||
# display.set_black_buffer(1, False)
|
# display.set_black_buffer(1, False)
|
||||||
# display.set_color_buffer(1, False)
|
# display.set_color_buffer(1, False)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,14 @@ from adafruit_epd.ek79686 import Adafruit_EK79686
|
||||||
from adafruit_epd.il0373 import Adafruit_IL0373
|
from adafruit_epd.il0373 import Adafruit_IL0373
|
||||||
from adafruit_epd.il0398 import Adafruit_IL0398
|
from adafruit_epd.il0398 import Adafruit_IL0398
|
||||||
from adafruit_epd.il91874 import Adafruit_IL91874
|
from adafruit_epd.il91874 import Adafruit_IL91874
|
||||||
|
from adafruit_epd.jd79661 import Adafruit_JD79661
|
||||||
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
||||||
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
||||||
from adafruit_epd.ssd1680 import Adafruit_SSD1680, Adafruit_SSD1680Z
|
from adafruit_epd.ssd1680 import Adafruit_SSD1680, Adafruit_SSD1680Z
|
||||||
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
||||||
|
from adafruit_epd.ssd1683 import Adafruit_SSD1683
|
||||||
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
||||||
|
from adafruit_epd.uc8179 import Adafruit_UC8179
|
||||||
|
|
||||||
# create the spi device and pins we will need
|
# create the spi device and pins we will need
|
||||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||||
|
|
@ -32,6 +35,7 @@ rst = digitalio.DigitalInOut(board.D27)
|
||||||
busy = digitalio.DigitalInOut(board.D17)
|
busy = digitalio.DigitalInOut(board.D17)
|
||||||
|
|
||||||
# give them all to our driver
|
# give them all to our driver
|
||||||
|
# display = Adafruit_JD79661(122, 150, # 2.13" Quad-color display
|
||||||
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
||||||
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
||||||
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color or mono display
|
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color or mono display
|
||||||
|
|
@ -41,8 +45,11 @@ busy = digitalio.DigitalInOut(board.D17)
|
||||||
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
||||||
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
||||||
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
||||||
|
# display = Adafruit_UC8179(648, 480, # 5.83" mono 648x480 display
|
||||||
|
# display = Adafruit_UC8179(800, 480, # 7.5" mono 800x480 display
|
||||||
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
||||||
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
||||||
|
# display = Adafruit_SSD1683(400, 300, # 4.2" 300x400 Tri-Color display
|
||||||
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
||||||
display = Adafruit_IL0373(
|
display = Adafruit_IL0373(
|
||||||
104,
|
104,
|
||||||
|
|
@ -55,7 +62,9 @@ display = Adafruit_IL0373(
|
||||||
busy_pin=busy,
|
busy_pin=busy,
|
||||||
)
|
)
|
||||||
|
|
||||||
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
|
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY OR!
|
||||||
|
# UC8179 5.83" or 7.5" displays
|
||||||
|
# uncomment these lines!
|
||||||
# display.set_black_buffer(1, False)
|
# display.set_black_buffer(1, False)
|
||||||
# display.set_color_buffer(1, False)
|
# display.set_color_buffer(1, False)
|
||||||
|
|
||||||
|
|
@ -86,6 +95,38 @@ image = image.crop((x, y, x + display.width, y + display.height)).convert("RGB")
|
||||||
# Convert to Monochrome and Add dithering
|
# Convert to Monochrome and Add dithering
|
||||||
# image = image.convert("1").convert("L")
|
# image = image.convert("1").convert("L")
|
||||||
|
|
||||||
|
if type(display) == Adafruit_JD79661:
|
||||||
|
# Create a palette with the 4 colors: Black, White, Red, Yellow
|
||||||
|
# The palette needs 768 values (256 colors × 3 channels)
|
||||||
|
palette = []
|
||||||
|
|
||||||
|
# We'll map the 256 palette indices to our 4 colors
|
||||||
|
# 0-63: Black, 64-127: Red, 128-191: Yellow, 192-255: White
|
||||||
|
for i in range(256):
|
||||||
|
if i < 64:
|
||||||
|
palette.extend([0, 0, 0]) # Black
|
||||||
|
elif i < 128:
|
||||||
|
palette.extend([255, 0, 0]) # Red
|
||||||
|
elif i < 192:
|
||||||
|
palette.extend([255, 255, 0]) # Yellow
|
||||||
|
else:
|
||||||
|
palette.extend([255, 255, 255]) # White
|
||||||
|
|
||||||
|
# Create a palette image
|
||||||
|
palette_img = Image.new("P", (1, 1))
|
||||||
|
palette_img.putpalette(palette)
|
||||||
|
|
||||||
|
# Optional: Enhance colors before dithering for better results
|
||||||
|
# from PIL import ImageEnhance
|
||||||
|
# enhancer = ImageEnhance.Color(image)
|
||||||
|
# image = enhancer.enhance(1.5) # Increase color saturation
|
||||||
|
|
||||||
|
# Quantize the image using Floyd-Steinberg dithering
|
||||||
|
image = image.quantize(palette=palette_img, dither=Image.FLOYDSTEINBERG)
|
||||||
|
|
||||||
|
# Convert back to RGB for the display driver
|
||||||
|
image = image.convert("RGB")
|
||||||
|
|
||||||
# Display image.
|
# Display image.
|
||||||
display.image(image)
|
display.image(image)
|
||||||
display.display()
|
display.display()
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,14 @@ from adafruit_epd.epd import Adafruit_EPD
|
||||||
from adafruit_epd.il0373 import Adafruit_IL0373
|
from adafruit_epd.il0373 import Adafruit_IL0373
|
||||||
from adafruit_epd.il0398 import Adafruit_IL0398
|
from adafruit_epd.il0398 import Adafruit_IL0398
|
||||||
from adafruit_epd.il91874 import Adafruit_IL91874
|
from adafruit_epd.il91874 import Adafruit_IL91874
|
||||||
|
from adafruit_epd.jd79661 import Adafruit_JD79661
|
||||||
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
from adafruit_epd.ssd1608 import Adafruit_SSD1608
|
||||||
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
from adafruit_epd.ssd1675 import Adafruit_SSD1675
|
||||||
from adafruit_epd.ssd1680 import Adafruit_SSD1680, Adafruit_SSD1680Z
|
from adafruit_epd.ssd1680 import Adafruit_SSD1680, Adafruit_SSD1680Z
|
||||||
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
from adafruit_epd.ssd1681 import Adafruit_SSD1681
|
||||||
|
from adafruit_epd.ssd1683 import Adafruit_SSD1683
|
||||||
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
from adafruit_epd.uc8151d import Adafruit_UC8151D
|
||||||
|
from adafruit_epd.uc8179 import Adafruit_UC8179
|
||||||
|
|
||||||
# create the spi device and pins we will need
|
# create the spi device and pins we will need
|
||||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||||
|
|
@ -26,6 +29,7 @@ busy = digitalio.DigitalInOut(board.D5) # can be None to not use this pin
|
||||||
|
|
||||||
# give them all to our drivers
|
# give them all to our drivers
|
||||||
print("Creating display")
|
print("Creating display")
|
||||||
|
# display = Adafruit_JD79661(122, 150, # 2.13" Quad-color display
|
||||||
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
|
||||||
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
|
||||||
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color display
|
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color display
|
||||||
|
|
@ -35,8 +39,11 @@ print("Creating display")
|
||||||
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
# display = Adafruit_EK79686(176, 264, # 2.7" Tri-color display
|
||||||
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
|
||||||
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
|
||||||
|
# display = Adafruit_UC8179(648, 480, # 5.83" mono 648x480 display
|
||||||
|
# display = Adafruit_UC8179(800, 480, # 7.5" mono 800x480 display
|
||||||
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display IL0373
|
||||||
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
# display = Adafruit_SSD1680(128, 296, # 2.9" Tri-color display SSD1680
|
||||||
|
# display = Adafruit_SSD1683(400, 300, # 4.2" 300x400 Tri-Color display
|
||||||
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
|
||||||
display = Adafruit_IL0373(
|
display = Adafruit_IL0373(
|
||||||
104,
|
104,
|
||||||
|
|
@ -49,7 +56,9 @@ display = Adafruit_IL0373(
|
||||||
busy_pin=busy,
|
busy_pin=busy,
|
||||||
)
|
)
|
||||||
|
|
||||||
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
|
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY OR!
|
||||||
|
# UC8179 5.83" or 7.5" displays
|
||||||
|
# uncomment these lines!
|
||||||
# display.set_black_buffer(1, False)
|
# display.set_black_buffer(1, False)
|
||||||
# display.set_color_buffer(1, False)
|
# display.set_color_buffer(1, False)
|
||||||
|
|
||||||
|
|
@ -58,20 +67,33 @@ display = Adafruit_IL0373(
|
||||||
# display.set_color_buffer(1, True)
|
# display.set_color_buffer(1, True)
|
||||||
|
|
||||||
display.rotation = 1
|
display.rotation = 1
|
||||||
|
if type(display) == Adafruit_JD79661:
|
||||||
|
WHITE = Adafruit_JD79661.WHITE
|
||||||
|
BLACK = Adafruit_JD79661.BLACK
|
||||||
|
RED = Adafruit_JD79661.RED
|
||||||
|
YELLOW = Adafruit_JD79661.YELLOW
|
||||||
|
else:
|
||||||
|
WHITE = Adafruit_EPD.WHITE
|
||||||
|
BLACK = Adafruit_EPD.BLACK
|
||||||
|
RED = Adafruit_EPD.RED
|
||||||
|
|
||||||
# clear the buffer
|
# clear the buffer
|
||||||
print("Clear buffer")
|
print("Clear buffer")
|
||||||
display.fill(Adafruit_EPD.WHITE)
|
display.fill(WHITE)
|
||||||
display.pixel(10, 100, Adafruit_EPD.BLACK)
|
display.pixel(10, 100, BLACK)
|
||||||
|
|
||||||
print("Draw Rectangles")
|
print("Draw Rectangles")
|
||||||
display.fill_rect(5, 5, 10, 10, Adafruit_EPD.RED)
|
display.fill_rect(5, 5, 10, 10, RED)
|
||||||
display.rect(0, 0, 20, 30, Adafruit_EPD.BLACK)
|
display.rect(0, 0, 20, 30, BLACK)
|
||||||
|
|
||||||
print("Draw lines")
|
print("Draw lines")
|
||||||
display.line(0, 0, display.width - 1, display.height - 1, Adafruit_EPD.BLACK)
|
if type(display) == Adafruit_JD79661:
|
||||||
display.line(0, display.height - 1, display.width - 1, 0, Adafruit_EPD.RED)
|
display.line(0, 0, display.width - 1, display.height - 1, YELLOW)
|
||||||
|
display.line(0, display.height - 1, display.width - 1, 0, YELLOW)
|
||||||
|
else:
|
||||||
|
display.line(0, 0, display.width - 1, display.height - 1, BLACK)
|
||||||
|
display.line(0, display.height - 1, display.width - 1, 0, RED)
|
||||||
|
|
||||||
print("Draw text")
|
print("Draw text")
|
||||||
display.text("hello world", 25, 10, Adafruit_EPD.BLACK)
|
display.text("hello world", 25, 10, BLACK)
|
||||||
display.display()
|
display.display()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue