|
| 1 | +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries |
| 2 | +# SPDX-FileCopyrightText: 2024 Joel Miller for Adafruit Industries |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | + |
| 6 | +""" |
| 7 | +`adafruit_epd.ssd1680b` - Adafruit SSD1680B - ePaper display driver |
| 8 | +==================================================================================== |
| 9 | +CircuitPython driver for Adafruit SSD1680B displays (GDEY0213B74 display module) |
| 10 | +* Author(s): Melissa LeBlanc-Williams, Joel Miller, Mikey Sklar |
| 11 | +""" |
| 12 | + |
| 13 | +import time |
| 14 | + |
| 15 | +import adafruit_framebuf |
| 16 | +from micropython import const |
| 17 | + |
| 18 | +from adafruit_epd.epd import Adafruit_EPD |
| 19 | + |
| 20 | +try: |
| 21 | + """Needed for type annotations""" |
| 22 | + import typing |
| 23 | + |
| 24 | + from busio import SPI |
| 25 | + from digitalio import DigitalInOut |
| 26 | + from typing_extensions import Literal |
| 27 | + |
| 28 | +except ImportError: |
| 29 | + pass |
| 30 | + |
| 31 | +__version__ = "0.0.0+auto.0" |
| 32 | +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" |
| 33 | + |
| 34 | +_SSD1680B_DRIVER_CONTROL = const(0x01) |
| 35 | +_SSD1680B_GATE_VOLTAGE = const(0x03) |
| 36 | +_SSD1680B_SOURCE_VOLTAGE = const(0x04) |
| 37 | +_SSD1680B_INIT_SETTING = const(0x08) |
| 38 | +_SSD1680B_INIT_WRITE_REG = const(0x09) |
| 39 | +_SSD1680B_INIT_READ_REG = const(0x0A) |
| 40 | +_SSD1680B_BOOSTER_SOFT_START = const(0x0C) |
| 41 | +_SSD1680B_DEEP_SLEEP = const(0x10) |
| 42 | +_SSD1680B_DATA_MODE = const(0x11) |
| 43 | +_SSD1680B_SW_RESET = const(0x12) |
| 44 | +_SSD1680B_HV_DETECT = const(0x14) |
| 45 | +_SSD1680B_VCI_DETECT = const(0x15) |
| 46 | +_SSD1680B_TEMP_CONTROL = const(0x18) |
| 47 | +_SSD1680B_TEMP_WRITE = const(0x1A) |
| 48 | +_SSD1680B_TEMP_READ = const(0x1B) |
| 49 | +_SSD1680B_EXTTEMP_WRITE = const(0x1C) |
| 50 | +_SSD1680B_MASTER_ACTIVATE = const(0x20) |
| 51 | +_SSD1680B_DISP_CTRL1 = const(0x21) |
| 52 | +_SSD1680B_DISP_CTRL2 = const(0x22) |
| 53 | +_SSD1680B_WRITE_BWRAM = const(0x24) |
| 54 | +_SSD1680B_WRITE_REDRAM = const(0x26) |
| 55 | +_SSD1680B_READ_RAM = const(0x27) |
| 56 | +_SSD1680B_VCOM_SENSE = const(0x28) |
| 57 | +_SSD1680B_VCOM_DURATION = const(0x29) |
| 58 | +_SSD1680B_WRITE_VCOM_OTP = const(0x2A) |
| 59 | +_SSD1680B_WRITE_VCOM_CTRL = const(0x2B) |
| 60 | +_SSD1680B_WRITE_VCOM_REG = const(0x2C) |
| 61 | +_SSD1680B_READ_OTP = const(0x2D) |
| 62 | +_SSD1680B_READ_USERID = const(0x2E) |
| 63 | +_SSD1680B_READ_STATUS = const(0x2F) |
| 64 | +_SSD1680B_WRITE_WS_OTP = const(0x30) |
| 65 | +_SSD1680B_LOAD_WS_OTP = const(0x31) |
| 66 | +_SSD1680B_WRITE_LUT = const(0x32) |
| 67 | +_SSD1680B_CRC_CALC = const(0x34) |
| 68 | +_SSD1680B_CRC_READ = const(0x35) |
| 69 | +_SSD1680B_PROG_OTP = const(0x36) |
| 70 | +_SSD1680B_WRITE_DISPLAY_OPT = const(0x37) |
| 71 | +_SSD1680B_WRITE_USERID = const(0x38) |
| 72 | +_SSD1680B_OTP_PROGMODE = const(0x39) |
| 73 | +_SSD1680B_WRITE_BORDER = const(0x3C) |
| 74 | +_SSD1680B_END_OPTION = const(0x3F) |
| 75 | +_SSD1680B_READ_RAM_OPT = const(0x41) |
| 76 | +_SSD1680B_SET_RAMXPOS = const(0x44) |
| 77 | +_SSD1680B_SET_RAMYPOS = const(0x45) |
| 78 | +_SSD1680B_AUTOWRITE_RED = const(0x46) |
| 79 | +_SSD1680B_AUTOWRITE_BW = const(0x47) |
| 80 | +_SSD1680B_SET_RAMXCOUNT = const(0x4E) |
| 81 | +_SSD1680B_SET_RAMYCOUNT = const(0x4F) |
| 82 | +_SSD1680B_NOP = const(0x7F) |
| 83 | + |
| 84 | + |
| 85 | +class Adafruit_SSD1680B(Adafruit_EPD): |
| 86 | + """ |
| 87 | + Driver class for Adafruit SSD1680 "B" ePaper displays. This class is meant |
| 88 | + to be used with Adafruit boards equipped with an SSD1680 driver chip paired |
| 89 | + with a GDEY0213B74 display module. |
| 90 | + """ |
| 91 | + |
| 92 | + def __init__( |
| 93 | + self, |
| 94 | + width: int, |
| 95 | + height: int, |
| 96 | + spi: SPI, |
| 97 | + *, |
| 98 | + cs_pin: DigitalInOut, |
| 99 | + dc_pin: DigitalInOut, |
| 100 | + sramcs_pin: DigitalInOut, |
| 101 | + rst_pin: DigitalInOut, |
| 102 | + busy_pin: DigitalInOut, |
| 103 | + ) -> None: |
| 104 | + super().__init__(width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin) |
| 105 | + |
| 106 | + stride = width |
| 107 | + if stride % 8 != 0: |
| 108 | + stride += 8 - stride % 8 |
| 109 | + |
| 110 | + self._buffer1_size = int(stride * height / 8) |
| 111 | + self._buffer2_size = self._buffer1_size |
| 112 | + |
| 113 | + if sramcs_pin: |
| 114 | + self._buffer1 = self.sram.get_view(0) |
| 115 | + self._buffer2 = self.sram.get_view(self._buffer1_size) |
| 116 | + else: |
| 117 | + self._buffer1 = bytearray(self._buffer1_size) |
| 118 | + self._buffer2 = bytearray(self._buffer2_size) |
| 119 | + |
| 120 | + self._framebuf1 = adafruit_framebuf.FrameBuffer( |
| 121 | + self._buffer1, |
| 122 | + width, |
| 123 | + height, |
| 124 | + stride=stride, |
| 125 | + buf_format=adafruit_framebuf.MHMSB, |
| 126 | + ) |
| 127 | + self._framebuf2 = adafruit_framebuf.FrameBuffer( |
| 128 | + self._buffer2, |
| 129 | + width, |
| 130 | + height, |
| 131 | + stride=stride, |
| 132 | + buf_format=adafruit_framebuf.MHMSB, |
| 133 | + ) |
| 134 | + self.set_black_buffer(0, True) |
| 135 | + self.set_color_buffer(1, False) |
| 136 | + |
| 137 | + def begin(self, reset: bool = True) -> None: |
| 138 | + """Begin communication with the display and set basic settings""" |
| 139 | + if reset: |
| 140 | + self.hardware_reset() |
| 141 | + self.power_down() |
| 142 | + |
| 143 | + def busy_wait(self) -> None: |
| 144 | + """ |
| 145 | + Wait for display to be done with current task, either by polling the |
| 146 | + busy pin, or pausing |
| 147 | + """ |
| 148 | + if self._busy: |
| 149 | + while self._busy.value: |
| 150 | + time.sleep(0.01) |
| 151 | + else: |
| 152 | + time.sleep(0.5) |
| 153 | + |
| 154 | + def power_up(self) -> None: |
| 155 | + """Power up the display in preparation for writing RAM and updating""" |
| 156 | + self.hardware_reset() |
| 157 | + self.busy_wait() |
| 158 | + self.command(_SSD1680B_SW_RESET) |
| 159 | + self.busy_wait() |
| 160 | + # driver output control |
| 161 | + self.command( |
| 162 | + _SSD1680B_DRIVER_CONTROL, |
| 163 | + bytearray([self._height, self._height >> 8, 0x00]), |
| 164 | + ) |
| 165 | + # data entry mode |
| 166 | + self.command(_SSD1680B_DATA_MODE, bytearray([0x03])) |
| 167 | + |
| 168 | + # Set voltages |
| 169 | + self.command(_SSD1680B_WRITE_VCOM_REG, bytearray([0x36])) |
| 170 | + self.command(_SSD1680B_GATE_VOLTAGE, bytearray([0x17])) |
| 171 | + self.command(_SSD1680B_SOURCE_VOLTAGE, bytearray([0x41, 0x00, 0x32])) |
| 172 | + |
| 173 | + # Set ram X start/end postion |
| 174 | + self.command(_SSD1680B_SET_RAMXPOS, bytearray([0x00, self._width // 8])) |
| 175 | + # Set ram Y start/end postion |
| 176 | + self.command( |
| 177 | + _SSD1680B_SET_RAMYPOS, |
| 178 | + bytearray([0, 0, self._height, self._height >> 8]), |
| 179 | + ) |
| 180 | + # Set border waveform |
| 181 | + self.command(_SSD1680B_WRITE_BORDER, bytearray([0x05])) |
| 182 | + |
| 183 | + # Set ram X count |
| 184 | + self.command(_SSD1680B_SET_RAMXCOUNT, bytearray([0x01])) |
| 185 | + # Set ram Y count |
| 186 | + self.command(_SSD1680B_SET_RAMYCOUNT, bytearray([self._height, 0])) |
| 187 | + self.busy_wait() |
| 188 | + |
| 189 | + def power_down(self) -> None: |
| 190 | + """Power down the display - required when not actively displaying!""" |
| 191 | + self.command(_SSD1680B_DEEP_SLEEP, bytearray([0x01])) |
| 192 | + time.sleep(0.1) |
| 193 | + |
| 194 | + def update(self) -> None: |
| 195 | + """Update the display from internal memory""" |
| 196 | + self.command(_SSD1680B_DISP_CTRL2, bytearray([0xF7])) |
| 197 | + self.command(_SSD1680B_MASTER_ACTIVATE) |
| 198 | + self.busy_wait() |
| 199 | + if not self._busy: |
| 200 | + time.sleep(3) # wait 3 seconds |
| 201 | + |
| 202 | + def write_ram(self, index: Literal[0, 1]) -> int: |
| 203 | + """ |
| 204 | + Send the one byte command for starting the RAM write process. Returns |
| 205 | + the byte read at the same time over SPI. index is the RAM buffer, can |
| 206 | + be 0 or 1 for tri-color displays. |
| 207 | + """ |
| 208 | + if index == 0: |
| 209 | + return self.command(_SSD1680B_WRITE_BWRAM, end=False) |
| 210 | + if index == 1: |
| 211 | + return self.command(_SSD1680B_WRITE_REDRAM, end=False) |
| 212 | + raise RuntimeError("RAM index must be 0 or 1") |
| 213 | + |
| 214 | + def set_ram_address(self, x: int, y: int) -> None: # noqa: PLR6301, F841 |
| 215 | + """Set the RAM address location""" |
| 216 | + # Set RAM X address counter |
| 217 | + self.command(_SSD1680B_SET_RAMXCOUNT, bytearray([x])) |
| 218 | + # Set RAM Y address counter |
| 219 | + self.command(_SSD1680B_SET_RAMYCOUNT, bytearray([y, y >> 8])) |
0 commit comments