changeset 0:e74698c81c3e draft

Initial commit
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Thu, 05 Apr 2018 19:54:23 +0200
parents
children 94467ac67f68
files gdew0154t8.py main.py
diffstat 2 files changed, 164 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gdew0154t8.py	Thu Apr 05 19:54:23 2018 +0200
@@ -0,0 +1,123 @@
+_LUT_FULL = (
+    b'\x00\x08\x00\x00\x00\x02' b'\x60\x28\x28\x00\x00\x01'
+    b'\x00\x14\x00\x00\x00\x01' b'\x00\x12\x12\x00\x00\x01'
+    b'\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00' b'\x00\x00',  # VCOM
+    b'\x40\x08\x00\x00\x00\x02' b'\x90\x28\x28\x00\x00\x01'
+    b'\x40\x14\x00\x00\x00\x01' b'\xA0\x12\x12\x00\x00\x01'
+    b'\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00',  # white to white
+    b'\x40\x17\x00\x00\x00\x02' b'\x90\x0F\x0F\x00\x00\x03'
+    b'\x40\x0A\x01\x00\x00\x01' b'\xA0\x0E\x0E\x00\x00\x02'
+    b'\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00',  # black to white
+    b'\x80\x08\x00\x00\x00\x02' b'\x90\x28\x28\x00\x00\x01'
+    b'\x80\x14\x00\x00\x00\x01' b'\x50\x12\x12\x00\x00\x01'
+    b'\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00',  # white to black
+    b'\x80\x08\x00\x00\x00\x02' b'\x90\x28\x28\x00\x00\x01'
+    b'\x80\x14\x00\x00\x00\x01' b'\x50\x12\x12\x00\x00\x01'
+    b'\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00')  # black to black
+
+_LUT_FAST = (
+    b'\x00\x19\x01\x00\x00\x01' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'\x00\x00',  # VCOM
+    b'0x00\x19\x01\x00\x00\x01' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00',  # white to white
+    b'0x80\x19\x01\x00\x00\x01' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00',  # black to white
+    b'0x40\x19\x01\x00\x00\x01' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00',  # white to black
+    b'0x00\x19\x01\x00\x00\x01' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00' b'0x00\x00\x00\x00\x00\x00'
+    b'0x00\x00\x00\x00\x00\x00')  # black to black
+
+
+class Display:
+    width = 152
+    height = 152
+
+    def __init__(self, spi, dc, cs, busy):
+        self._spi = spi
+        self._cs = cs
+        self._dc = dc
+        self._busy = busy
+        self._stride = self.height // 8
+        self.buffer = memoryview(bytearray(self.width * self._stride))
+        self.reset()
+        self._fast = False
+
+    def _wait(self):
+        while not self._busy.value:
+            pass
+
+    def _command(self, command, data=None):
+        self._dc.value = 0
+        self._cs.value = 0
+        self._spi.write(command)
+        self._dc.value = 1
+        if data:
+            self._spi.write(data)
+        self._cs.value = 1
+
+    def _lut(self, lut):
+        for command, data in zip('\x20\x21\x22\x23\x24', lut):
+            self._command(command, data)
+
+    def reset(self):
+        self._wait()
+        self._command(b'\x00', b'\x00')  # reset
+        self._command(b'\x06', b'\x17\x17\x17')  # booster soft start
+        self._command(b'\x01', b'\x03\x00\x2b\x2b\x09')
+        self._command(b'\x04')  # power on
+        self._wait()
+        self._command(b'\x00', b'\x33')  # panel setting for BW
+        self._command(b'\x61', b'\x98\x00\x98')  # resolution 152x152
+        self._command(b'\x82', b'\x12')  # VCOM value 1V
+        self._command(b'\x50', b'\x87')  # VCOM and data interval
+        self._command(b'\x30', b'\x3c')  # PLL control 50Hz
+        self._lut(_LUT_FULL)
+
+    def sleep(self):
+        self._command(b'\x50', b'\x17')  # frame floating
+        self._command(b'\x82', b'\x00')  # VCOM value 0.1V
+        self._command(b'\x01', b'\x00\x00\x00\x00\x00')  # power 0V
+        self._command(b'\x02')  # power off
+        self._wait()
+        self._command(b'\x07\xa5')  # deep sleep
+
+    def update(self, block=True, fast=False):
+        if fast and not self._fast:
+            self._lut(_LUT_FAST)
+        elif not fast and self._fast:
+            self._lut(_LUT_FULL)
+        self._wait()
+        self._command(b'\x13', self.buffer)  # new data
+        self._command(b'\x11')  # data stop
+        self._command(b'\x12')  # refresh
+        if block:
+            self._wait()
+        self._command(b'\x10', self.buffer)  # old data
+        self._command(b'\x11')  # data stop
+
+    def pixel(self, x, y, color=None):
+        if not 0 <= x < self.width or not 0 <= y < self.height:
+            return
+        page = x // 8
+        mask = 1 << (x % 8)
+        if color is None:
+            return bool(self.buffer[page + y * self._stride] & mask)
+        elif color:
+            self.buffer[page + y * self._stride] |= mask
+        else:
+            self.buffer[page + y * self._stride] &= ~mask
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.py	Thu Apr 05 19:54:23 2018 +0200
@@ -0,0 +1,41 @@
+import busio
+import digitalio
+import board
+import time
+import gdew0154t8
+import font86
+
+
+spi = busio.SPI(board.SCK, board.MOSI)
+spi.try_lock()
+spi.configure(baudrate=12000000)
+
+dc = digitalio.DigitalInOut(board.MISO)
+dc.switch_to_output(value=1)
+
+cs = digitalio.DigitalInOut(board.A0)
+cs.switch_to_output(value=1)
+
+rst = digitalio.DigitalInOut(board.A2)
+rst.switch_to_output(value=0)
+
+busy = digitalio.DigitalInOut(board.A1)
+
+time.sleep(0.1)
+rst.value = 1
+display = gdew0154t8.Display(spi, dc, cs, busy)
+display.pixel(10, 10, 1)
+
+i = 32
+for y in range(19):
+    for x in range(25):
+        font86.put_char(display.buffer, chr(i), x, y)
+        i += 1
+display.update()
+
+for y in range(19):
+    for x in range(25):
+        font86.put_char(display.buffer, '*', x, y)
+        i += 1
+display.update()
+