From f36920fb3689a09e400f2f48dfe3ce108e811527 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Wed, 12 May 2021 15:21:13 +0300 Subject: [PATCH 1/3] st7789/st7789_4bit.py little speedup, split=5 --- drivers/st7789/st7789_4bit.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/st7789/st7789_4bit.py b/drivers/st7789/st7789_4bit.py index ef1ae70..ff3ac4a 100644 --- a/drivers/st7789/st7789_4bit.py +++ b/drivers/st7789/st7789_4bit.py @@ -79,6 +79,7 @@ class ST7789(framebuf.FrameBuffer): super().__init__(buf, width, height, mode) self._linebuf = bytearray(self.width * 2) # 16 bit color out self._init(disp_mode, orientation) + self.fill(0) self.show() # Hardware reset @@ -191,12 +192,13 @@ class ST7789(framebuf.FrameBuffer): #@micropython.native # Made virtually no difference to timing. def show(self): # Blocks for 83ms @60MHz SPI - # Blocks for 60ms @30MHz SPI on TTGO ESP32 + # Blocks for 60ms @30MHz SPI on TTGO in PORTRAIT mode + # Blocks for 46ms @30MHz SPI on TTGO in LANDSCAPE mode #ts = ticks_us() clut = ST7789.lut wd = -(-self.width // 2) # Ceiling division for odd number widths end = self.height * wd - lb = self._linebuf + lb = memoryview(self._linebuf) buf = self._mvb if self._spi_init: # A callback was passed self._spi_init(self._spi) # Bus may be shared @@ -211,14 +213,14 @@ class ST7789(framebuf.FrameBuffer): #print(ticks_diff(ticks_us(), ts)) # Asynchronous refresh with support for reducing blocking time. - async def do_refresh(self, split=4): + async def do_refresh(self, split=5): async with self._lock: lines, mod = divmod(self.height, split) # Lines per segment if mod: raise ValueError('Invalid do_refresh arg.') clut = ST7789.lut wd = -(-self.width // 2) - lb = self._linebuf + lb = memoryview(self._linebuf) buf = self._mvb line = 0 for n in range(split): From 4b283e31220c08f6e834e85e39a8f9aca1874dd6 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Thu, 13 May 2021 10:50:02 +0300 Subject: [PATCH 2/3] st7789_4bit.py: Prevents a white screen when the first time self.show() is called in __init__(). --- drivers/st7789/st7789_4bit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/st7789/st7789_4bit.py b/drivers/st7789/st7789_4bit.py index ff3ac4a..74068ae 100644 --- a/drivers/st7789/st7789_4bit.py +++ b/drivers/st7789/st7789_4bit.py @@ -46,6 +46,8 @@ def _lcopy(dest:ptr16, source:ptr8, lut:ptr16, length:int): class ST7789(framebuf.FrameBuffer): lut = bytearray(32) + for i in range(len(lut)): + lut[i] = 0xFF # set all colors to BLACK # Convert r, g, b in range 0-255 to a 16 bit colour value rgb565. # LS byte goes into LUT offset 0, MS byte into offset 1 @@ -79,7 +81,6 @@ class ST7789(framebuf.FrameBuffer): super().__init__(buf, width, height, mode) self._linebuf = bytearray(self.width * 2) # 16 bit color out self._init(disp_mode, orientation) - self.fill(0) self.show() # Hardware reset From b306d38e1d094cd853988e9de4ef3a66b0d3718d Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Thu, 13 May 2021 14:30:41 +0300 Subject: [PATCH 3/3] st7789_4bit.py: Cheaper version of BLACK color initialization --- drivers/st7789/st7789_4bit.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/st7789/st7789_4bit.py b/drivers/st7789/st7789_4bit.py index 74068ae..1aaacf1 100644 --- a/drivers/st7789/st7789_4bit.py +++ b/drivers/st7789/st7789_4bit.py @@ -45,9 +45,7 @@ def _lcopy(dest:ptr16, source:ptr8, lut:ptr16, length:int): class ST7789(framebuf.FrameBuffer): - lut = bytearray(32) - for i in range(len(lut)): - lut[i] = 0xFF # set all colors to BLACK + lut = bytearray(0xFF for _ in range(32)) # set all colors to BLACK # Convert r, g, b in range 0-255 to a 16 bit colour value rgb565. # LS byte goes into LUT offset 0, MS byte into offset 1