def LCD_Reset(self): GPIO.output(LCD_Config.LCD_RST_PIN, GPIO.HIGH) LCD_Config.Driver_Delay_ms(100) GPIO.output(LCD_Config.LCD_RST_PIN, GPIO.LOW) LCD_Config.Driver_Delay_ms(100) GPIO.output(LCD_Config.LCD_RST_PIN, GPIO.HIGH) LCD_Config.Driver_Delay_ms(100)
def LCD_Clear(self): # hello _buffer = [0xFF] * (self.width * self.height * 2) self.LCD_SetWindows(0, 0, self.width, self.height) GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) for i in range(0, len(_buffer), 4096): LCD_Config.SPI_Write_Byte(_buffer[i:i + 4096])
def LCD_Init(self, Lcd_ScanDir): if LCD_Config.GPIO_Init() != 0: return -1 # Turn on the backlight GPIO.output(LCD_Config.LCD_BL_PIN, GPIO.HIGH) # Hardware reset self.LCD_Reset() # Set the initialization register self.LCD_InitReg() # Set the display scan and color transfer modes self.LCD_SetGramScanWay(Lcd_ScanDir) LCD_Config.Driver_Delay_ms(200) # sleep out self.LCD_WriteReg(0x11) LCD_Config.Driver_Delay_ms(120) # Turn on the LCD display self.LCD_WriteReg(0x29)
def LCD_ShowImage(self, Image, Xstart, Ystart): if Image == None: return imwidth, imheight = Image.size if imwidth != self.width or imheight != self.height: raise ValueError("Image must be same dimensions as display \ ({0}x{1}).".format(self.width, self.height)) img = np.asarray(Image) pix = np.zeros((self.width, self.height, 2), dtype=np.uint8) pix[..., [0]] = np.add(np.bitwise_and(img[..., [0]], 0xF8), np.right_shift(img[..., [1]], 5)) pix[..., [1]] = np.add( np.bitwise_and(np.left_shift(img[..., [1]], 3), 0xE0), np.right_shift(img[..., [2]], 3)) pix = pix.flatten().tolist() self.LCD_SetWindows(0, 0, self.width, self.height) GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) for i in range(0, len(pix), 4096): LCD_Config.SPI_Write_Byte(pix[i:i + 4096])
def LCD_WriteData_NLen16Bit(self, Data, DataLen): GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) for i in range(0, DataLen): LCD_Config.SPI_Write_Byte([Data >> 8]) LCD_Config.SPI_Write_Byte([Data & 0xFF])
def LCD_WriteData_8bit(self, Data): GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH) LCD_Config.SPI_Write_Byte([Data])
def LCD_WriteReg(self, Reg): GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.LOW) LCD_Config.SPI_Write_Byte([Reg])