Update v2 driver
This commit is contained in:
		| @@ -35,6 +35,8 @@ from inkycal.display.drivers import epdconfig | |||||||
| EPD_WIDTH = 800 | EPD_WIDTH = 800 | ||||||
| EPD_HEIGHT = 480 | EPD_HEIGHT = 480 | ||||||
|  |  | ||||||
|  | logger = logging.getLogger(__name__) | ||||||
|  |  | ||||||
|  |  | ||||||
| class EPD: | class EPD: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
| @@ -48,11 +50,11 @@ class EPD: | |||||||
|     # Hardware reset |     # Hardware reset | ||||||
|     def reset(self): |     def reset(self): | ||||||
|         epdconfig.digital_write(self.reset_pin, 1) |         epdconfig.digital_write(self.reset_pin, 1) | ||||||
|         epdconfig.delay_ms(200) |         epdconfig.delay_ms(20) | ||||||
|         epdconfig.digital_write(self.reset_pin, 0) |         epdconfig.digital_write(self.reset_pin, 0) | ||||||
|         epdconfig.delay_ms(2) |         epdconfig.delay_ms(2) | ||||||
|         epdconfig.digital_write(self.reset_pin, 1) |         epdconfig.digital_write(self.reset_pin, 1) | ||||||
|         epdconfig.delay_ms(200) |         epdconfig.delay_ms(20) | ||||||
|  |  | ||||||
|     def send_command(self, command): |     def send_command(self, command): | ||||||
|         epdconfig.digital_write(self.dc_pin, 0) |         epdconfig.digital_write(self.dc_pin, 0) | ||||||
| @@ -66,14 +68,21 @@ class EPD: | |||||||
|         epdconfig.spi_writebyte([data]) |         epdconfig.spi_writebyte([data]) | ||||||
|         epdconfig.digital_write(self.cs_pin, 1) |         epdconfig.digital_write(self.cs_pin, 1) | ||||||
|  |  | ||||||
|  |     def send_data2(self, data): | ||||||
|  |         epdconfig.digital_write(self.dc_pin, 1) | ||||||
|  |         epdconfig.digital_write(self.cs_pin, 0) | ||||||
|  |         epdconfig.SPI.writebytes2(data) | ||||||
|  |         epdconfig.digital_write(self.cs_pin, 1) | ||||||
|  |  | ||||||
|     def ReadBusy(self): |     def ReadBusy(self): | ||||||
|         logging.debug("e-Paper busy") |         logger.debug("e-Paper busy") | ||||||
|         self.send_command(0x71) |         self.send_command(0x71) | ||||||
|         busy = epdconfig.digital_read(self.busy_pin) |         busy = epdconfig.digital_read(self.busy_pin) | ||||||
|         while (busy == 0): |         while (busy == 0): | ||||||
|             self.send_command(0x71) |             self.send_command(0x71) | ||||||
|             busy = epdconfig.digital_read(self.busy_pin) |             busy = epdconfig.digital_read(self.busy_pin) | ||||||
|         epdconfig.delay_ms(200) |         epdconfig.delay_ms(20) | ||||||
|  |         logger.debug("e-Paper busy release") | ||||||
|  |  | ||||||
|     def init(self): |     def init(self): | ||||||
|         if (epdconfig.module_init() != 0): |         if (epdconfig.module_init() != 0): | ||||||
| @@ -81,6 +90,12 @@ class EPD: | |||||||
|         # EPD hardware init start |         # EPD hardware init start | ||||||
|         self.reset() |         self.reset() | ||||||
|  |  | ||||||
|  |         self.send_command(0x06)  # btst | ||||||
|  |         self.send_data(0x17) | ||||||
|  |         self.send_data(0x17) | ||||||
|  |         self.send_data(0x28)  # If an exception is displayed, try using 0x38 | ||||||
|  |         self.send_data(0x17) | ||||||
|  |  | ||||||
|         self.send_command(0x01)  # POWER SETTING |         self.send_command(0x01)  # POWER SETTING | ||||||
|         self.send_data(0x07) |         self.send_data(0x07) | ||||||
|         self.send_data(0x07)  # VGH=20V,VGL=-20V |         self.send_data(0x07)  # VGH=20V,VGL=-20V | ||||||
| @@ -114,47 +129,39 @@ class EPD: | |||||||
|         return 0 |         return 0 | ||||||
|  |  | ||||||
|     def getbuffer(self, image): |     def getbuffer(self, image): | ||||||
|         # logging.debug("bufsiz = ",int(self.width/8) * self.height) |         img = image | ||||||
|         buf = [0xFF] * (int(self.width / 8) * self.height) |         imwidth, imheight = img.size | ||||||
|         image_monocolor = image.convert('1') |  | ||||||
|         imwidth, imheight = image_monocolor.size |  | ||||||
|         pixels = image_monocolor.load() |  | ||||||
|         # logging.debug("imwidth = %d, imheight = %d",imwidth,imheight) |  | ||||||
|         if (imwidth == self.width and imheight == self.height): |         if (imwidth == self.width and imheight == self.height): | ||||||
|             logging.debug("Vertical") |             img = img.convert('1') | ||||||
|             for y in range(imheight): |  | ||||||
|                 for x in range(imwidth): |  | ||||||
|                     # Set the bits for the column of pixels at the current position. |  | ||||||
|                     if pixels[x, y] == 0: |  | ||||||
|                         buf[int((x + y * self.width) / 8)] &= ~(0x80 >> (x % 8)) |  | ||||||
|         elif (imwidth == self.height and imheight == self.width): |         elif (imwidth == self.height and imheight == self.width): | ||||||
|             logging.debug("Horizontal") |             # image has correct dimensions, but needs to be rotated | ||||||
|             for y in range(imheight): |             img = img.rotate(90, expand=True).convert('1') | ||||||
|                 for x in range(imwidth): |         else: | ||||||
|                     newx = y |             logger.warning("Wrong image dimensions: must be " + str(self.width) + "x" + str(self.height)) | ||||||
|                     newy = self.height - x - 1 |             # return a blank buffer | ||||||
|                     if pixels[x, y] == 0: |             return [0x00] * (int(self.width / 8) * self.height) | ||||||
|                         buf[int((newx + newy * self.width) / 8)] &= ~(0x80 >> (y % 8)) |  | ||||||
|  |         buf = bytearray(img.tobytes('raw')) | ||||||
|  |         # The bytes need to be inverted, because in the PIL world 0=black and 1=white, but | ||||||
|  |         # in the e-paper world 0=white and 1=black. | ||||||
|  |         for i in range(len(buf)): | ||||||
|  |             buf[i] ^= 0xFF | ||||||
|         return buf |         return buf | ||||||
|  |  | ||||||
|     def display(self, image): |     def display(self, image): | ||||||
|         self.send_command(0x13) |         self.send_command(0x13) | ||||||
|         for i in range(0, int(self.width * self.height / 8)): |         self.send_data2(image) | ||||||
|             self.send_data(~image[i]); |  | ||||||
|  |  | ||||||
|         self.send_command(0x12) |         self.send_command(0x12) | ||||||
|         epdconfig.delay_ms(100) |         epdconfig.delay_ms(100) | ||||||
|         self.ReadBusy() |         self.ReadBusy() | ||||||
|  |  | ||||||
|     def Clear(self): |     def Clear(self): | ||||||
|  |         buf = [0x00] * (int(self.width / 8) * self.height) | ||||||
|         self.send_command(0x10) |         self.send_command(0x10) | ||||||
|         for i in range(0, int(self.width * self.height / 8)): |         self.send_data2(buf) | ||||||
|             self.send_data(0x00) |  | ||||||
|  |  | ||||||
|         self.send_command(0x13) |         self.send_command(0x13) | ||||||
|         for i in range(0, int(self.width * self.height / 8)): |         self.send_data2(buf) | ||||||
|             self.send_data(0x00) |  | ||||||
|  |  | ||||||
|         self.send_command(0x12) |         self.send_command(0x12) | ||||||
|         epdconfig.delay_ms(100) |         epdconfig.delay_ms(100) | ||||||
|         self.ReadBusy() |         self.ReadBusy() | ||||||
| @@ -166,5 +173,6 @@ class EPD: | |||||||
|         self.send_command(0x07)  # DEEP_SLEEP |         self.send_command(0x07)  # DEEP_SLEEP | ||||||
|         self.send_data(0XA5) |         self.send_data(0XA5) | ||||||
|  |  | ||||||
|  |         epdconfig.delay_ms(2000) | ||||||
|         epdconfig.module_exit() |         epdconfig.module_exit() | ||||||
| ### END OF FILE ### | ### END OF FILE ### | ||||||
		Reference in New Issue
	
	Block a user