1
0
Fork 0

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.
This commit is contained in:
Daniel Thompson 2020-02-08 07:49:38 +00:00
parent bfebf4c250
commit bb033577da
2 changed files with 30 additions and 9 deletions

View file

@ -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

View file

@ -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