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>
This commit is contained in:
Daniel Thompson 2021-01-17 16:08:27 +00:00
parent 2fe3ac1388
commit 5abae5a7f6

View file

@ -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.