|
| 1 | +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +`adafruit_epd.EK79686` - Adafruit EK79686 - ePaper display driver |
| 7 | +==================================================================================== |
| 8 | +CircuitPython driver for Adafruit EK79686 display breakouts |
| 9 | +* Author(s): Melissa LeBlanc-Williams |
| 10 | +""" |
| 11 | + |
| 12 | +import time |
| 13 | +from micropython import const |
| 14 | +import adafruit_framebuf |
| 15 | +from adafruit_epd.epd import Adafruit_EPD |
| 16 | + |
| 17 | +try: |
| 18 | + "Needed for type annotations" |
| 19 | + import typing # pylint: disable=unused-import |
| 20 | + from typing_extensions import Literal |
| 21 | + from busio import SPI |
| 22 | + from digitalio import DigitalInOut |
| 23 | + |
| 24 | +except ImportError: |
| 25 | + pass |
| 26 | + |
| 27 | +__version__ = "0.0.0+auto.0" |
| 28 | +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" |
| 29 | + |
| 30 | +_EK79686_PANEL_SETTING = const(0x00) |
| 31 | +_EK79686_POWER_SETTING = const(0x01) |
| 32 | +_EK79686_POWER_OFF = const(0x02) |
| 33 | +_EK79686_POWER_OFF_SEQUENCE = const(0x03) |
| 34 | +_EK79686_POWER_ON = const(0x04) |
| 35 | +_EK79686_POWER_ON_MEASURE = const(0x05) |
| 36 | +_EK79686_BOOSTER_SOFT_START = const(0x06) |
| 37 | +_EK79686_DEEP_SLEEP = const(0x07) |
| 38 | +_EK79686_DTM1 = const(0x10) |
| 39 | +_EK79686_DATA_STOP = const(0x11) |
| 40 | +_EK79686_DISPLAY_REFRESH = const(0x12) |
| 41 | +_EK79686_DTM2 = const(0x13) |
| 42 | +_EK79686_PDTM1 = const(0x14) |
| 43 | +_EK79686_PDTM2 = const(0x15) |
| 44 | +_EK79686_PDRF = const(0x16) |
| 45 | +_EK79686_LUT1 = const(0x20) |
| 46 | +_EK79686_LUTWW = const(0x21) |
| 47 | +_EK79686_LUTBW = const(0x22) |
| 48 | +_EK79686_LUTWB = const(0x23) |
| 49 | +_EK79686_LUTBB = const(0x24) |
| 50 | +_EK79686_PLL = const(0x30) |
| 51 | +_EK79686_CDI = const(0x50) |
| 52 | +_EK79686_RESOLUTION = const(0x61) |
| 53 | +_EK79686_VCM_DC_SETTING = const(0x82) |
| 54 | + |
| 55 | + |
| 56 | +class Adafruit_EK79686(Adafruit_EPD): |
| 57 | + """driver class for Adafruit EK79686 ePaper display breakouts""" |
| 58 | + |
| 59 | + # pylint: disable=too-many-arguments |
| 60 | + def __init__( |
| 61 | + self, |
| 62 | + width: int, |
| 63 | + height: int, |
| 64 | + spi: SPI, |
| 65 | + *, |
| 66 | + cs_pin: DigitalInOut, |
| 67 | + dc_pin: DigitalInOut, |
| 68 | + sramcs_pin: DigitalInOut, |
| 69 | + rst_pin: DigitalInOut, |
| 70 | + busy_pin: DigitalInOut |
| 71 | + ) -> None: |
| 72 | + super().__init__( |
| 73 | + width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin |
| 74 | + ) |
| 75 | + |
| 76 | + self._buffer1_size = int(width * height / 8) |
| 77 | + self._buffer2_size = int(width * height / 8) |
| 78 | + |
| 79 | + if sramcs_pin: |
| 80 | + self._buffer1 = self.sram.get_view(0) |
| 81 | + self._buffer2 = self.sram.get_view(self._buffer1_size) |
| 82 | + else: |
| 83 | + self._buffer1 = bytearray((width * height) // 8) |
| 84 | + self._buffer2 = bytearray((width * height) // 8) |
| 85 | + # since we have *two* framebuffers - one for red and one for black |
| 86 | + # we dont subclass but manage manually |
| 87 | + self._framebuf1 = adafruit_framebuf.FrameBuffer( |
| 88 | + self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB |
| 89 | + ) |
| 90 | + self._framebuf2 = adafruit_framebuf.FrameBuffer( |
| 91 | + self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB |
| 92 | + ) |
| 93 | + self.set_black_buffer(0, True) |
| 94 | + self.set_color_buffer(1, False) |
| 95 | + self._single_byte_tx = False |
| 96 | + |
| 97 | + def begin(self, reset: bool = True) -> None: |
| 98 | + """Begin communication with the display and set basic settings""" |
| 99 | + if reset: |
| 100 | + self.hardware_reset() |
| 101 | + |
| 102 | + self.power_down() |
| 103 | + |
| 104 | + def busy_wait(self) -> None: |
| 105 | + """Wait for display to be done with current task, either by polling the |
| 106 | + busy pin, or pausing""" |
| 107 | + if self._busy: |
| 108 | + while not self._busy.value: |
| 109 | + time.sleep(0.01) |
| 110 | + else: |
| 111 | + time.sleep(0.5) |
| 112 | + |
| 113 | + def power_up(self) -> None: |
| 114 | + """Power up the display in preparation for writing RAM and updating""" |
| 115 | + self.hardware_reset() |
| 116 | + time.sleep(0.2) |
| 117 | + |
| 118 | + self.command(_EK79686_PANEL_SETTING, bytearray([0x0F])) # LUT from OTP 176x264 |
| 119 | + self.command(0x4D, bytearray([0xAA])) # FITI cmd (???) |
| 120 | + self.command(0x87, bytearray([0x28])) |
| 121 | + self.command(0x84, bytearray([0x00])) |
| 122 | + self.command(0x83, bytearray([0x05])) |
| 123 | + self.command(0xA8, bytearray([0xDF])) |
| 124 | + self.command(0xA9, bytearray([0x05])) |
| 125 | + self.command(0xB1, bytearray([0xE8])) |
| 126 | + self.command(0xAB, bytearray([0xA1])) |
| 127 | + self.command(0xB9, bytearray([0x10])) |
| 128 | + self.command(0x88, bytearray([0x80])) |
| 129 | + self.command(0x90, bytearray([0x02])) |
| 130 | + self.command(0x86, bytearray([0x15])) |
| 131 | + self.command(0x91, bytearray([0x8D])) |
| 132 | + self.command(0xAA, bytearray([0x0F])) |
| 133 | + self.command(_EK79686_POWER_ON) |
| 134 | + self.busy_wait() |
| 135 | + |
| 136 | + def power_down(self) -> None: |
| 137 | + """Power down the display - required when not actively displaying!""" |
| 138 | + self.command(_EK79686_POWER_OFF, bytearray([0x17])) |
| 139 | + self.busy_wait() |
| 140 | + |
| 141 | + if self._rst: # Only deep sleep if we can get out of it |
| 142 | + self.command(_EK79686_DEEP_SLEEP, bytearray([0xA5])) |
| 143 | + |
| 144 | + def update(self) -> None: |
| 145 | + """Update the display from internal memory""" |
| 146 | + self.command(_EK79686_DISPLAY_REFRESH) |
| 147 | + self.busy_wait() |
| 148 | + if not self._busy: |
| 149 | + time.sleep(16) # wait 16 seconds |
| 150 | + |
| 151 | + def write_ram(self, index: Literal[0, 1]) -> int: |
| 152 | + """Send the one byte command for starting the RAM write process. Returns |
| 153 | + the byte read at the same time over SPI. index is the RAM buffer, can be |
| 154 | + 0 or 1 for tri-color displays.""" |
| 155 | + if index == 0: |
| 156 | + return self.command(_EK79686_DTM1, end=False) |
| 157 | + if index == 1: |
| 158 | + return self.command(_EK79686_DTM2, end=False) |
| 159 | + raise RuntimeError("RAM index must be 0 or 1") |
| 160 | + |
| 161 | + def set_ram_address( |
| 162 | + self, x: int, y: int |
| 163 | + ) -> None: # pylint: disable=unused-argument, no-self-use |
| 164 | + """Set the RAM address location, not used on this chipset but required by |
| 165 | + the superclass""" |
| 166 | + return # on this chip it does nothing |
0 commit comments