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:
parent
bfebf4c250
commit
bb033577da
2 changed files with 30 additions and 9 deletions
|
@ -1,5 +1,16 @@
|
||||||
def const(x):
|
def const(fn):
|
||||||
return x
|
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
|
|
||||||
|
|
|
@ -19,6 +19,16 @@ _RAMWR = const(0x2c)
|
||||||
_COLMOD = const(0x3a)
|
_COLMOD = const(0x3a)
|
||||||
_MADCTL = const(0x36)
|
_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):
|
class ST7789(object):
|
||||||
def __init__(self, width, height):
|
def __init__(self, width, height):
|
||||||
self.width = width
|
self.width = width
|
||||||
|
@ -111,12 +121,12 @@ class ST7789(object):
|
||||||
|
|
||||||
for rl in rle:
|
for rl in rle:
|
||||||
while rl:
|
while rl:
|
||||||
buf[bp] = color >> 8
|
count = min(sx - bp, rl)
|
||||||
buf[bp+1] = color & 0xff
|
fastfill(buf, color, count, bp)
|
||||||
bp += 2
|
bp += count
|
||||||
rl -= 1
|
rl -= count
|
||||||
|
|
||||||
if bp >= (2*sx):
|
if bp >= sx:
|
||||||
self.write_data(buf)
|
self.write_data(buf)
|
||||||
bp = 0
|
bp = 0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue