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 /wasp/drivers | |
| 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.
Diffstat (limited to 'wasp/drivers')
| -rw-r--r-- | wasp/drivers/st7789.py | 20 |
1 files changed, 15 insertions, 5 deletions
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 |
