update power_up
This commit is contained in:
parent
a04a6a8d48
commit
5ea27cf74b
1 changed files with 42 additions and 81 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: 2024
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
`adafruit_epd.uc8179` - Adafruit UC8179 - ePaper display driver
|
||||
====================================================================================
|
||||
CircuitPython driver for Adafruit UC8179 display breakouts
|
||||
* Author(s): Liz Clark
|
||||
* Author(s): Your Name Here
|
||||
"""
|
||||
|
||||
import time
|
||||
|
|
@ -52,31 +52,6 @@ BUSY_WAIT = const(500) # milliseconds
|
|||
class Adafruit_UC8179(Adafruit_EPD):
|
||||
"""driver class for Adafruit UC8179 ePaper display breakouts"""
|
||||
|
||||
# Default initialization sequence
|
||||
_default_init_code = bytes([
|
||||
_UC8179_POWERSETTING, 4,
|
||||
0x07, # VGH=20V
|
||||
0x07, # VGL=-20V
|
||||
0x3F, # VDH=15V
|
||||
0x3F, # VDL=-15V
|
||||
|
||||
_UC8179_POWERON, 0,
|
||||
0xFF, 100, # busy wait
|
||||
|
||||
_UC8179_PANELSETTING, 1,
|
||||
0b010111, # BW OTP LUT
|
||||
|
||||
_UC8179_TRES, 4,
|
||||
0x02, 0x88, 0x01, 0xE0,
|
||||
|
||||
_UC8179_DUALSPI, 1, 0x00,
|
||||
|
||||
_UC8179_WRITE_VCOM, 2, 0x10, 0x07,
|
||||
_UC8179_TCON, 1, 0x22,
|
||||
|
||||
0xFE # End marker
|
||||
])
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
width: int,
|
||||
|
|
@ -125,32 +100,18 @@ class Adafruit_UC8179(Adafruit_EPD):
|
|||
# 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 = True
|
||||
|
||||
# Custom init code if needed
|
||||
self._epd_init_code = None
|
||||
|
||||
# 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"""
|
||||
# Direct port of Arduino begin() method
|
||||
|
||||
# Note: Arduino sets _data_entry_mode = THINKINK_UC8179
|
||||
# This appears to be specific to SRAM organization for this chip
|
||||
|
||||
if reset:
|
||||
self.hardware_reset()
|
||||
|
||||
# Black buffer defaults to inverted (0 means black)
|
||||
self.set_black_buffer(0, True)
|
||||
# Red/color buffer defaults to not inverted (1 means red)
|
||||
self.set_color_buffer(1, False)
|
||||
|
||||
self.power_down()
|
||||
|
||||
def busy_wait(self) -> None:
|
||||
|
|
@ -170,24 +131,50 @@ class Adafruit_UC8179(Adafruit_EPD):
|
|||
def power_up(self) -> None:
|
||||
"""Power up the display in preparation for writing RAM and updating"""
|
||||
self.hardware_reset()
|
||||
|
||||
# Use custom init code if provided, otherwise use default
|
||||
init_code = self._epd_init_code if self._epd_init_code else self._default_init_code
|
||||
|
||||
# Process initialization sequence
|
||||
self._command_list(init_code)
|
||||
|
||||
# Set display resolution (using WIDTH and HEIGHT macros in Arduino)
|
||||
|
||||
# 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([0b010111])) # BW OTP LUT
|
||||
|
||||
# Resolution setting
|
||||
self.command(
|
||||
_UC8179_TRES,
|
||||
bytearray([self._width >> 8, self._width & 0xFF, self._height >> 8, self._height & 0xFF]),
|
||||
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]))
|
||||
|
|
@ -196,12 +183,12 @@ class Adafruit_UC8179(Adafruit_EPD):
|
|||
def update(self) -> None:
|
||||
"""Update the display from internal memory"""
|
||||
self.command(_UC8179_DISPLAYREFRESH)
|
||||
time.sleep(0.1)
|
||||
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 / 1000.0)
|
||||
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
|
||||
|
|
@ -224,29 +211,3 @@ class Adafruit_UC8179(Adafruit_EPD):
|
|||
the superclass"""
|
||||
# Not used in UC8179 chip
|
||||
pass
|
||||
|
||||
def _command_list(self, init_sequence: bytes) -> None:
|
||||
"""Process a command list for initialization"""
|
||||
i = 0
|
||||
while i < len(init_sequence):
|
||||
cmd = init_sequence[i]
|
||||
i += 1
|
||||
|
||||
# Check for end marker
|
||||
if cmd == 0xFE:
|
||||
break
|
||||
|
||||
# Get number of data bytes
|
||||
num_data = init_sequence[i]
|
||||
i += 1
|
||||
|
||||
# Check for delay command (0xFF)
|
||||
if cmd == 0xFF:
|
||||
time.sleep(num_data / 1000.0)
|
||||
else:
|
||||
# Send command with data if any
|
||||
if num_data > 0:
|
||||
self.command(cmd, bytearray(init_sequence[i:i + num_data]))
|
||||
i += num_data
|
||||
else:
|
||||
self.command(cmd)
|
||||
Loading…
Reference in a new issue