|
| 1 | +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +`adafruit_epd.uc8151d` - Adafruit UC8151D - ePaper display driver |
| 7 | +==================================================================================== |
| 8 | +CircuitPython driver for Adafruit UC8151D display breakouts |
| 9 | +* Author(s): Dean Miller |
| 10 | +""" |
| 11 | + |
| 12 | +import time |
| 13 | +from micropython import const |
| 14 | +import adafruit_framebuf |
| 15 | +from adafruit_epd.epd import Adafruit_EPD |
| 16 | + |
| 17 | +__version__ = "0.0.0-auto.0" |
| 18 | +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" |
| 19 | + |
| 20 | +_UC8151D_PANEL_SETTING = const(0x00) |
| 21 | +_UC8151D_POWER_SETTING = const(0x01) |
| 22 | +_UC8151D_POWER_OFF = const(0x02) |
| 23 | +_UC8151D_POWER_OFF_SEQUENCE = const(0x03) |
| 24 | +_UC8151D_POWER_ON = const(0x04) |
| 25 | +_UC8151D_POWER_ON_MEASURE = const(0x05) |
| 26 | +_UC8151D_BOOSTER_SOFT_START = const(0x06) |
| 27 | +_UC8151D_DEEP_SLEEP = const(0x07) |
| 28 | +_UC8151D_DTM1 = const(0x10) |
| 29 | +_UC8151D_DATA_STOP = const(0x11) |
| 30 | +_UC8151D_DISPLAY_REFRESH = const(0x12) |
| 31 | +_UC8151D_DTM2 = const(0x13) |
| 32 | +_UC8151D_AUTO = const(0x17) |
| 33 | +_UC8151D_LUTOPT = const(0x2A) |
| 34 | +_UC8151D_PLL = const(0x30) |
| 35 | +_UC8151D_TSC = const(0x40) |
| 36 | +_UC8151D_TSE = const(0x41) |
| 37 | +_UC8151D_TSW = const(0x42) |
| 38 | +_UC8151D_TSR = const(0x43) |
| 39 | +_UC8151D_PBC = const(0x44) |
| 40 | +_UC8151D_CDI = const(0x50) |
| 41 | +_UC8151D_LPD = const(0x51) |
| 42 | +_UC8151D_TRES = const(0x65) |
| 43 | +_UC8151D_GSST = const(0x70) |
| 44 | +_UC8151D_REV = const(0x70) |
| 45 | +_UC8151D_FLG = const(0x71) |
| 46 | +_UC8151D_AMV = const(0x80) |
| 47 | +_UC8151D_VV = const(0x81) |
| 48 | +_UC8151D_VCM_DC_SETTING = const(0x82) |
| 49 | +_UC8151D_PTL = const(0x90) |
| 50 | +_UC8151D_PTIN = const(0x91) |
| 51 | +_UC8151D_PTOUT = const(0x92) |
| 52 | +_UC8151D_PGM = const(0xA0) |
| 53 | +_UC8151D_APG = const(0xA1) |
| 54 | +_UC8151D_ROTP = const(0xA2) |
| 55 | +_UC8151D_CCSET = const(0xE0) |
| 56 | +_UC8151D_PWS = const(0xE3) |
| 57 | +_UC8151D_LVSEL = const(0xE4) |
| 58 | +_UC8151D_TSSET = const(0xE5) |
| 59 | + |
| 60 | + |
| 61 | +class Adafruit_UC8151D(Adafruit_EPD): |
| 62 | + """driver class for Adafruit UC8151D ePaper display breakouts""" |
| 63 | + |
| 64 | + # pylint: disable=too-many-arguments |
| 65 | + def __init__( |
| 66 | + self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin |
| 67 | + ): |
| 68 | + super().__init__( |
| 69 | + width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin |
| 70 | + ) |
| 71 | + |
| 72 | + self._buffer1_size = int(width * height / 8) |
| 73 | + self._buffer2_size = int(width * height / 8) |
| 74 | + |
| 75 | + if sramcs_pin: |
| 76 | + self._buffer1 = self.sram.get_view(0) |
| 77 | + self._buffer2 = self.sram.get_view(self._buffer1_size) |
| 78 | + else: |
| 79 | + self._buffer1 = bytearray((width * height) // 8) |
| 80 | + self._buffer2 = bytearray((width * height) // 8) |
| 81 | + # since we have *two* framebuffers - one for red and one for black |
| 82 | + # we dont subclass but manage manually |
| 83 | + self._framebuf1 = adafruit_framebuf.FrameBuffer( |
| 84 | + self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB |
| 85 | + ) |
| 86 | + self._framebuf2 = adafruit_framebuf.FrameBuffer( |
| 87 | + self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB |
| 88 | + ) |
| 89 | + self.set_black_buffer(0, True) |
| 90 | + self.set_color_buffer(1, True) |
| 91 | + # pylint: enable=too-many-arguments |
| 92 | + |
| 93 | + def begin(self, reset=True): |
| 94 | + """Begin communication with the display and set basic settings""" |
| 95 | + if reset: |
| 96 | + self.hardware_reset() |
| 97 | + self.power_down() |
| 98 | + |
| 99 | + def busy_wait(self): |
| 100 | + """Wait for display to be done with current task, either by polling the |
| 101 | + busy pin, or pausing""" |
| 102 | + if self._busy: |
| 103 | + while not self._busy.value: |
| 104 | + time.sleep(0.01) |
| 105 | + else: |
| 106 | + time.sleep(0.5) |
| 107 | + |
| 108 | + def power_up(self): |
| 109 | + """Power up the display in preparation for writing RAM and updating""" |
| 110 | + self.hardware_reset() |
| 111 | + self.busy_wait() |
| 112 | + |
| 113 | + self.command(_UC8151D_POWER_ON) |
| 114 | + |
| 115 | + self.busy_wait() |
| 116 | + time.sleep(0.01) |
| 117 | + |
| 118 | + self.command(_UC8151D_PANEL_SETTING, bytearray([0x1F])) |
| 119 | + self.command(_UC8151D_CDI, bytearray([0x97])) |
| 120 | + time.sleep(0.05) |
| 121 | + |
| 122 | + def power_down(self): |
| 123 | + """Power down the display - required when not actively displaying!""" |
| 124 | + self.command(_UC8151D_CDI, bytearray([0xF7])) |
| 125 | + self.command(_UC8151D_POWER_OFF) |
| 126 | + self.busy_wait() |
| 127 | + self.command(_UC8151D_DEEP_SLEEP, bytearray([0xA5])) |
| 128 | + |
| 129 | + def update(self): |
| 130 | + """Update the display from internal memory""" |
| 131 | + self.command(_UC8151D_DISPLAY_REFRESH) |
| 132 | + time.sleep(0.1) |
| 133 | + self.busy_wait() |
| 134 | + if not self._busy: |
| 135 | + time.sleep(15) # wait 15 seconds |
| 136 | + |
| 137 | + def write_ram(self, index): |
| 138 | + """Send the one byte command for starting the RAM write process. Returns |
| 139 | + the byte read at the same time over SPI. index is the RAM buffer, can be |
| 140 | + 0 or 1 for tri-color displays.""" |
| 141 | + if index == 0: |
| 142 | + return self.command(_UC8151D_DTM1, end=False) |
| 143 | + if index == 1: |
| 144 | + return self.command(_UC8151D_DTM2, end=False) |
| 145 | + raise RuntimeError("RAM index must be 0 or 1") |
| 146 | + |
| 147 | + def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use |
| 148 | + """Set the RAM address location, not used on this chipset but required by |
| 149 | + the superclass""" |
| 150 | + return # on this chip it does nothing |
0 commit comments