summaryrefslogtreecommitdiff
path: root/wasp/drivers
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-08 20:50:42 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-08 20:50:42 (GMT)
commitfd64abe882a2064bad0131424835c169e365d83f (patch)
treed63acda8b2afb03e8ed6ee4f5dfea48d9f30f2a7 /wasp/drivers
parentac61d8a1c114d7f4ca8000afc02c843db5fd6245 (diff)
wasp: draw565: Optimize the 2-bit RLE drawing functions
There's a bunch of different changes here but there are only really three big wins. The biggest win comes from restructuring the 2-bit RLE decode loop to avoid the inner function (~20%) but the switch to 16-bit writes in _fill() and adoption of quick_write (e.g. no CS toggling) are also note worthy (and about 5% each).
Diffstat (limited to 'wasp/drivers')
-rw-r--r--wasp/drivers/st7789.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/wasp/drivers/st7789.py b/wasp/drivers/st7789.py
index 980435b..aca89db 100644
--- a/wasp/drivers/st7789.py
+++ b/wasp/drivers/st7789.py
@@ -121,13 +121,13 @@ class ST7789(object):
class ST7789_SPI(ST7789):
def __init__(self, width, height, spi, cs, dc, res=None, rate=8000000):
- self.spi = spi
- self.dc = dc
+ self.quick_write = spi.write
+ self.cs = cs.value
+ self.dc = dc.value
self.res = res
- self.cs = cs
self.rate = rate
- #self.spi.init(baudrate=self.rate, polarity=1, phase=1)
+ #spi.init(baudrate=self.rate, polarity=1, phase=1)
cs.init(cs.OUT, value=1)
dc.init(dc.OUT, value=0)
if res:
@@ -145,13 +145,23 @@ class ST7789_SPI(ST7789):
sleep_ms(125)
def write_cmd(self, cmd):
- self.dc(0)
- self.cs(0)
- self.spi.write(bytearray([cmd]))
- self.cs(1)
- self.dc(1)
+ dc = self.dc
+ cs = self.cs
+
+ dc(0)
+ cs(0)
+ self.quick_write(bytearray([cmd]))
+ cs(1)
+ dc(1)
def write_data(self, buf):
+ cs = self.cs
+ cs(0)
+ self.quick_write(buf)
+ cs(1)
+
+ def quick_start(self):
self.cs(0)
- self.spi.write(buf)
+
+ def quick_end(self):
self.cs(1)