build(boards): xpython板卡执行 npm run build:prod

This commit is contained in:
王立帮
2025-12-14 21:18:41 +08:00
parent 26bae5da89
commit 0ff5878d5f
416 changed files with 12404 additions and 48341 deletions

View File

@@ -8,26 +8,7 @@ MicroPython library for the ST7789(TFT-SPI)
import time
import uframebuf
from machine import Pin
from jpeg import Decoder
from micropython import const
_CMD_SWRESET = const(0x01)
_CMD_SLPIN = const(0x10)
_CMD_SLPOUT = const(0x11)
_CMD_PTLON = const(0x12)
_CMD_NORON = const(0x13)
_CMD_INVOFF = const(0x20)
_CMD_INVON = const(0x21)
_CMD_DISPOFF = const(0x28)
_CMD_DISPON = const(0x29)
_CMD_CASET = const(0x2A)
_CMD_RASET = const(0x2B)
_CMD_RAMWR = const(0x2C)
_CMD_RAMRD = const(0x2E)
_CMD_PTLAR = const(0x30)
_CMD_VSCRDEF = const(0x33)
_CMD_COLMOD = const(0x3A)
_CMD_MADCTL = const(0x36)
from camera import Image, IMG
class ST7789(uframebuf.FrameBuffer_Uincode):
def __init__(self, spi, width, height, dc_pin=None, backlight=None, reset=None, font_address=0x700000):
@@ -35,25 +16,25 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
self.dc = Pin(dc_pin, Pin.OUT, value=1)
self._buffer = bytearray(width * height * 2)
super().__init__(self._buffer, width, height, uframebuf.RGB565)
reset(1, 100)
if reset: reset(1, 100)
self.font(font_address)
self._init()
# self.show()
self._oneclight = True
self._backlight = backlight
def display(self, data=None, rotation=0, sync=True):
def display(self, data=None, x=None, y=None, scale_width=None, scale_height=None, rotation=0, sync=True):
if type(data) is str:
with open(data, "rb") as f:
_jpeg = f.read()
_decoder = Decoder(pixel_format="RGB565_BE", rotation=rotation)
self._buffer[:] = _decoder.decode(_jpeg)
del _decoder
data = Image.open(data, scale_width, scale_height, self.width, self.height, rotation=rotation)
if sync: self.fill(0x0, sync=False)
self.blit_rgb565(data.image, data.width, data.height, x, y)
if sync: self.show()
def screenshot(self, x=0, y=0, w=None, h=None):
if (w is None and h is None):
return IMG(memoryview(self._buffer), self.width, self.height)
else:
self._buffer[:] = data # 后期做图像大小处理
if sync:
self.show()
return self._buffer
return IMG(memoryview(self.crop_rgb565(x,y,w,h)), w, h)
def _write(self, cmd, dat=None):
self.dc.off()
@@ -65,23 +46,24 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
def _init(self):
"""Display initialization configuration"""
for cmd, data, delay in [
# (_CMD_SWRESET, None, 20000),
(_CMD_SLPOUT, None, 120000),
(_CMD_MADCTL, b'\x00', 50),
(_CMD_COLMOD, b'\x05', 50),
(0xB2, b'\x0c\x0c\x00\x33\x33', 10),
(0xB7, b'\x35', 10),
(0xBB, b'\x19', 10),
(0x11, None, 120000),
(0x36, b'\x00', 50),
(0x3A, b'\x05', 50),
(0xB2, b'\x1F\x1F\x00\x33\x33', 10),
(0xB7, b'\x00', 10),
(0xBB, b'\x36', 10),
(0xC0, b'\x2C', 10),
(0xC2, b'\x01', 10),
(0xC3, b'\x12', 10),
(0xC3, b'\x13', 10),
(0xC4, b'\x20', 10),
(0xC6, b'\x0F', 10),
(0xC6, b'\x13', 10),
(0xD0, b'\xA4\xA1', 10),
(0xE0, b'\xD0\x04\x0D\x11\x13\x2B\x3F\x54\x4C\x18\x0D\x0B\x1F\x23', 10),
(0xE1, b'\xD0\x04\x0C\x11\x13\x2C\x3F\x44\x51\x2F\x1F\x1F\x20\x23', 10),
(_CMD_INVON, None, 10),
(_CMD_DISPON, None, 10),
(0xD6, b'\xA1', 10),
(0xE0, b'\xF0\x08\x0E\x09\x08\x04\x2F\x33\x45\x36\x13\x12\x2A\x2D', 10),
(0xE1, b'\xF0\x0E\x12\x0C\x0A\x15\x2E\x32\x44\x39\x17\x18\x2B\x2F', 10),
(0xE4, b'\x1D\x00\x00', 10),
(0x21, None, 10),
(0x29, None, 10),
]:
self._write(cmd, data)
if delay:
@@ -108,6 +90,6 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
if self._oneclight:
self.set_brightness(0.6)
self._oneclight = False
self._write(_CMD_CASET, b'\x00\x00\x00\xef')
self._write(_CMD_RASET, b'\x00\x00\x00\xef')
self._write(_CMD_RAMWR, self._buffer)
self._write(0x2A, b'\x00\x00\x00\xef')
self._write(0x2B, b'\x00\x00\x00\xef')
self._write(0x2C, self._buffer)