summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2021-01-17 17:44:50 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2021-01-17 17:44:50 (GMT)
commitfbc806721e346e5c5727e7233c5c8f5e08270eac (patch)
tree33ac41218ad3f6b743738b3f9eefcab19cf97108
parent6b41c8f3db1778826ec8556f8900878a8f32c87a (diff)
drivers: st7789: Further reduce allocations during set_window()
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
-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 817c414..46404f9 100644
--- a/wasp/drivers/st7789.py
+++ b/wasp/drivers/st7789.py
@@ -45,6 +45,7 @@ class ST7789(object):
self.width = width
self.height = height
self.linebuffer = memoryview(bytearray(2 * width))
+ self.window = bytearray(4)
self.init_display()
def init_display(self):
@@ -106,7 +107,7 @@ class ST7789(object):
self.write_cmd(_DISPON)
@micropython.native
- def set_window(self, x=0, y=0, width=None, height=None):
+ def set_window(self, x, y, width, height):
"""Set the clipping rectangle.
All writes to the display will be wrapped at the edges of the rectangle.
@@ -118,19 +119,28 @@ class ST7789(object):
:param h: Height of the rectangle, defaults to None (which means select
the bottom-most pixel of the display)
"""
- if not width:
- width = self.width
- if not height:
- height = self.height
+ write_cmd = self.write_cmd
+ window = self.window
+ write_data = self.write_data
xp = x + width - 1
yp = y + height - 1
- self.write_cmd(_CASET)
- self.write_data(bytearray([x >> 8, x & 0xff, xp >> 8, xp & 0xff]))
- self.write_cmd(_RASET)
- self.write_data(bytearray([y >> 8, y & 0xff, yp >> 8, yp & 0xff]))
- self.write_cmd(_RAMWR)
+ write_cmd(_CASET)
+ window[0] = x >> 8
+ window[1] = x & 0xff
+ window[2] = xp >> 8
+ window[3] = xp & 0xff
+ write_data(window)
+
+ write_cmd(_RASET)
+ window[0] = y >> 8
+ window[1] = y & 0xff
+ window[2] = yp >> 8
+ window[3] = yp & 0xff
+ write_data(window)
+
+ write_cmd(_RAMWR)
def rawblit(self, buf, x, y, width, height):
"""Blit raw pixels to the display.