diff --git a/pwnagotchi/ui/hw/libs/waveshare/lcdhat/ST7789.py b/pwnagotchi/ui/hw/libs/waveshare/lcdhat/ST7789.py index 0edd1d1..88409ec 100644 --- a/pwnagotchi/ui/hw/libs/waveshare/lcdhat/ST7789.py +++ b/pwnagotchi/ui/hw/libs/waveshare/lcdhat/ST7789.py @@ -7,24 +7,25 @@ import numpy as np class ST7789(object): """class for ST7789 240*240 1.3inch OLED displays.""" - def __init__(self,spi,rst = 27,dc = 25,bl = 24): + def __init__(self, spi, rst=27, dc=25, bl=24): self.width = 240 self.height = 240 - #Initialize DC RST pin + # Initialize DC RST pin self._dc = dc self._rst = rst self._bl = bl GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) - GPIO.setup(self._dc,GPIO.OUT) - GPIO.setup(self._rst,GPIO.OUT) - GPIO.setup(self._bl,GPIO.OUT) + GPIO.setup(self._dc, GPIO.OUT) + GPIO.setup(self._rst, GPIO.OUT) + GPIO.setup(self._bl, GPIO.OUT) GPIO.output(self._bl, GPIO.HIGH) - #Initialize SPI + # Initialize SPI self._spi = spi self._spi.max_speed_hz = 40000000 """ Write register address and data """ + def command(self, cmd): GPIO.output(self._dc, GPIO.LOW) self._spi.writebytes([cmd]) @@ -34,13 +35,13 @@ class ST7789(object): self._spi.writebytes([val]) def Init(self): - """Initialize dispaly""" + """Initialize dispaly""" self.reset() self.command(0x36) - self.data(0x70) #self.data(0x00) + self.data(0x70) # self.data(0x00) - self.command(0x3A) + self.command(0x3A) self.data(0x05) self.command(0xB2) @@ -51,7 +52,7 @@ class ST7789(object): self.data(0x33) self.command(0xB7) - self.data(0x35) + self.data(0x35) self.command(0xBB) self.data(0x19) @@ -63,13 +64,13 @@ class ST7789(object): self.data(0x01) self.command(0xC3) - self.data(0x12) + self.data(0x12) self.command(0xC4) self.data(0x20) self.command(0xC6) - self.data(0x0F) + self.data(0x0F) self.command(0xD0) self.data(0xA4) @@ -106,7 +107,7 @@ class ST7789(object): self.data(0x1F) self.data(0x20) self.data(0x23) - + self.command(0x21) self.command(0x11) @@ -115,51 +116,51 @@ class ST7789(object): def reset(self): """Reset the display""" - GPIO.output(self._rst,GPIO.HIGH) + GPIO.output(self._rst, GPIO.HIGH) time.sleep(0.01) - GPIO.output(self._rst,GPIO.LOW) + GPIO.output(self._rst, GPIO.LOW) time.sleep(0.01) - GPIO.output(self._rst,GPIO.HIGH) + GPIO.output(self._rst, GPIO.HIGH) time.sleep(0.01) - + def SetWindows(self, Xstart, Ystart, Xend, Yend): - #set the X coordinates + # set the X coordinates self.command(0x2A) - self.data(0x00) #Set the horizontal starting point to the high octet - self.data(Xstart & 0xff) #Set the horizontal starting point to the low octet - self.data(0x00) #Set the horizontal end to the high octet - self.data((Xend - 1) & 0xff) #Set the horizontal end to the low octet - - #set the Y coordinates + self.data(0x00) # Set the horizontal starting point to the high octet + self.data(Xstart & 0xff) # Set the horizontal starting point to the low octet + self.data(0x00) # Set the horizontal end to the high octet + self.data((Xend - 1) & 0xff) # Set the horizontal end to the low octet + + # set the Y coordinates self.command(0x2B) self.data(0x00) self.data((Ystart & 0xff)) self.data(0x00) - self.data((Yend - 1) & 0xff ) + self.data((Yend - 1) & 0xff) - self.command(0x2C) - - def ShowImage(self,Image,Xstart,Ystart): + self.command(0x2C) + + def ShowImage(self, Image, Xstart, Ystart): """Set buffer to value of Python Imaging Library image.""" """Write display buffer to physical display""" 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)) + ({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 = 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.SetWindows ( 0, 0, self.width, self.height) - GPIO.output(self._dc,GPIO.HIGH) - for i in range(0,len(pix),4096): - self._spi.writebytes(pix[i:i+4096]) - + self.SetWindows(0, 0, self.width, self.height) + GPIO.output(self._dc, GPIO.HIGH) + for i in range(0, len(pix), 4096): + self._spi.writebytes(pix[i:i + 4096]) + def clear(self): """Clear contents of image buffer""" - _buffer = [0xff]*(self.width * self.height * 2) - self.SetWindows ( 0, 0, self.width, self.height) - GPIO.output(self._dc,GPIO.HIGH) - for i in range(0,len(_buffer),4096): - self._spi.writebytes(_buffer[i:i+4096]) + _buffer = [0xff] * (self.width * self.height * 2) + self.SetWindows(0, 0, self.width, self.height) + GPIO.output(self._dc, GPIO.HIGH) + for i in range(0, len(_buffer), 4096): + self._spi.writebytes(_buffer[i:i + 4096]) diff --git a/pwnagotchi/ui/hw/libs/waveshare/lcdhat/config.py b/pwnagotchi/ui/hw/libs/waveshare/lcdhat/config.py index a319364..24b5cc8 100644 --- a/pwnagotchi/ui/hw/libs/waveshare/lcdhat/config.py +++ b/pwnagotchi/ui/hw/libs/waveshare/lcdhat/config.py @@ -7,70 +7,15 @@ # * | Date : 2019-10-18 # * | Info : # ******************************************************************************/ - -import RPi.GPIO as GPIO -import time -from smbus import SMBus import spidev -import ctypes -# import spidev - # Pin definition -RST_PIN = 27 -DC_PIN = 25 -BL_PIN = 24 +RST_PIN = 27 +DC_PIN = 25 +BL_PIN = 24 Device_SPI = 1 Device_I2C = 0 Device = Device_SPI spi = spidev.SpiDev(0, 0) - -def digital_write(pin, value): - GPIO.output(pin, value) - -def digital_read(pin): - return GPIO.input(BUSY_PIN) - -def delay_ms(delaytime): - time.sleep(delaytime / 1000.0) - -def spi_writebyte(data): - # SPI.writebytes(data) - spi.writebytes([data[0]]) - -def i2c_writebyte(reg, value): - bus.write_byte_data(address, reg, value) - - # time.sleep(0.01) -def module_init(): - # print("module_init") - - GPIO.setmode(GPIO.BCM) - GPIO.setwarnings(False) - GPIO.setup(RST_PIN, GPIO.OUT) - GPIO.setup(DC_PIN, GPIO.OUT) - - - # SPI.max_speed_hz = 2000000 - # SPI.mode = 0b00 - # i2c_writebyte(0xff,0xff) - # spi.SYSFS_software_spi_begin() - # spi.SYSFS_software_spi_setDataMode(0); - # spi.SYSFS_software_spi_setClockDivider(1); - #spi.max_speed_hz = 2000000 - #spi.mode = 0b00 - - GPIO.output(BL_PIN, 1) - GPIO.output(DC_PIN, 0) - return 0 - -def module_exit(): - spi.SYSFS_software_spi_end() - GPIO.output(RST_PIN, 0) - GPIO.output(DC_PIN, 0) - - - -### END OF FILE ### diff --git a/pwnagotchi/ui/hw/libs/waveshare/lcdhat/epd.py b/pwnagotchi/ui/hw/libs/waveshare/lcdhat/epd.py index cd0d81f..1a559f4 100644 --- a/pwnagotchi/ui/hw/libs/waveshare/lcdhat/epd.py +++ b/pwnagotchi/ui/hw/libs/waveshare/lcdhat/epd.py @@ -1,28 +1,21 @@ from . import ST7789 from . import config -# Display resolution -EPD_WIDTH = 240 -EPD_HEIGHT = 240 - -disp = ST7789.ST7789(config.spi,config.RST_PIN, config.DC_PIN, config.BL_PIN) class EPD(object): - def __init__(self): self.reset_pin = config.RST_PIN self.dc_pin = config.DC_PIN - #self.busy_pin = config.BUSY_PIN - #self.cs_pin = config.CS_PIN - self.width = EPD_WIDTH - self.height = EPD_HEIGHT + self.width = 240 + self.height = 240 + self.st7789 = ST7789.ST7789(config.spi, config.RST_PIN, config.DC_PIN, config.BL_PIN) def init(self): - disp.Init() + self.st7789.Init() - def Clear(self): - disp.clear() + def clear(self): + self.st7789.clear() def display(self, image): rgb_im = image.convert('RGB') - disp.ShowImage(rgb_im,0,0) + self.st7789.ShowImage(rgb_im, 0, 0)