|
| 1 | +from Adafruit_EPD.epd import Adafruit_EPD |
| 2 | +from Adafruit_EPD.mcp_sram import Adafruit_MCP_SRAM |
| 3 | +from micropython import const |
| 4 | +import time |
| 5 | + |
| 6 | +IL0373_PANEL_SETTING = const(0x00) |
| 7 | +IL0373_POWER_SETTING = const(0x01) |
| 8 | +IL0373_POWER_OFF = const(0x02) |
| 9 | +IL0373_POWER_OFF_SEQUENCE = const(0x03) |
| 10 | +IL0373_POWER_ON = const(0x04) |
| 11 | +IL0373_POWER_ON_MEASURE = const(0x05) |
| 12 | +IL0373_BOOSTER_SOFT_START = const(0x06) |
| 13 | +IL0373_DEEP_SLEEP = const(0x07) |
| 14 | +IL0373_DTM1 = const(0x10) |
| 15 | +IL0373_DATA_STOP = const(0x11) |
| 16 | +IL0373_DISPLAY_REFRESH = const(0x12) |
| 17 | +IL0373_DTM2 = const(0x13) |
| 18 | +IL0373_PDTM1 = const(0x14) |
| 19 | +IL0373_PDTM2 = const(0x15) |
| 20 | +IL0373_PDRF = const(0x16) |
| 21 | +IL0373_LUT1 = const(0x20) |
| 22 | +IL0373_LUTWW = const(0x21) |
| 23 | +IL0373_LUTBW = const(0x22) |
| 24 | +IL0373_LUTWB = const(0x23) |
| 25 | +IL0373_LUTBB = const(0x24) |
| 26 | +IL0373_PLL = const(0x30) |
| 27 | +IL0373_CDI = const(0x50) |
| 28 | +IL0373_RESOLUTION = const(0x61) |
| 29 | +IL0373_VCM_DC_SETTING = const(0x82) |
| 30 | + |
| 31 | +class Adafruit_IL0373(Adafruit_EPD): |
| 32 | + def __init__(self, width, height, rst, dc, busy, srcs, cs, spi): |
| 33 | + super().__init__(width, height, rst, dc, busy, srcs, cs, spi) |
| 34 | + |
| 35 | + self.bw_bufsize = int(width * height / 8) |
| 36 | + self.red_bufsize = int(width * height / 8) |
| 37 | + |
| 38 | + self.begin() |
| 39 | + |
| 40 | + def begin(self, reset=True): |
| 41 | + super(Adafruit_IL0373, self).begin(reset) |
| 42 | + |
| 43 | + while self._busy.value == False: |
| 44 | + pass |
| 45 | + |
| 46 | + self.command(IL0373_POWER_SETTING, bytearray([0x03, 0x00, 0x2b, 0x2b, 0x09])) |
| 47 | + self.command(IL0373_BOOSTER_SOFT_START, bytearray([0x17, 0x17, 0x17])) |
| 48 | + |
| 49 | + def update(self): |
| 50 | + self.command(IL0373_DISPLAY_REFRESH) |
| 51 | + |
| 52 | + while self._busy.value == False: |
| 53 | + pass |
| 54 | + |
| 55 | + self.command(IL0373_CDI, bytearray([0x17])) |
| 56 | + self.command(IL0373_VCM_DC_SETTING, bytearray([0x00])) |
| 57 | + self.command(IL0373_POWER_OFF) |
| 58 | + time.sleep(2) |
| 59 | + |
| 60 | + def power_up(self): |
| 61 | + self.command(IL0373_POWER_ON) |
| 62 | + |
| 63 | + while self._busy.value == False: |
| 64 | + pass |
| 65 | + |
| 66 | + time.sleep(.2) |
| 67 | + |
| 68 | + self.command(IL0373_PANEL_SETTING, bytearray([0xCF])) |
| 69 | + self.command(IL0373_CDI, bytearray([0x37])) |
| 70 | + self.command(IL0373_PLL, bytearray([0x29])) |
| 71 | + b1 = self.height & 0xFF |
| 72 | + b2 = (self.height >> 8) & 0xFF |
| 73 | + b3 = self.width & 0xFF |
| 74 | + b4 = (self.width >> 8) & 0xFF |
| 75 | + self.command(IL0373_RESOLUTION, bytearray([b1, b2, b3, b4])) |
| 76 | + self.command(IL0373_VCM_DC_SETTING, bytearray([0x0A])) |
| 77 | + |
| 78 | + |
| 79 | + def display(self): |
| 80 | + self.power_up() |
| 81 | + |
| 82 | + while not self.spi_device.try_lock(): |
| 83 | + pass |
| 84 | + self.sram.cs.value = False |
| 85 | + #send read command |
| 86 | + self.spi_device.write(bytearray([Adafruit_MCP_SRAM.SRAM_READ])) |
| 87 | + #send start address |
| 88 | + self.spi_device.write(bytearray([0x00, 0x00])) |
| 89 | + self.spi_device.unlock() |
| 90 | + |
| 91 | + #first data byte from SRAM will be transfered in at the same time as the EPD command is transferred out |
| 92 | + c = self.command(IL0373_DTM1, end=False) |
| 93 | + |
| 94 | + while not self.spi_device.try_lock(): |
| 95 | + pass |
| 96 | + self._dc.value = True |
| 97 | + xfer = bytearray([c]) |
| 98 | + outbuf = bytearray(1) |
| 99 | + for i in range(self.bw_bufsize): |
| 100 | + outbuf[0] = xfer[0] |
| 101 | + self.spi_device.write_readinto(outbuf, xfer) |
| 102 | + self._cs.value = True |
| 103 | + self.sram.cs.value = True |
| 104 | + |
| 105 | + time.sleep(.002) |
| 106 | + |
| 107 | + self.sram.cs.value = False |
| 108 | + #send read command |
| 109 | + self.spi_device.write(bytearray([Adafruit_MCP_SRAM.SRAM_READ])) |
| 110 | + #send start address |
| 111 | + self.spi_device.write(bytearray([(self.bw_bufsize >> 8), (self.bw_bufsize & 0xFF)])) |
| 112 | + self.spi_device.unlock() |
| 113 | + |
| 114 | + #first data byte from SRAM will be transfered in at the same time as the EPD command is transferred out |
| 115 | + c = self.command(IL0373_DTM2, end=False) |
| 116 | + |
| 117 | + while not self.spi_device.try_lock(): |
| 118 | + pass |
| 119 | + self._dc.value = True |
| 120 | + xfer = bytearray([c]) |
| 121 | + outbuf = bytearray(1) |
| 122 | + for i in range(self.bw_bufsize): |
| 123 | + outbuf[0] = xfer[0] |
| 124 | + self.spi_device.write_readinto(outbuf, xfer) |
| 125 | + self._cs.value = True |
| 126 | + self.sram.cs.value = True |
| 127 | + self.spi_device.unlock() |
| 128 | + |
| 129 | + self.update() |
| 130 | + |
| 131 | + def draw_pixel(self, x, y, color): |
| 132 | + if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height): |
| 133 | + return |
| 134 | + |
| 135 | + if x == 0: |
| 136 | + x = 1 |
| 137 | + |
| 138 | + addr = int(((self.width - x) * self.height + y)/8) |
| 139 | + if color == Adafruit_EPD.RED: |
| 140 | + addr = addr + self.bw_bufsize |
| 141 | + c = self.sram.read8(addr) |
| 142 | + |
| 143 | + if color == Adafruit_EPD.WHITE: |
| 144 | + c = c | (1 << (7 - y%8)) |
| 145 | + elif color == Adafruit_EPD.RED or color == Adafruit_EPD.BLACK: |
| 146 | + c = c & ~(1 << (7 - y%8)) |
| 147 | + elif color == Adafruit_EPD.INVERSE: |
| 148 | + c = c ^ (1 << (7 - y%8)) |
| 149 | + |
| 150 | + self.sram.write8(addr, c) |
| 151 | + |
| 152 | + def clear_buffer(self): |
| 153 | + self.sram.erase(0x00, self.bw_bufsize, 0xFF) |
| 154 | + self.sram.erase(self.bw_bufsize, self.red_bufsize, 0xFF) |
| 155 | + |
| 156 | + def clear_display(self): |
| 157 | + self.clear_buffer() |
| 158 | + self.display() |
| 159 | + |
0 commit comments