|
| 1 | +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +`adafruit_epd.ssd1681` - Adafruit SSD1681 - ePaper display driver |
| 7 | +==================================================================================== |
| 8 | +CircuitPython driver for Adafruit SSD1681 display breakouts |
| 9 | +* Author(s): Dean Miller, Ladyada |
| 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 | +_SSD1681_DRIVER_CONTROL = const(0x01) |
| 21 | +_SSD1681_GATE_VOLTAGE = const(0x03) |
| 22 | +_SSD1681_SOURCE_VOLTAGE = const(0x04) |
| 23 | +_SSD1681_INIT_SETTING = const(0x08) |
| 24 | +_SSD1681_INIT_WRITE_REG = const(0x09) |
| 25 | +_SSD1681_INIT_READ_REG = const(0x0A) |
| 26 | +_SSD1681_BOOSTER_SOFT_START = const(0x0C) |
| 27 | +_SSD1681_DEEP_SLEEP = const(0x10) |
| 28 | +_SSD1681_DATA_MODE = const(0x11) |
| 29 | +_SSD1681_SW_RESET = const(0x12) |
| 30 | +_SSD1681_HV_DETECT = const(0x14) |
| 31 | +_SSD1681_VCI_DETECT = const(0x15) |
| 32 | +_SSD1681_TEMP_CONTROL = const(0x18) |
| 33 | +_SSD1681_TEMP_WRITE = const(0x1A) |
| 34 | +_SSD1681_TEMP_READ = const(0x1B) |
| 35 | +_SSD1681_EXTTEMP_WRITE = const(0x1C) |
| 36 | +_SSD1681_MASTER_ACTIVATE = const(0x20) |
| 37 | +_SSD1681_DISP_CTRL1 = const(0x21) |
| 38 | +_SSD1681_DISP_CTRL2 = const(0x22) |
| 39 | +_SSD1681_WRITE_BWRAM = const(0x24) |
| 40 | +_SSD1681_WRITE_REDRAM = const(0x26) |
| 41 | +_SSD1681_READ_RAM = const(0x27) |
| 42 | +_SSD1681_VCOM_SENSE = const(0x28) |
| 43 | +_SSD1681_VCOM_DURATION = const(0x29) |
| 44 | +_SSD1681_WRITE_VCOM_OTP = const(0x2A) |
| 45 | +_SSD1681_WRITE_VCOM_CTRL = const(0x2B) |
| 46 | +_SSD1681_WRITE_VCOM_REG = const(0x2C) |
| 47 | +_SSD1681_READ_OTP = const(0x2D) |
| 48 | +_SSD1681_READ_USERID = const(0x2E) |
| 49 | +_SSD1681_READ_STATUS = const(0x2F) |
| 50 | +_SSD1681_WRITE_WS_OTP = const(0x30) |
| 51 | +_SSD1681_LOAD_WS_OTP = const(0x31) |
| 52 | +_SSD1681_WRITE_LUT = const(0x32) |
| 53 | +_SSD1681_CRC_CALC = const(0x34) |
| 54 | +_SSD1681_CRC_READ = const(0x35) |
| 55 | +_SSD1681_PROG_OTP = const(0x36) |
| 56 | +_SSD1681_WRITE_DISPLAY_OPT = const(0x37) |
| 57 | +_SSD1681_WRITE_USERID = const(0x38) |
| 58 | +_SSD1681_OTP_PROGMODE = const(0x39) |
| 59 | +_SSD1681_WRITE_BORDER = const(0x3C) |
| 60 | +_SSD1681_END_OPTION = const(0x3F) |
| 61 | +_SSD1681_SET_RAMXPOS = const(0x44) |
| 62 | +_SSD1681_SET_RAMYPOS = const(0x45) |
| 63 | +_SSD1681_AUTOWRITE_RED = const(0x46) |
| 64 | +_SSD1681_AUTOWRITE_BW = const(0x47) |
| 65 | +_SSD1681_SET_RAMXCOUNT = const(0x4E) |
| 66 | +_SSD1681_SET_RAMYCOUNT = const(0x4F) |
| 67 | +_SSD1681_NOP = const(0xFF) |
| 68 | + |
| 69 | +_LUT_DATA = b'\x02\x02\x01\x11\x12\x12""fiiYX\x99\x99\x88\x00\x00\x00\x00\xf8\xb4\x13Q5QQ\x19\x01\x00' # pylint: disable=line-too-long |
| 70 | + |
| 71 | + |
| 72 | +class Adafruit_SSD1681(Adafruit_EPD): |
| 73 | + """driver class for Adafruit SSD1681 ePaper display breakouts""" |
| 74 | + |
| 75 | + # pylint: disable=too-many-arguments |
| 76 | + def __init__( |
| 77 | + self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin |
| 78 | + ): |
| 79 | + super().__init__( |
| 80 | + width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin |
| 81 | + ) |
| 82 | + |
| 83 | + if height % 8 != 0: |
| 84 | + height += 8 - height % 8 |
| 85 | + self._height = height |
| 86 | + |
| 87 | + self._buffer1_size = int(width * height / 8) |
| 88 | + |
| 89 | + if sramcs_pin: |
| 90 | + self._buffer1 = self.sram.get_view(0) |
| 91 | + else: |
| 92 | + self._buffer1 = bytearray((width * height) // 8) |
| 93 | + self._framebuf1 = adafruit_framebuf.FrameBuffer( |
| 94 | + self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB |
| 95 | + ) |
| 96 | + self.set_black_buffer(0, True) |
| 97 | + self.set_color_buffer(0, True) |
| 98 | + # pylint: enable=too-many-arguments |
| 99 | + |
| 100 | + def begin(self, reset=True): |
| 101 | + """Begin communication with the display and set basic settings""" |
| 102 | + if reset: |
| 103 | + self.hardware_reset() |
| 104 | + self.power_down() |
| 105 | + |
| 106 | + def busy_wait(self): |
| 107 | + """Wait for display to be done with current task, either by polling the |
| 108 | + busy pin, or pausing""" |
| 109 | + if self._busy: |
| 110 | + while self._busy.value: |
| 111 | + time.sleep(0.01) |
| 112 | + else: |
| 113 | + time.sleep(0.5) |
| 114 | + |
| 115 | + def power_up(self): |
| 116 | + """Power up the display in preparation for writing RAM and updating""" |
| 117 | + self.hardware_reset() |
| 118 | + self.busy_wait() |
| 119 | + self.command(_SSD1681_SW_RESET) |
| 120 | + self.busy_wait() |
| 121 | + # driver output control |
| 122 | + self.command( |
| 123 | + _SSD1681_DRIVER_CONTROL, |
| 124 | + bytearray([self._width - 1, (self._width - 1) >> 8, 0x00]), |
| 125 | + ) |
| 126 | + # data entry mode |
| 127 | + self.command(_SSD1681_DATA_MODE, bytearray([0x03])) |
| 128 | + # Set ram X start/end postion |
| 129 | + self.command(_SSD1681_SET_RAMXPOS, bytearray([0x00, self._height // 8 - 1])) |
| 130 | + # Set ram Y start/end postion |
| 131 | + self.command( |
| 132 | + _SSD1681_SET_RAMYPOS, |
| 133 | + bytearray([0, 0, self._height - 1, (self._height - 1) >> 8]), |
| 134 | + ) |
| 135 | + # Set border waveform |
| 136 | + self.command(_SSD1681_WRITE_BORDER, bytearray([0x05])) |
| 137 | + # Set temperature control |
| 138 | + self.command(_SSD1681_TEMP_CONTROL, bytearray([0x80])) |
| 139 | + |
| 140 | + self.busy_wait() |
| 141 | + |
| 142 | + def power_down(self): |
| 143 | + """Power down the display - required when not actively displaying!""" |
| 144 | + self.command(_SSD1681_DEEP_SLEEP, bytearray([0x01])) |
| 145 | + time.sleep(0.1) |
| 146 | + |
| 147 | + def update(self): |
| 148 | + """Update the display from internal memory""" |
| 149 | + self.command(_SSD1681_DISP_CTRL2, bytearray([0xF7])) |
| 150 | + self.command(_SSD1681_MASTER_ACTIVATE) |
| 151 | + self.busy_wait() |
| 152 | + if not self._busy: |
| 153 | + time.sleep(3) # wait 3 seconds |
| 154 | + |
| 155 | + def write_ram(self, index): |
| 156 | + """Send the one byte command for starting the RAM write process. Returns |
| 157 | + the byte read at the same time over SPI. index is the RAM buffer, can be |
| 158 | + 0 or 1 for tri-color displays.""" |
| 159 | + if index == 0: |
| 160 | + return self.command(_SSD1681_WRITE_BWRAM, end=False) |
| 161 | + raise RuntimeError("RAM index must be 0") |
| 162 | + |
| 163 | + def set_ram_address(self, x, y): # 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 | + # Set RAM X address counter |
| 167 | + self.command(_SSD1681_SET_RAMXCOUNT, bytearray([x])) |
| 168 | + # Set RAM Y address counter |
| 169 | + self.command(_SSD1681_SET_RAMYCOUNT, bytearray([y >> 8, y])) |
0 commit comments