Improve display driver Viper code.

pull/48/head
Peter Hinch 2024-05-13 18:04:19 +01:00
rodzic 9e9f076d1b
commit 4c20bae0b0
3 zmienionych plików z 18 dodań i 11 usunięć

Wyświetl plik

@ -11,8 +11,7 @@ import asyncio
from drivers.boolpalette import BoolPalette from drivers.boolpalette import BoolPalette
# Initialisation ported from Russ Hughes' C driver # Initialisation ported from Russ Hughes' C driver
# https://github.com/russhughes/gc9a01_mpy/blob/main/src/gc9a01.h # https://github.com/russhughes/gc9a01_mpy/
# https://github.com/russhughes/gc9a01_mpy/blob/main/src/gc9a01.c
# Based on a ST7789 C driver: https://github.com/devbis/st7789_mpy # Based on a ST7789 C driver: https://github.com/devbis/st7789_mpy
# Many registers are undocumented. Lines initialising them are commented "?" # Many registers are undocumented. Lines initialising them are commented "?"
# in cases where initialising them seems to have no effect. # in cases where initialising them seems to have no effect.
@ -21,7 +20,7 @@ from drivers.boolpalette import BoolPalette
# Waveshare touch board https://www.waveshare.com/wiki/1.28inch_Touch_LCD has CST816S touch controller # Waveshare touch board https://www.waveshare.com/wiki/1.28inch_Touch_LCD has CST816S touch controller
# Touch controller uses I2C # Touch controller uses I2C
# Portrait mode # Portrait mode. ~70μs on RP2 at standard clock.
@micropython.viper @micropython.viper
def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int): def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int):
# rgb565 - 16bit/pixel # rgb565 - 16bit/pixel
@ -84,7 +83,7 @@ class GC9A01(framebuf.FrameBuffer):
sleep_ms(50) sleep_ms(50)
if self._spi_init: # A callback was passed if self._spi_init: # A callback was passed
self._spi_init(spi) # Bus may be shared self._spi_init(spi) # Bus may be shared
self._lock = asyncio.Lock() self._lock = asyncio.Lock() # Prevent concurrent refreshes.
sleep_ms(100) sleep_ms(100)
self._wcd(b"\x2a", int.to_bytes(width - 1, 4, "big")) self._wcd(b"\x2a", int.to_bytes(width - 1, 4, "big"))
# Default page address start == 0 end == 0xEF (239) # Default page address start == 0 end == 0xEF (239)

Wyświetl plik

@ -1,6 +1,6 @@
# ILI9341 nano-gui driver for ili9341 displays # ILI9341 nano-gui driver for ili9341 displays
# Copyright (c) Peter Hinch 2020 # Copyright (c) Peter Hinch 2020-2024
# Released under the MIT license see LICENSE # Released under the MIT license see LICENSE
# This work is based on the following sources. # This work is based on the following sources.
@ -15,16 +15,20 @@ import asyncio
from drivers.boolpalette import BoolPalette from drivers.boolpalette import BoolPalette
# ~80μs on RP2 @ 250MHz.
@micropython.viper @micropython.viper
def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int): def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int):
# rgb565 - 16bit/pixel # rgb565 - 16bit/pixel
n = 0 n: int = 0
for x in range(length): x: int = 0
while length:
c = source[x] c = source[x]
dest[n] = lut[c >> 4] # current pixel dest[n] = lut[c >> 4] # current pixel
n += 1 n += 1
dest[n] = lut[c & 0x0F] # next pixel dest[n] = lut[c & 0x0F] # next pixel
n += 1 n += 1
x += 1
length -= 1
class ILI9341(framebuf.FrameBuffer): class ILI9341(framebuf.FrameBuffer):

Wyświetl plik

@ -1,6 +1,6 @@
# ILI9486 nano-gui driver for ili9486 displays # ILI9486 nano-gui driver for ili9486 displays
# Copyright (c) Peter Hinch 2022 # Copyright (c) Peter Hinch 2022-2024
# Released under the MIT license see LICENSE # Released under the MIT license see LICENSE
# Much help provided by @brave-ulysses in this thread # Much help provided by @brave-ulysses in this thread
@ -22,13 +22,16 @@ from drivers.boolpalette import BoolPalette
@micropython.viper @micropython.viper
def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int): def _lcopy(dest: ptr16, source: ptr8, lut: ptr16, length: int):
# rgb565 - 16bit/pixel # rgb565 - 16bit/pixel
n = 0 n: int = 0
for x in range(length): x: int = 0
while length:
c = source[x] c = source[x]
dest[n] = lut[c >> 4] # current pixel dest[n] = lut[c >> 4] # current pixel
n += 1 n += 1
dest[n] = lut[c & 0x0F] # next pixel dest[n] = lut[c & 0x0F] # next pixel
n += 1 n += 1
x += 1
length -= 1
# FB is in landscape mode, hence issue a column at a time to portrait mode hardware. # FB is in landscape mode, hence issue a column at a time to portrait mode hardware.
@ -41,7 +44,7 @@ def _lscopy(dest: ptr16, source: ptr8, lut: ptr16, ch: int):
n = 0 n = 0
clsb = col & 1 clsb = col & 1
idx = col >> 1 # 2 pixels per byte idx = col >> 1 # 2 pixels per byte
for _ in range(height): while height:
if clsb: if clsb:
c = source[idx] & 0x0F c = source[idx] & 0x0F
else: else:
@ -49,6 +52,7 @@ def _lscopy(dest: ptr16, source: ptr8, lut: ptr16, ch: int):
dest[n] = lut[c] # 16 bit transfer of rightmost 4-bit pixel dest[n] = lut[c] # 16 bit transfer of rightmost 4-bit pixel
n += 1 # 16 bit n += 1 # 16 bit
idx += wbytes idx += wbytes
height -= 1
class ILI9486(framebuf.FrameBuffer): class ILI9486(framebuf.FrameBuffer):