summaryrefslogtreecommitdiff
path: root/wasp/drivers/st7789.py
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2021-01-17 16:08:27 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2021-01-17 16:08:27 (GMT)
commit5abae5a7f63f6841744ad63e7c8bbbb1d8452b37 (patch)
tree0b00a22d335198db2febb80e681746cf013d6139 /wasp/drivers/st7789.py
parent2fe3ac1388aa14bafe25fb525f61bc77dd31fb21 (diff)
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 <daniel@redfelineninja.org.uk>
Diffstat (limited to 'wasp/drivers/st7789.py')
-rw-r--r--wasp/drivers/st7789.py8
1 files changed, 7 insertions, 1 deletions
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.