From 5abae5a7f63f6841744ad63e7c8bbbb1d8452b37 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 17 Jan 2021 16:08:27 +0000 Subject: drivers: st7789: Optimize set_window() For small graphical items (line drawing, font glyphs) the performance of the set_window() method is critical. Emit native code for this function and optimize the SPI write_cmd() method to avoid memory allocation. This give a performance boost of a little over 15% for (24pt) font rendering and 30% for line drawing. Signed-off-by: Daniel Thompson diff --git a/wasp/drivers/st7789.py b/wasp/drivers/st7789.py index be4b109..e689e4e 100644 --- a/wasp/drivers/st7789.py +++ b/wasp/drivers/st7789.py @@ -105,6 +105,7 @@ class ST7789(object): else: self.write_cmd(_DISPON) + @micropython.native def set_window(self, x=0, y=0, width=None, height=None): """Set the clipping rectangle. @@ -202,6 +203,7 @@ class ST7789_SPI(ST7789): self.dc = dc.value self.res = res self.rate = rate + self.cmd = bytearray(1) #spi.init(baudrate=self.rate, polarity=1, phase=1) cs.init(cs.OUT, value=1) @@ -225,6 +227,7 @@ class ST7789_SPI(ST7789): self.write_cmd(_SWRESET) sleep_ms(125) + @micropython.native def write_cmd(self, cmd): """Send a command opcode to the display. @@ -233,13 +236,16 @@ class ST7789_SPI(ST7789): """ dc = self.dc cs = self.cs + c = self.cmd dc(0) cs(0) - self.quick_write(bytearray([cmd])) + c[0] = cmd + self.quick_write(c) cs(1) dc(1) + @micropython.native def write_data(self, buf): """Send data to the display. -- cgit v0.10.2