diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-02-08 07:49:38 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-02-08 07:49:38 (GMT) |
| commit | bb033577dafc71e43a1c66c212cca806d862b657 (patch) | |
| tree | 454b6e2781f631493d7115d980c08adf7dbb3486 | |
| parent | bfebf4c25045d0aa21b9ee430904819b4aaeacea (diff) | |
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.
| -rw-r--r-- | wasp/boards/simulator/micropython.py | 19 | ||||
| -rw-r--r-- | wasp/drivers/st7789.py | 20 |
2 files changed, 30 insertions, 9 deletions
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 |
