I have styled my driver to be similar to yours in structure, just with a change in self.style and buffer size to account for screen size and style (320 * 240 //2). My show function is also almost identicale, just wiuth 2 extra commands to set the limit of the write as required by the ili9341 display. The main difference I can see is in the _lcopy function.
Code: Select all
@micropython.viper
def _lcopy(dest, source, length:int):
n = 0
for x in range(length):
# First nibble is pixel 1
c = source[x]
color = color4to565(int(c) >> 4)
dest[n] = int(color) >> 8 # Blue green
n += 1
dest[n] = int(color) & 0xff # Red
n += 1
# Second nibble is pixel 2
color = color4to565(int(c) & 15)
dest[n] = int(color) >> 8 # Blue green
n += 1
dest[n] = int(color) & 0xff # Red
n += 1
Code: Select all
@micropython.viper
def color4to565(c:int) -> int:
clup = [ 0,30720, 992,31712,
15,30735, 1007,25388,
52825,63488, 2016,65504,
31,63519, 2047,65535]
return int(clup[c])