# Driver for 2.4" LCD for P2 Eval Board type headers import array import p2 from machine import Pin import time import uctypes class ILI934X(): #Colors White= 0xFFFF Black= 0x0000 MidnightBlue= 0x18CE MintCream= 0xF7FF Yellow= 0xFFE0 LightYellow= 0xFFFC Aqua= 0x07FF Blue= 0x001F Gray= 0x8410 Green= 0x0400 Lime= 0x07E0 Maroon= 0x8000 Navy= 0x0010 Olive= 0x8400 Purple= 0x8010 Red= 0xF800 Silver= 0xC618 Teal= 0x0410 #Commands TakePins_ = 1 WrByte_CMD_ = 2 WrByte_DAT_ = 3 WrWord_DAT_ = 4 WrWordN_DAT_ = 5 WrBytes_DAT_ = 6 RdBytes_DAT_ = 7 DrawLineCmd_ = 8 SetPixelCmd_ = 9 DrawCircleCmd_ = 10 DrawCharCmd_ = 11 TogglePin_ = 12 def __init__(self, basepin, height=240, width=320): # self, spi, cs, dc, rst, height=240, width=320, usd=False, init_spi=False): # Process arguments self.rst = basepin + 8 #self._rst = Pin(self.rst, value=1) p2.pinh(self.rst) self.cs = basepin + 12 self.dc = basepin + 11 self.basepin = basepin self.rd = basepin + 9 self.wr = basepin + 10 self.height = height self.width = width #self.pins = array.array('L',[self.basepin, self.rst, self.rd, self.wr, self.dc, self.cs]) #pins = [self.basepin, self.rst, self.rd, self.wr, self.dc, self.cs] #pina = bytearray(pins) #pina = uctypes.addressof(self.pins)+5 self.data=array.array('L',[0, 0,0,0,0, 0,0,0,0, 0,0,0,0]) # 12, but only need 11 at this time #testa = uctypes.bytearray_at(self.pins, 4) #print("Testing Pins = ",testa) #Start driver f=open("ili934x.binary","rb") code=f.read() f.close() self.cog=p2.Cpu() self.cog.start(code,self.data) #Hard Reset #self._rst.value(0) p2.pinl(self.rst) time.sleep_ms(1) #self._rst.value(1) p2.pinh(self.rst) time.sleep_ms(200) #TakePins self.data[1]=self.basepin self.data[4]=self.rst self.data[5]=self.rd self.data[6]=self.wr self.data[7]=self.dc self.data[8]=self.cs WriteDelay = int(p2.clkfreq()/15000000/2) if (WriteDelay > 8): WriteDelay -= 4 self.data[2]=WriteDelay ReadDelay = int(p2.clkfreq()/2000000/2) if (ReadDelay > 8): ReadDelay-=8 self.data[3]=ReadDelay print("Taking Pins:",self.data) self.data[0]=self.TakePins_ self.WaitDone() #ConfigureLCD # Start initial Sequence self.WrByte_CMD(b'\x28') #'display OFF self.WrByte_CMD(b'\x11') self.WrByte_DAT(b'\x00') #'exit SLEEP mode self.WrByte_CMD(b'\xC0') self.WrByte_DAT(b'\x26') self.WrByte_DAT(b'\x04') #'power control 1 self.WrByte_CMD(b'\xC1') self.WrByte_DAT(b'\x04') #'power control 2 self.WrByte_CMD(b'\xC5') self.WrByte_DAT(b'\x34') self.WrByte_DAT(b'\x40') #'VCOM control 1 self.WrByte_CMD(b'\x36') self.WrByte_DAT(b'\xA8') #'memory access control = b'\xA0=RGB, b'\xA8=BGR self.WrByte_CMD(b'\xB1') self.WrByte_DAT(b'\x00') self.WrByte_DAT(b'\x18') #'frame rate control self.WrByte_CMD(b'\xB6') self.WrByte_DAT(b'\x0A') self.WrByte_DAT(b'\xA2') #'display function control self.WrByte_CMD(b'\xC7') self.WrByte_DAT(b'\xC0') #'VCOM control 2 self.WrByte_CMD(b'\x3A') self.WrByte_DAT(b'\x05') #'pixel format: b'\x06 = 18 bits per pixel, b'\x05 = 16 bits per pixel self.WrByte_CMD(b'\xE0') self.WrByte_DAT(b'\x1F') #'positive gamma correction self.WrByte_DAT(b'\x1B') self.WrByte_DAT(b'\x18') self.WrByte_DAT(b'\x0B') self.WrByte_DAT(b'\x0F') self.WrByte_DAT(b'\x09') self.WrByte_DAT(b'\x46') self.WrByte_DAT(b'\xB5') self.WrByte_DAT(b'\x37') self.WrByte_DAT(b'\x0A') self.WrByte_DAT(b'\x0C') self.WrByte_DAT(b'\x07') self.WrByte_DAT(b'\x07') self.WrByte_DAT(b'\x05') self.WrByte_DAT(b'\x00') self.WrByte_CMD(b'\xE1') self.WrByte_DAT(b'\x00') #'negative gamma correction self.WrByte_DAT(b'\x24') self.WrByte_DAT(b'\x27') self.WrByte_DAT(b'\x04') self.WrByte_DAT(b'\x10') self.WrByte_DAT(b'\x06') self.WrByte_DAT(b'\x39') self.WrByte_DAT(b'\x74') self.WrByte_DAT(b'\x48') self.WrByte_DAT(b'\x05') self.WrByte_DAT(b'\x13') self.WrByte_DAT(b'\x38') self.WrByte_DAT(b'\x38') self.WrByte_DAT(b'\x3A') self.WrByte_DAT(b'\x1F') self.WrByte_CMD(b'\x2A') self.WrByte_DAT(b'\x00') #'column address set (set horizontal window to full screen) self.WrByte_DAT(b'\x00') #'start b'\x00 self.WrByte_DAT(b'\x01') self.WrByte_DAT(b'\x3F') #'end b'\x013F =320-1 self.WrByte_CMD(b'\x2B') self.WrByte_DAT(b'\x00') #'page address set (set vertical window to full screen) self.WrByte_DAT(b'\x00') #start b'\x00 self.WrByte_DAT(b'\x00') self.WrByte_DAT(b'\xEF') #end b'\xEF =240-1 self.WrByte_CMD(b'\x29') #display on self.WrByte_CMD(b'\x2C') #write pixels def WrByte_CMD(self, d): self.data[1]=int.from_bytes(d,"big") self.data[0]=self.WrByte_CMD_ self.WaitDone() def WrByte_DAT(self, d): self.data[1]=int.from_bytes(d,"big") self.data[0]=self.WrByte_DAT_ self.WaitDone() def WrBy