From bb033577dafc71e43a1c66c212cca806d862b657 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 8 Feb 2020 07:49:38 +0000 Subject: drivers: st7789: Optimize RLE decoding loop Migrate the filling of the line buffer into a seperate function. This does naturally reduce the cost of the loop management but much more importantly allows us to use viper native code generator. diff --git a/wasp/boards/simulator/micropython.py b/wasp/boards/simulator/micropython.py index a5740f1..578a12d 100644 --- a/wasp/boards/simulator/micropython.py +++ b/wasp/boards/simulator/micropython.py @@ -1,5 +1,16 @@ -def const(x): - return x +def const(fn): + return fn + +def native(fn): + return fn + +def viper(fn): + def ptr8(buf): + return buf + + # This is a bit of a hack since the scope for ptr8 won't be right + # but it does mean no changes to the client + fn.__globals__['ptr8'] = ptr8 + + return fn -def native(x): - return x diff --git a/wasp/drivers/st7789.py b/wasp/drivers/st7789.py index d96d417..1ec1ed4 100644 --- a/wasp/drivers/st7789.py +++ b/wasp/drivers/st7789.py @@ -19,6 +19,16 @@ _RAMWR = const(0x2c) _COLMOD = const(0x3a) _MADCTL = const(0x36) +@micropython.viper +def fastfill(mv, color: int, count: int, offset: int): + p = ptr8(mv) + colorhi = color >> 8 + colorlo = color & 0xff + + for x in range(count): + p[2*(x+offset) ] = colorhi + p[2*(x+offset) + 1] = colorlo + class ST7789(object): def __init__(self, width, height): self.width = width @@ -111,12 +121,12 @@ class ST7789(object): for rl in rle: while rl: - buf[bp] = color >> 8 - buf[bp+1] = color & 0xff - bp += 2 - rl -= 1 + count = min(sx - bp, rl) + fastfill(buf, color, count, bp) + bp += count + rl -= count - if bp >= (2*sx): + if bp >= sx: self.write_data(buf) bp = 0 -- cgit v0.10.2