def __init__(self,
              spi,
              cs,
              dc,
              rst,
              height=240,
              width=240,
              disp_mode=LANDSCAPE,
              init_spi=False,
              display=GENERIC):
     if not 0 <= disp_mode <= 7:
         raise ValueError('Invalid display mode:', disp_mode)
     if not display in (GENERIC, TDISPLAY):
         raise ValueError('Invalid display type.')
     self._spi = spi  # Clock cycle time for write 16ns 62.5MHz max (read is 150ns)
     self._rst = rst  # Pins
     self._dc = dc
     self._cs = cs
     self.height = height  # Required by Writer class
     self.width = width
     self._offset = display[:2]  # display arg is (x, y, orientation)
     orientation = display[2]  # where x, y is the RAM offset
     self._spi_init = init_spi  # Possible user callback
     self._lock = asyncio.Lock()
     mode = framebuf.GS4_HMSB  # Use 4bit greyscale.
     self.palette = BoolPalette(mode)
     gc.collect()
     buf = bytearray(height *
                     -(-width // 2))  # Ceiling division for odd widths
     self._mvb = memoryview(buf)
     super().__init__(buf, width, height, mode)
     self._linebuf = bytearray(self.width * 2)  # 16 bit color out
     self._init(disp_mode, orientation)
     self.show()
Esempio n. 2
0
 def __init__(self,
              spi,
              pincs,
              pindc,
              pinrs,
              height=128,
              width=128,
              init_spi=False):
     if height not in (96, 128):
         raise ValueError('Unsupported height {}'.format(height))
     self.spi = spi
     self.spi_init = init_spi
     self.pincs = pincs
     self.pindc = pindc  # 1 = data 0 = cmd
     self.height = height  # Required by Writer class
     self.width = width
     mode = framebuf.GS8  # Use 8bit greyscale for 8 bit color.
     self.palette = BoolPalette(mode)
     gc.collect()
     self.buffer = bytearray(self.height * self.width)
     super().__init__(self.buffer, self.width, self.height, mode)
     self.linebuf = bytearray(self.width * 2)
     pinrs(0)  # Pulse the reset line
     utime.sleep_ms(1)
     pinrs(1)
     utime.sleep_ms(1)
     if self.spi_init:  # A callback was passed
         self.spi_init(spi)  # Bus may be shared
     # See above comment to explain this allocation-saving gibberish.
     self._write(b'\xfd\x12\xfd\xb1\xae\xb3\xf1\xca\x7f\xa0\x74'\
     b'\x15\x00\x7f\x75\x00\x7f\xa1\x00\xa2\x00\xb5\x00\xab\x01'\
     b'\xb1\x32\xbe\x05\xa6\xc1\xc8\x80\xc8\xc7\x0f'\
     b'\xb4\xa0\xb5\x55\xb6\x01\xaf', 0)
     self.show()
     gc.collect()
Esempio n. 3
0
 def __init__(self,
              spi,
              cs,
              dc,
              rst,
              height=128,
              width=160,
              usd=False,
              init_spi=False):
     self._spi = spi
     self._rst = rst  # Pins
     self._dc = dc
     self._cs = cs
     self.height = height  # Required by Writer class
     self.width = width
     self._spi_init = init_spi
     mode = framebuf.GS8  # Use 8bit greyscale for 8 bit color.
     self.palette = BoolPalette(mode)
     gc.collect()
     buf = bytearray(height * width)
     self._mvb = memoryview(buf)
     super().__init__(buf, width, height, mode)
     self._linebuf = bytearray(int(width * 3 // 2))  # 12 bit color out
     self._init(usd)
     self.show()
Esempio n. 4
0
 def __init__(self,
              spi,
              cs,
              dc,
              rst,
              height=128,
              width=128,
              rotation=0,
              init_spi=False):
     self._spi = spi
     self._rst = rst  # Pins
     self._dc = dc
     self._cs = cs
     self.height = height  # Required by Writer class
     self.width = width
     self._spi_init = init_spi
     mode = framebuf.GS8  # Use 8bit greyscale for 8 bit color.
     self.palette = BoolPalette(mode)
     gc.collect()
     buf = bytearray(self.height * self.width)
     self._mvb = memoryview(buf)
     super().__init__(buf, self.width, self.height, mode)
     self._linebuf = bytearray(self.width * 2)  # 16 bit color out
     quad, mod = divmod(rotation, 90)  # Get quadrant
     if mod or quad > 3:
         quad %= 4
         print('Warning: rotation adjusted to', quad * 90)
     self._init(quad)
     self.show()
Esempio n. 5
0
 def __init__(self,
              spi,
              pincs,
              pindc,
              pinrs,
              height=64,
              width=96,
              init_spi=False):
     self._spi = spi
     self._pincs = pincs
     self._pindc = pindc  # 1 = data 0 = cmd
     self.height = height  # Required by Writer class
     self.width = width
     self._spi_init = init_spi
     mode = framebuf.GS8  # Use 8bit greyscale for 8 bit color.
     self.palette = BoolPalette(mode)
     gc.collect()
     self.buffer = bytearray(self.height * self.width)
     super().__init__(self.buffer, self.width, self.height, mode)
     pinrs(0)  # Pulse the reset line
     utime.sleep_ms(1)
     pinrs(1)
     utime.sleep_ms(1)
     self._write(b'\xae\xa0\x32\xa1\x00\xa2\x00\xa4\xa8\x3f\xad\x8e\xb0'\
     b'\x0b\xb1\x31\xb3\xf0\x8a\x64\x8b\x78\x8c\x64\xbb\x3a\xbe\x3e\x87'\
     b'\x06\x81\x91\x82\x50\x83\x7d\xaf', 0)
     gc.collect()
     self.show()
Esempio n. 6
0
 def __init__(self,
              spi,
              cs,
              dc,
              rst,
              height=240,
              width=320,
              usd=False,
              init_spi=False):
     self._spi = spi
     self._cs = cs
     self._dc = dc
     self._rst = rst
     self.height = height
     self.width = width
     self._spi_init = init_spi
     mode = framebuf.GS4_HMSB
     self.palette = BoolPalette(mode)
     gc.collect()
     buf = bytearray(self.height * self.width // 2)
     self._mvb = memoryview(buf)
     super().__init__(buf, self.width, self.height, mode)
     self._linebuf = bytearray(self.width * 2)
     # Hardware reset
     self._rst(0)
     sleep_ms(50)
     self._rst(1)
     sleep_ms(50)
     if self._spi_init:  # A callback was passed
         self._spi_init(spi)  # Bus may be shared
     self._lock = asyncio.Lock()
     # Send initialization commands
     self._wcmd(b'\x01')  # SWRESET Software reset
     sleep_ms(100)
     self._wcd(b'\xcf', b'\x00\xC1\x30')  # PWCTRB Pwr ctrl B
     self._wcd(b'\xed', b'\x64\x03\x12\x81')  # POSC Pwr on seq. ctrl
     self._wcd(b'\xe8', b'\x85\x00\x78')  # DTCA Driver timing ctrl A
     self._wcd(b'\xcb', b'\x39\x2C\x00\x34\x02')  # PWCTRA Pwr ctrl A
     self._wcd(b'\xf7', b'\x20')  # PUMPRC Pump ratio control
     self._wcd(b'\xea', b'\x00\x00')  # DTCB Driver timing ctrl B
     self._wcd(b'\xc0', b'\x23')  # PWCTR1 Pwr ctrl 1
     self._wcd(b'\xc1', b'\x10')  # PWCTR2 Pwr ctrl 2
     self._wcd(b'\xc5', b'\x3E\x28')  # VMCTR1 VCOM ctrl 1
     self._wcd(b'\xc7', b'\x86')  # VMCTR2 VCOM ctrl 2
     # (b'\x88', b'\xe8', b'\x48', b'\x28')[rotation // 90]
     if self.height > self.width:
         self._wcd(b'\x36',
                   b'\x48' if usd else b'\x88')  # MADCTL: RGB portrait mode
     else:
         self._wcd(
             b'\x36',
             b'\x28' if usd else b'\xe8')  # MADCTL: RGB landscape mode
     self._wcd(b'\x37',
               b'\x00')  # VSCRSADD Vertical scrolling start address
     self._wcd(
         b'\x3a',
         b'\x55')  # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface)
     self._wcd(b'\xb1', b'\x00\x18')  # FRMCTR1 Frame rate ctrl
     self._wcd(b'\xb6', b'\x08\x82\x27')  # DFUNCTR
     self._wcd(b'\xf2', b'\x00')  # ENABLE3G Enable 3 gamma ctrl
     self._wcd(b'\x26', b'\x01')  # GAMMASET Gamma curve selected
     self._wcd(
         b'\xe0',
         b'\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00'
     )  # GMCTRP1
     self._wcd(
         b'\xe1',
         b'\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F'
     )  # GMCTRN1
     self._wcmd(b'\x11')  # SLPOUT Exit sleep
     sleep_ms(100)
     self._wcmd(b'\x29')  # DISPLAY_ON
     sleep_ms(100)