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

This commit is contained in:
王立帮
2025-07-12 18:26:50 +08:00
parent 04d3f373e7
commit 047c028587
53 changed files with 15427 additions and 325 deletions

View File

@@ -17,11 +17,11 @@ _BOT035_SPK = const(0x07)
_BOT035_PWM = const(0x0B)
_BOT035_FLAG = const(0x0F)
_BOT035_LEDS = const(0x10)
_BOT035_PGA = const(0x20)
_BOT035_KB = const(0x1C)
_BOT035_MS = const(0x20)
_BOT035_STR = const(0x24)
_BOT035_STA = const(0x25)
_BOT035_PCM = const(0x26)
_FONT_W = const(5)
_FONT_H = const(8)
_LEDS_W = const(12)
@@ -35,8 +35,8 @@ class BOT035(FrameBuffer):
self._buffer = bytearray(12)
self._brightness = brightness
self._touchs = [self.touch(0), self.touch(1)]
self._version = True if self._rreg(0x00) >= 0x27 else False
super().__init__(self._buffer, _LEDS_W, _LEDS_H, MONO_VLSB)
self.version()
self.reset()
self.show()
@@ -229,23 +229,29 @@ class BOT035(FrameBuffer):
def _rreg(self, reg, nbytes=1):
'''Read memory address'''
self._i2c.writeto(_BOT035_ADDRESS, reg.to_bytes(1, 'little'))
return self._i2c.readfrom(_BOT035_ADDRESS, nbytes)[0]
return self._i2c.readfrom(_BOT035_ADDRESS, nbytes)[0] if nbytes <= 1 else self._i2c.readfrom(_BOT035_ADDRESS, nbytes)
def version(self):
_ver = self._rreg(0x00)
if _ver == 0x26:
return "v1.7", "Only supports CDC serial port"
self._version = 0
return "v1.7", "Only support CDC serial port"
elif _ver == 0x27:
return "v2.5", "Composite devices (CDC, keyboard and mouse)"
self._version = 1
return "v2.5", "Composite devices (CDC, Keyboard and Mouse)"
elif _ver == 0x28:
return "v2.9", "Composite devices (CDC, HID, WEBUSB, Keyboard and mouse)"
self._version = 2
return "v2.9", "Composite devices (CDC, HID, WEBUSB, Keyboard and Mouse)"
elif _ver == 0x29:
self._version = 3
return "v3.0", "Composite devices (CDC, HID, WEBUSB, Keyboard and Mouse), Support PCM collection for MIC"
else:
return "vx.x", "Unknown, awaiting update"
def reset(self):
"""Reset SPK, PWM, HID registers to default state"""
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_SPK, b'\x0A\x00\x00\x00\x20\x4E\x64\x64')
if self._version: self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_KB, bytes(9))
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_SPK, b'\x0A\x00\x00\x00\x20\x4E\x64\x64\x28')
if self._version: self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_KB, bytes(10))
def get_brightness(self):
return self._brightness
@@ -254,7 +260,7 @@ class BOT035(FrameBuffer):
if not 0.0 <= brightness <= 1.0:
raise ValueError("Brightness must be a decimal number in the range: 0.0-1.0")
self._brightness = brightness
self._wreg(_BOT035_FLAG, _BOT035_PGA | round(10 * brightness))
self._wreg(_BOT035_FLAG, (self._rreg(_BOT035_FLAG) & 0x0F) | round(10 * brightness))
def show(self):
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_LEDS, self._buffer)
@@ -341,6 +347,47 @@ class BOT035(FrameBuffer):
else:
print("Warning: Please upgrade the coprocessor firmware to use this feature")
def mic_pga(self, value=None):
'''0:4x, 1:8x, 2:16x, 3:32x, 4:OFF'''
if value is None:
return self._rreg(_BOT035_FLAG) >> 4
else:
self._wreg(_BOT035_FLAG, (self._rreg(_BOT035_FLAG) & 0x0F) | (value & 0x03) << 4)
def pcm_en(self, power=None):
if self._version >= 3:
if power is None:
return bool(self._rreg(_BOT035_STA) & 0x08)
else:
self._wreg(_BOT035_STA, (self._rreg(_BOT035_STA) & 0xF7) | (power & 0x01) << 3)
else:
print("Warning: Please upgrade the coprocessor firmware to use this feature")
def pcm_any(self):
return bool(self._rreg(_BOT035_STA) & 0x80)
def pcm_read(self, ibuf=1600):
return self._rreg(_BOT035_PCM, ibuf)
def pcm_record(self, path='mixly.wav', seconds=5, ibuf=1600, timeout=2000):
if self._version >= 3:
self.pcm_en(True)
_star = time.ticks_ms()
_size = int(ibuf * seconds * 10)
_header = b'RIFF' + (36 + _size).to_bytes(4, 'little') + b'WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00' + (ibuf * 5).to_bytes(4, 'little') + (ibuf * 10).to_bytes(4, 'little') + b'\x02\x00\x10\x00data' + _size.to_bytes(4, 'little')
with open(path, 'wb') as f:
f.write(_header)
while _size > 0:
if self.pcm_any():
f.write(self.pcm_read(ibuf))
_size -= ibuf
_star = time.ticks_ms()
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
raise OSError("Timeout write error")
self.pcm_en(False)
else:
print("Warning: Please upgrade the coprocessor firmware to use this feature")
"""Graph module"""
HEART =b'\x00\x0c\x1e?~\xfc~?\x1e\x0c\x00\x00'
HEART_SMALL =b'\x00\x00\x0c\x1e<x<\x1e\x0c\x00\x00\x00'