kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Full color mode working with fixed image_converter.py
rodzic
d47519f82a
commit
3d6b485f3d
|
@ -49,6 +49,7 @@ _ST7789_DISPON = b"\x29"
|
|||
_ST7789_CASET = b"\x2a"
|
||||
_ST7789_RASET = b"\x2b"
|
||||
_ST7789_RAMWR = b"\x2c"
|
||||
_ST7789_WRMEMC = b"\x3c"
|
||||
_ST7789_VSCRDEF = b"\x33"
|
||||
_ST7789_COLMOD = b"\x3a"
|
||||
_ST7789_MADCTL = b"\x36"
|
||||
|
@ -261,27 +262,28 @@ class ST7789(framebuf.FrameBuffer):
|
|||
self._cs(1)
|
||||
|
||||
# Asynchronous refresh with support for reducing blocking time.
|
||||
async def ddo_refresh(self, split=5):
|
||||
async def do_refresh(self, split=5):
|
||||
async with self._lock:
|
||||
lines, mod = divmod(self.height, split) # Lines per segment
|
||||
if mod:
|
||||
raise ValueError("Invalid do_refresh arg.")
|
||||
#clut = ST7789.lut
|
||||
wd = -(-self.width // 2)
|
||||
lb = memoryview(self._linebuf)
|
||||
cm = self._gscale # color False, greyscale True
|
||||
|
||||
bw = self.width * 2
|
||||
end = self.height * self.width * 2
|
||||
buf = self.mvb
|
||||
|
||||
line = 0
|
||||
for n in range(split):
|
||||
if self._spi_init: # A callback was passed
|
||||
self._spi_init(self._spi) # Bus may be shared
|
||||
|
||||
self._dc(0)
|
||||
self._cs(0)
|
||||
self._spi.write(b"\x3c" if n else b"\x2c") # RAMWR/Write memory continue
|
||||
self._spi.write(_ST7789_WRMEMC if n else _ST7789_RAMWR) # RAMWR/Write memory continue
|
||||
self._dc(1)
|
||||
for start in range(wd * line, wd * (line + lines), wd):
|
||||
#_lcopy(lb, buf[start:], 0xffff, wd, cm) # Copy and map colors
|
||||
self._spi.write(buf[start : start + wd])
|
||||
|
||||
for start in range(bw * line, bw * (line + lines), bw):
|
||||
self._spi.write(buf[start : start + bw])
|
||||
line += lines
|
||||
self._cs(1)
|
||||
await asyncio.sleep(0)
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
from gui.core.ugui import Widget
|
||||
from gui.core.colors import *
|
||||
from gui.core.ugui import ssd
|
||||
import struct
|
||||
|
||||
def little_to_big_endian(value):
|
||||
# A Helper function to convert 16 bit int from little to big endian
|
||||
# Pack the value as little-endian
|
||||
packed = struct.pack(f'<H', value)
|
||||
# Unpack it as big-endian
|
||||
return struct.unpack(f'>H', packed)[0]
|
||||
|
||||
def transform_palette(color565):
|
||||
# change endian of the color from little to BIG
|
||||
col = (color565 & 0xFF00) >> 8 | color565 << 8
|
||||
# invert bitwise
|
||||
return col ^ 0xffff
|
||||
|
||||
|
||||
class ColorBitMap(Widget):
|
||||
|
||||
|
@ -36,7 +36,8 @@ class ColorBitMap(Widget):
|
|||
|
||||
# Transform palette to match display color format
|
||||
# this will be run for with all image palette members
|
||||
palette_transformer_cb = lambda self, x: ~little_to_big_endian(x) & 0xffff
|
||||
# I did not find good way of changing other than class variable.
|
||||
palette_transformer_cb = staticmethod(transform_palette)
|
||||
|
||||
def show(self):
|
||||
if not super().show(True): # Draw or erase border
|
||||
|
|
|
@ -58,7 +58,7 @@ def rgb_to_color565(r, g, b):
|
|||
int: Converted color value in the 16-bit color format (565).
|
||||
"""
|
||||
|
||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b & 0xF8)
|
||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
|
||||
|
||||
|
||||
def convert_to_bitmap(image_file, bits_requested):
|
||||
|
|
Ładowanie…
Reference in New Issue