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

@@ -21,7 +21,7 @@
"framebuf"
],
"__file__": true,
"__size__": 13061,
"__size__": 14852,
"__name__": "mini_bot.py"
},
"mini_go": {
@@ -53,14 +53,14 @@
"gc",
"esp32",
"machine",
"ws2812x",
"musicx",
"ws2812x",
"sc7a20",
"ap3216c",
"mini_bot"
],
"__file__": true,
"__size__": 4611,
"__size__": 4920,
"__name__": "mixgo_mini.py"
},
"musicx": {
@@ -77,7 +77,7 @@
"machine"
],
"__file__": true,
"__size__": 1881,
"__size__": 1979,
"__name__": "ws2812x.py"
}
}

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'

View File

@@ -69,10 +69,6 @@ except Exception as e:
def onboard_temperature():
return mcu_temperature()
'''2RGB_WS2812'''
from ws2812x import NeoPixel
onboard_rgb = NeoPixel(Pin(9), 2)
'''1Buzzer-Music'''
from musicx import MIDI
onboard_music = MIDI(onboard_bot)
@@ -84,7 +80,7 @@ class KEYSensor:
self.adc = ADC(Pin(pin), atten=ADC.ATTN_0DB)
self.range = range
self.flag = True
def _value(self):
values = []
for _ in range(50):
@@ -92,7 +88,7 @@ class KEYSensor:
time.sleep_us(2)
return (self.range-200) < min(values) < (self.range+200)
def get_presses(self, delay = 1):
def get_presses(self, delay=1):
last_time,presses = time.time(), 0
while time.time() < last_time + delay:
time.sleep_ms(50)
@@ -112,7 +108,13 @@ class KEYSensor:
return False
def irq(self, handler, trigger):
Pin(self.pin, Pin.IN).irq(handler = handler, trigger = trigger)
self.handler = handler
self.trigger = trigger
Pin(self.pin, Pin.IN).irq(handler=handler, trigger=trigger)
def irq_en(self, enable):
if self.handler is not None and self.trigger is not None:
Pin(self.pin, Pin.IN).irq(handler=None if enable else self.handler, trigger=self.trigger)
'''1KEY_Button'''
class Button(KEYSensor):
@@ -120,6 +122,8 @@ class Button(KEYSensor):
self.pin = pin
self.key = Pin(pin, Pin.IN)
self.flag = True
self.handler = None
self.trigger = None
def _value(self):
return not self.key.value()
@@ -131,6 +135,10 @@ A2key = KEYSensor(0, 1500)
A3key = KEYSensor(0, 800)
A4key = KEYSensor(0, 2700)
'''2RGB_WS2812 #Public IO'''
from ws2812x import NeoPixel
onboard_rgb = NeoPixel(B1key.key, 2, func=B1key.irq_en)
'''2LED-Multiplex RGB'''
class LED:
def __init__(self, rgb, num=2, color=7):

View File

@@ -9,10 +9,11 @@ from time import sleep, sleep_us
from machine import bitstream
class NeoPixel:
def __init__(self, pin, n, bpp=3, timing=1, ORDER=(1, 0, 2, 3)):
def __init__(self, pin, n, bpp=3, timing=1, ORDER=(1, 0, 2, 3), func=None):
self.pin = pin
self.bpp = bpp
self.rgbs = n
self.func = func
self.ORDER = ORDER
self.rgb_buf = bytearray(self.rgbs * bpp)
self.timing = (((350, 850, 800, 400) if timing else (800, 1700, 1600, 900)) if isinstance(timing, int) else timing)
@@ -36,10 +37,12 @@ class NeoPixel:
j += self.bpp
def write(self):
if self.func: self.func(True)
self.pin.init(self.pin.OUT, value=0)
bitstream(self.pin, 0, self.timing, bytes(3) + self.rgb_buf)
sleep_us(150)
self.pin.init(self.pin.IN)
if self.func: self.func(False)
def color_chase(self,R, G, B, wait):
for i in range(self.rgbs):

View File

@@ -8,15 +8,19 @@
"type": "command",
"portSelect": "all",
"micropython:esp32c2:mixgo_mini": {
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud 115200 --after=no_reset_stub erase_flash && \"{esptool}\" --chip esp32c2 --port {com} --baud 460800 --after=no_reset_stub write_flash 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud 115200 --after=no_reset_stub erase_flash && \"{esptool}\" --chip esp32c2 --port {com} --baud 460800 --after=no_reset_stub write_flash 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
"special": [
{
"name": "Firmware No Ble With SSL",
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud 115200 --after=no_reset_stub erase_flash && \"{esptool}\" --chip esp32c2 --port {com} --baud 460800 --after=no_reset_stub write_flash 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud 115200 --after=no_reset_stub erase_flash && \"{esptool}\" --chip esp32c2 --port {com} --baud 460800 --after=no_reset_stub write_flash 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
},
{
"name": "Firmware With Ble No SSL",
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud 115200 --after=no_reset_stub erase_flash && \"{esptool}\" --chip esp32c2 --port {com} --baud 460800 --after=no_reset_stub write_flash 0x0 \"{indexPath}/build/Mixgo_Mini_lib_ble-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud 115200 --after=no_reset_stub erase_flash && \"{esptool}\" --chip esp32c2 --port {com} --baud 460800 --after=no_reset_stub write_flash 0x0 \"{indexPath}/build/Mixgo_Mini_lib_ble-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
},
{
"name": "Firmware With V2.0 Board",
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud 115200 --after=no_reset_stub erase_flash && \"{esptool}\" --chip esp32c2 --port {com} --baud 460800 --after=no_reset_stub write_flash 0x0 \"{indexPath}/build/Mixgo_Mini_lib_ble-V2-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
}
]
},
@@ -102,7 +106,7 @@
"binFile": [
{
"offset": "0x0000",
"path": "./build/Mixgo_Mini_lib-v1.23.0.bin"
"path": "./build/Mixgo_Mini_lib-v1.25.0.bin"
},
{
"offset": "0x3A0000",
@@ -115,7 +119,7 @@
"binFile": [
{
"offset": "0x0000",
"path": "./build/Mixgo_Mini_lib-v1.23.0.bin"
"path": "./build/Mixgo_Mini_lib-v1.25.0.bin"
},
{
"offset": "0x3A0000",
@@ -128,7 +132,20 @@
"binFile": [
{
"offset": "0x0000",
"path": "./build/Mixgo_Mini_lib_ble-v1.23.0.bin"
"path": "./build/Mixgo_Mini_lib_ble-v1.25.0.bin"
},
{
"offset": "0x3A0000",
"path": "../micropython/build/HZK12.bin"
}
]
},
{
"name": "Firmware With V2.0 Board",
"binFile": [
{
"offset": "0x0000",
"path": "./build/Mixgo_Mini_lib_ble-V2-v1.25.0.bin"
},
{
"offset": "0x3A0000",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long