|
| 1 | +# The MIT License (MIT) |
| 2 | +# |
| 3 | +# Copyright (c) 2018 Dean Miller for Adafruit Industries |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +# THE SOFTWARE. |
| 22 | +""" |
| 23 | +`adafruit_epd.il91874` - Adafruit IL91874 - ePaper display driver |
| 24 | +==================================================================================== |
| 25 | +CircuitPython driver for Adafruit IL91874 display breakouts |
| 26 | +* Author(s): Dean Miller, Ladyada |
| 27 | +""" |
| 28 | + |
| 29 | +import time |
| 30 | +from micropython import const |
| 31 | +import adafruit_framebuf |
| 32 | +from adafruit_epd.epd import Adafruit_EPD |
| 33 | + |
| 34 | +_IL91874_PANEL_SETTING = const(0x00) |
| 35 | +_IL91874_POWER_SETTING = const(0x01) |
| 36 | +_IL91874_POWER_OFF = const(0x02) |
| 37 | +_IL91874_POWER_OFF_SEQUENCE = const(0x03) |
| 38 | +_IL91874_POWER_ON = const(0x04) |
| 39 | +_IL91874_POWER_ON_MEASURE = const(0x05) |
| 40 | +_IL91874_BOOSTER_SOFT_START = const(0x06) |
| 41 | +_IL91874_DEEP_SLEEP = const(0x07) |
| 42 | +_IL91874_DTM1 = const(0x10) |
| 43 | +_IL91874_DATA_STOP = const(0x11) |
| 44 | +_IL91874_DISPLAY_REFRESH = const(0x12) |
| 45 | +_IL91874_DTM2 = const(0x13) |
| 46 | +_IL91874_PDTM1 = const(0x14) |
| 47 | +_IL91874_PDTM2 = const(0x15) |
| 48 | +_IL91874_PDRF = const(0x16) |
| 49 | +_IL91874_LUT1 = const(0x20) |
| 50 | +_IL91874_LUTWW = const(0x21) |
| 51 | +_IL91874_LUTBW = const(0x22) |
| 52 | +_IL91874_LUTWB = const(0x23) |
| 53 | +_IL91874_LUTBB = const(0x24) |
| 54 | +_IL91874_PLL = const(0x30) |
| 55 | +_IL91874_CDI = const(0x50) |
| 56 | +_IL91874_RESOLUTION = const(0x61) |
| 57 | +_IL91874_VCM_DC_SETTING = const(0x82) |
| 58 | + |
| 59 | +_LUT_VCOMDC = b'\x00\x00\x00\x1a\x1a\x00\x00\x01\x00\n\n\x00\x00\x08\x00\x0e\x01\x0e\x01\x10\x00\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01' |
| 60 | +_LUT_WW = b'\x90\x1a\x1a\x00\x00\x01@\n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x80\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01' |
| 61 | +_LUT_BW = b'\xa0\x1a\x1a\x00\x00\x01\x00\n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x90\n\n\x00\x00\x08\xb0\x04\x10\x00\x00\x05\xb0\x03\x0e\x00\x00\n\xc0#\x00\x00\x00\x01' |
| 62 | +_LUT_BB = b'\x90\x1a\x1a\x00\x00\x01@\n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x80\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01' |
| 63 | +_LUT_WB = b'\x90\x1a\x1a\x00\x00\x01 \n\n\x00\x00\x08\x84\x0e\x01\x0e\x01\x10\x10\n\n\x00\x00\x08\x00\x04\x10\x00\x00\x05\x00\x03\x0e\x00\x00\n\x00#\x00\x00\x00\x01' |
| 64 | + |
| 65 | +class Adafruit_IL91874(Adafruit_EPD): |
| 66 | + """driver class for Adafruit IL91874 ePaper display breakouts""" |
| 67 | + # pylint: disable=too-many-arguments |
| 68 | + def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): |
| 69 | + super(Adafruit_IL91874, self).__init__(width, height, spi, cs_pin, dc_pin, |
| 70 | + sramcs_pin, rst_pin, busy_pin) |
| 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(self._buffer1, width, height, |
| 84 | + buf_format=adafruit_framebuf.MHMSB) |
| 85 | + self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height, |
| 86 | + buf_format=adafruit_framebuf.MHMSB) |
| 87 | + self.black_invert = True |
| 88 | + self.red_invert = False |
| 89 | + self._single_byte_tx = True |
| 90 | + |
| 91 | + def begin(self, reset=True): |
| 92 | + """Begin communication with the display and set basic settings""" |
| 93 | + if reset: |
| 94 | + self.hardware_reset() |
| 95 | + |
| 96 | + self.power_down() |
| 97 | + |
| 98 | + def busy_wait(self): |
| 99 | + """Wait for display to be done with current task, either by polling the |
| 100 | + busy pin, or pausing""" |
| 101 | + if self._busy: |
| 102 | + while not self._busy.value: |
| 103 | + pass |
| 104 | + else: |
| 105 | + time.sleep(0.5) |
| 106 | + |
| 107 | + def power_up(self): |
| 108 | + """Power up the display in preparation for writing RAM and updating""" |
| 109 | + self.hardware_reset() |
| 110 | + time.sleep(0.2) |
| 111 | + self.command(_IL91874_POWER_ON) |
| 112 | + self.busy_wait() |
| 113 | + |
| 114 | + self.command(_IL91874_PANEL_SETTING, bytearray([0xAF])) |
| 115 | + self.command(_IL91874_PLL, bytearray([0x3A])) |
| 116 | + self.command(_IL91874_POWER_SETTING, bytearray([0x03, 0x00, 0x2b, 0x2b, 0x09])) |
| 117 | + self.command(_IL91874_BOOSTER_SOFT_START, bytearray([0x07, 0x07, 0x17])) |
| 118 | + |
| 119 | + self.command(0xF8, bytearray([0x60, 0xA5])) # mystery command in example code |
| 120 | + self.command(0xF8, bytearray([0x89, 0xA5])) # mystery command in example code |
| 121 | + self.command(0xF8, bytearray([0x90, 0x00])) # mystery command in example code |
| 122 | + self.command(0xF8, bytearray([0x93, 0xA2])) # mystery command in example code |
| 123 | + self.command(0xF8, bytearray([0x73, 0x41])) # mystery command in example code |
| 124 | + |
| 125 | + self.command(_IL91874_VCM_DC_SETTING, bytearray([0x12])) |
| 126 | + self.command(_IL91874_CDI, bytearray([0x87])) |
| 127 | + |
| 128 | + # Look Up Tables |
| 129 | + self.command(_IL91874_LUT1, _LUT_VCOMDC); |
| 130 | + self.command(_IL91874_LUTWW, _LUT_WW); |
| 131 | + self.command(_IL91874_LUTBW, _LUT_BW); |
| 132 | + self.command(_IL91874_LUTWB, _LUT_WB); |
| 133 | + self.command(_IL91874_LUTBB, _LUT_BB); |
| 134 | + |
| 135 | + _b0 = (self._width >> 8) & 0xFF |
| 136 | + _b1 = self._width & 0xFF |
| 137 | + _b2 = (self._height >> 8) & 0xFF |
| 138 | + _b3 = self._height & 0xFF |
| 139 | + self.command(_IL91874_RESOLUTION, bytearray([_b0, _b1, _b2, _b3])) |
| 140 | + self.command(_IL91874_PDRF, bytearray([0x00])) |
| 141 | + |
| 142 | + def power_down(self): |
| 143 | + """Power down the display - required when not actively displaying!""" |
| 144 | + self.command(_IL91874_POWER_OFF, bytearray([0x17])) |
| 145 | + self.busy_wait() |
| 146 | + |
| 147 | + if self._rst: # Only deep sleep if we can get out of it |
| 148 | + self.command(_IL91874_DEEP_SLEEP, bytearray([0xA5])) |
| 149 | + |
| 150 | + def update(self): |
| 151 | + """Update the display from internal memory""" |
| 152 | + self.command(_IL91874_DISPLAY_REFRESH) |
| 153 | + self.busy_wait() |
| 154 | + if not self._busy: |
| 155 | + time.sleep(16) # wait 16 seconds |
| 156 | + |
| 157 | + def write_ram(self, index): |
| 158 | + """Send the one byte command for starting the RAM write process. Returns |
| 159 | + the byte read at the same time over SPI. index is the RAM buffer, can be |
| 160 | + 0 or 1 for tri-color displays.""" |
| 161 | + if index == 0: |
| 162 | + return self.command(_IL91874_DTM1, end=False) |
| 163 | + if index == 1: |
| 164 | + return self.command(_IL91874_DTM2, end=False) |
| 165 | + raise RuntimeError("RAM index must be 0 or 1") |
| 166 | + |
| 167 | + def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use |
| 168 | + """Set the RAM address location, not used on this chipset but required by |
| 169 | + the superclass""" |
| 170 | + return # on this chip it does nothing |
0 commit comments