From b1b24b27a62bd5308a757749291f3d684ad5564c Mon Sep 17 00:00:00 2001 From: dahanzimin <353767514@qq.com> Date: Thu, 23 Oct 2025 19:21:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=B6=E4=BB=96=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E6=92=AD=E6=94=BE=E9=9F=B3=E4=B9=90=EF=BC=8CC3?= =?UTF-8?q?=E6=94=AF=E6=8C=81v1.25.0=EF=BC=8C=E4=BF=AE=E6=94=B9sant?= =?UTF-8?q?=E7=9A=84es-dl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micropython/origin/build/lib/music.py | 66 ++-- .../micropython/origin/build/lib/uframebuf.py | 6 +- .../origin/build/lib/mixgo_cc.py | 79 ++--- .../origin/build/lib/mixgo_me.py | 84 ++---- .../origin/build/lib/mixgocar_c3.py | 9 +- .../origin/build/lib/ai_camera.py | 110 ------- .../origin/build/lib/camera.py | 80 ++--- .../origin/build/lib/esp_dl.py | 17 ++ .../origin/build/lib/mixgo_sant.py | 7 +- .../origin/build/lib/mixgo_zero.py | 283 ------------------ .../origin/build/lib/mixgo_zero_voice.py | 88 ------ .../origin/build/lib/musicx.py | 159 ---------- .../origin/build/lib/sant_bot.py | 2 +- .../origin/build/lib/sdcard.py | 231 -------------- .../origin/build/lib/st7789_cf.py | 98 ++++-- 15 files changed, 239 insertions(+), 1080 deletions(-) delete mode 100644 boards/default_src/micropython_esp32s3/origin/build/lib/ai_camera.py create mode 100644 boards/default_src/micropython_esp32s3/origin/build/lib/esp_dl.py delete mode 100644 boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero.py delete mode 100644 boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero_voice.py delete mode 100644 boards/default_src/micropython_esp32s3/origin/build/lib/musicx.py delete mode 100644 boards/default_src/micropython_esp32s3/origin/build/lib/sdcard.py diff --git a/boards/default_src/micropython/origin/build/lib/music.py b/boards/default_src/micropython/origin/build/lib/music.py index 97281d12..7528ad36 100644 --- a/boards/default_src/micropython/origin/build/lib/music.py +++ b/boards/default_src/micropython/origin/build/lib/music.py @@ -3,14 +3,9 @@ Music buzzer Micropython library for the Music buzzer ======================================================= - -#Based on Author: qiren123(MIDI Music) 20220618 -#Make changes to instantiation 20220622 -#Increase level reversal selection 20220716 - -dahanzimin From the Mixly Team +@dahanzimin From the Mixly Team """ - +import _thread, gc from time import sleep_ms from machine import Pin, PWM @@ -30,13 +25,15 @@ Letter = 'ABCDEFG#R' class MIDI(): def __init__(self, pin, volume=100, invert=0, pa_ctrl=None): self.reset() - self._invert=invert + self._invert = invert self._pin = pin self._volume = volume + self._play = False + self._over = True self._pwm = None self._pa_ctrl = pa_ctrl - def set_volume(self,volume): + def set_volume(self, volume): if not 0 <= volume <= 100: raise ValueError("Volume value is in the range: 0-100") self._volume=volume @@ -97,45 +94,60 @@ class MIDI(): self.set_duration(int(tone[(pos + 1):])) tone = tone[:pos] - def play(self, tune, duration=None): - if self._pa_ctrl: self._pa_ctrl(1) + def play(self, tune, duration=None, pa_delay=100): + if self._pa_ctrl: self._pa_ctrl(1, pa_delay) self._pwm = PWM(Pin(self._pin), duty=1023 if self._invert else 0) + self._play = True + self._over = False if duration is None: self.set_default(tune[0]) else: self.set_duration(duration) for tone in tune: tone = tone.upper() + if not self._play: + break if tone[0] not in Letter: continue midi = self.midi(tone) - self._pwm.duty(1023-self._volume) if self._invert else self._pwm.duty(self._volume) - self._pwm.freq(midi[0]) + if self._play: self._pwm.duty((1023-self._volume) if self._invert else self._volume) + if self._play: self._pwm.freq(midi[0]) sleep_ms(midi[1]) - self._pwm.freq(400000) + if self._play: self._pwm.freq(400000) sleep_ms(1) - if self._pa_ctrl: self._pa_ctrl(0) + if self._pa_ctrl: self._pa_ctrl(0, 0) self._pwm.deinit() sleep_ms(10) + self._over = True - def pitch(self, freq): - if self._pa_ctrl: self._pa_ctrl(1) - self._pwm = PWM(Pin(self._pin)) - self._pwm.duty(1023-self._volume) if self._invert else self._pwm.duty(self._volume) - self._pwm.freq(int(freq)) + def play_thread(self, tune, duration=None, pa_delay=100): + self._play = False + while not self._over: + sleep_ms(10) + if not self._play: + gc.collect() + _thread.start_new_thread(self.play, (tune, duration, pa_delay)) + sleep_ms(100) - def pitch_time(self, freq, delay): - if self._pa_ctrl: self._pa_ctrl(1) + def pitch(self, freq, pa_delay=100): + if self._pa_ctrl: self._pa_ctrl(1, pa_delay) self._pwm = PWM(Pin(self._pin)) - self._pwm.duty(1023-self._volume) if self._invert else self._pwm.duty(self._volume) - self._pwm.freq(int(freq)) + self._pwm.duty((1023-self._volume) if self._invert else self._volume) + self._pwm.freq(int(freq)) + + def pitch_time(self, freq, delay, pa_delay=100): + if self._pa_ctrl: self._pa_ctrl(1, pa_delay) + self._pwm = PWM(Pin(self._pin)) + self._pwm.duty((1023-self._volume) if self._invert else self._volume) + self._pwm.freq(int(freq)) sleep_ms(delay) - if self._pa_ctrl: self._pa_ctrl(0) + if self._pa_ctrl: self._pa_ctrl(0, 0) self._pwm.deinit() sleep_ms(10) - + def stop(self): - if self._pa_ctrl: self._pa_ctrl(0) + self._play = False + if self._pa_ctrl: self._pa_ctrl(0, 0) if self._pwm: self._pwm.deinit() sleep_ms(10) diff --git a/boards/default_src/micropython/origin/build/lib/uframebuf.py b/boards/default_src/micropython/origin/build/lib/uframebuf.py index c3c14e87..2dfa073e 100644 --- a/boards/default_src/micropython/origin/build/lib/uframebuf.py +++ b/boards/default_src/micropython/origin/build/lib/uframebuf.py @@ -553,15 +553,17 @@ class FrameBuffer_Uincode(FrameBuffer_Base): self.show() time.sleep_ms(speed) - def qrcode(self, data, x=0, y=0, size=None, bold=0, type=None, correct=0, color=0xffff, bg_color=0x0, sync=True): + def qrcode(self, data, x=None, y=None, size=None, bold=0, type=None, correct=0, color=0xffff, bg_color=0x0, sync=True): if self._miniqr is None: from adafruit_miniqr import QRCode self._miniqr = QRCode _qr = self._miniqr(qr_type=type, error_correct=correct) - _qr.add_data(data) + _qr.add_data(str(data)) _qr.make() if sync: self.fill(bg_color, sync=False) size = min(self.height // _qr.matrix.height, self.width // _qr.matrix.width) if size is None else size + x = (self.width - _qr.matrix.width * size) // 2 if x is None else x + y = (self.height - _qr.matrix.height * size) // 2 if y is None else y for j in range(_qr.matrix.height): for i in range(_qr.matrix.width): if _qr.matrix[i, j]: diff --git a/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_cc.py b/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_cc.py index ffc4ace1..62f22b2c 100644 --- a/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_cc.py +++ b/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_cc.py @@ -1,15 +1,12 @@ """ -MixGo CC -Onboard resources +MixGo CC Onboard resources -MicroPython library for the MixGo CC -Onboard resources +MicroPython library for the MixGo CC Onboard resources ======================================================= - -#Preliminary composition 20221010 - -dahanzimin From the Mixly Team +@dahanzimin From the Mixly Team """ import time, gc -from machine import Pin, SoftI2C, ADC, PWM, RTC +from machine import * '''i2c-onboard''' onboard_i2c=SoftI2C(scl = Pin(7), sda = Pin(6), freq = 400000) @@ -95,7 +92,7 @@ onboard_rgb = NeoPixel(Pin(8), 4, ORDER=(0, 1, 2, 3)) '''1Buzzer-Music''' from music import MIDI -onboard_music =MIDI(10) +onboard_music = MIDI(10) '''MIC_Sensor''' class MICSensor: @@ -105,10 +102,10 @@ class MICSensor: def read(self): maxloudness = 0 for i in range(5): - loudness = self.sample() + loudness = self.sample() if loudness > maxloudness: maxloudness = loudness - return maxloudness + return maxloudness def sample(self): values = [] @@ -119,21 +116,24 @@ class MICSensor: onboard_sound = MICSensor(pin=4 if version else 3) -'''4,5KEY_Sensor''' +'''5KEY_Sensor''' class KEYSensor: def __init__(self, pin, range): - self.adc = ADC(Pin(pin), atten=ADC.ATTN_11DB) self.pin = pin + self.adc = ADC(Pin(pin), atten=ADC.ATTN_11DB) self.range = range self.flag = True - + def _value(self): values = [] - for _ in range(50): - values.append(self.adc.read()) - time.sleep_us(2) - return (self.range - 300) < min(sorted(values)[25:]) < (self.range + 300) - + for _ in range(25): + try: + values.append(self.adc.read()) + except: #IDF>5.2.2存在ADC2问题 + pass + time.sleep_us(5) + return (self.range-200) < min(values) < (self.range+200) + def get_presses(self, delay = 1): last_time,presses = time.time(), 0 while time.time() < last_time + delay: @@ -148,7 +148,7 @@ class KEYSensor: def was_pressed(self): if(self._value() != self.flag): self.flag = self._value() - if self.flag : + if self.flag: return True else: return False @@ -156,34 +156,15 @@ class KEYSensor: def irq(self, handler, trigger): Pin(self.pin, Pin.IN).irq(handler = handler, trigger = trigger) -'''2,1KEY_Button''' -class Button: +'''1KEY_Button''' +class Button(KEYSensor): def __init__(self, pin): - self.pin = Pin(pin, Pin.IN) + self.pin = pin + self.key = Pin(pin, Pin.IN) self.flag = True - def get_presses(self, delay = 1): - last_time,presses = time.time(), 0 - while time.time() < last_time + delay: - time.sleep(0.05) - if self.was_pressed(): - presses += 1 - return presses - - def is_pressed(self): - return not self.pin.value() - - def was_pressed(self, flag = 0): - if(self.pin.value() != self.flag): - self.flag = self.pin.value() - time.sleep(0.02) - if self.flag: - return False - else: - return True - - def irq(self, handler, trigger): - self.pin.irq(handler = handler, trigger = trigger) + def _value(self): + return not self.key.value() if version==0: B1key = Button(9) @@ -191,7 +172,7 @@ if version==0: A1key = KEYSensor(2,20) A2key = KEYSensor(2,1170) A3key = KEYSensor(2,2400) - A4key = KEYSensor(2,3610) + A4key = KEYSensor(2,3610) else: B1key = Button(9) @@ -201,7 +182,7 @@ else: A3key = KEYSensor(5,2500) A4key = KEYSensor(5,3500) -'''2-LED''' #Modify indexing method +'''2-LED''' #Modify indexing method class LED: def __init__(self, pins=[]): self._pins = pins @@ -231,11 +212,11 @@ class LED: print("Warning: Old version, without this function") else: if val == -1: - self.setbrightness(index, 100) if self.getbrightness(index) < 50 else self.setbrightness(index, 0) + self.setbrightness(index, 100) if self.getbrightness(index) < 50 else self.setbrightness(index, 0) elif val == 1: - self.setbrightness(index, 100) + self.setbrightness(index, 100) elif val == 0: - self.setbrightness(index, 0) + self.setbrightness(index, 0) def getonoff(self, index): if len(self._pins) == 0: diff --git a/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_me.py b/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_me.py index 5c30fc5c..2a515067 100644 --- a/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_me.py +++ b/boards/default_src/micropython_esp32c3/origin/build/lib/mixgo_me.py @@ -1,16 +1,12 @@ """ -MixGo ME -Onboard resources +MixGo ME Onboard resources -MicroPython library for the MixGo ME -Onboard resources +MicroPython library for the MixGo ME Onboard resources ======================================================= - -#Preliminary composition 20221010 - -dahanzimin From the Mixly Team +@dahanzimin From the Mixly Team """ - import time, gc -from machine import Pin, SoftI2C, ADC, PWM, RTC +from machine import * '''i2c-onboard''' onboard_i2c=SoftI2C(scl = Pin(7), sda = Pin(6), freq = 400000) @@ -52,7 +48,7 @@ onboard_rgb = NeoPixel(Pin(9), 2, ORDER=(0, 1, 2, 3), multiplex=1) '''1Buzzer-Music''' from music import MIDI -onboard_music =MIDI(10) +onboard_music = MIDI(10) '''MIC_Sensor''' class MICSensor: @@ -62,7 +58,7 @@ class MICSensor: def read(self): maxloudness = 0 for i in range(5): - loudness = self.sample() + loudness = self.sample() if loudness > maxloudness: maxloudness = loudness return maxloudness @@ -78,18 +74,22 @@ onboard_sound = MICSensor() '''5KEY_Sensor''' class KEYSensor: - def __init__(self,range): - self.adc=ADC(Pin(5), atten=ADC.ATTN_11DB) - self.range=range + def __init__(self, pin, range): + self.pin = pin + self.adc = ADC(Pin(pin), atten=ADC.ATTN_11DB) + self.range = range self.flag = True - + def _value(self): values = [] - for _ in range(50): - values.append(self.adc.read()) - time.sleep_us(2) - return (self.range - 300) < min(sorted(values)[25:]) < (self.range + 300) - + for _ in range(25): + try: + values.append(self.adc.read()) + except: #IDF>5.2.2存在ADC2问题 + pass + time.sleep_us(5) + return (self.range-200) < min(values) < (self.range+200) + def get_presses(self, delay = 1): last_time,presses = time.time(), 0 while time.time() < last_time + delay: @@ -97,57 +97,37 @@ class KEYSensor: if self.was_pressed(): presses += 1 return presses - + def is_pressed(self): return self._value() def was_pressed(self): if(self._value() != self.flag): self.flag = self._value() - if self.flag : + if self.flag: return True else: return False def irq(self, handler, trigger): - Pin(5, Pin.IN).irq(handler = handler, trigger = trigger) - -B2key = KEYSensor(20) -A1key = KEYSensor(800) -A2key = KEYSensor(1600) -A3key = KEYSensor(2500) -A4key = KEYSensor(3500) + Pin(self.pin, Pin.IN).irq(handler = handler, trigger = trigger) '''1KEY_Button''' -class Button: +class Button(KEYSensor): def __init__(self, pin): - self.pin = Pin(pin, Pin.IN) + self.pin = pin + self.key = Pin(pin, Pin.IN) self.flag = True - - def get_presses(self, delay = 1): - last_time,presses = time.time(), 0 - while time.time() < last_time + delay: - time.sleep(0.05) - if self.was_pressed(): - presses += 1 - return presses - def is_pressed(self): - return not self.pin.value() + def _value(self): + return not self.key.value() - def was_pressed(self, flag = 0): - if(self.pin.value() != self.flag): - self.flag = self.pin.value() - time.sleep(0.02) - if self.flag: - return False - else: - return True - - def irq(self, handler, trigger): - self.pin.irq(handler = handler, trigger = trigger) - B1key = Button(9) +B2key = KEYSensor(5,20) +A1key = KEYSensor(5,800) +A2key = KEYSensor(5,1600) +A3key = KEYSensor(5,2500) +A4key = KEYSensor(5,3500) '''2LED-Multiplex RGB''' class LED: diff --git a/boards/default_src/micropython_esp32c3/origin/build/lib/mixgocar_c3.py b/boards/default_src/micropython_esp32c3/origin/build/lib/mixgocar_c3.py index 8975a2c0..b221e09e 100644 --- a/boards/default_src/micropython_esp32c3/origin/build/lib/mixgocar_c3.py +++ b/boards/default_src/micropython_esp32c3/origin/build/lib/mixgocar_c3.py @@ -3,13 +3,10 @@ MixGo CAR -Onboard resources MicroPython library for the MixGo CAR (ESP32C3) ======================================================= - -#Preliminary composition 20220804 - -dahanzimin From the Mixly Team +@dahanzimin From the Mixly Team """ import time,gc,ms32006 -from machine import Pin,SoftI2C,ADC,RTC +from machine import * '''RTC''' rtc_clock=RTC() @@ -17,7 +14,7 @@ rtc_clock=RTC() '''i2c-onboard''' onboard_i2c=SoftI2C(scl = Pin(7), sda = Pin(6), freq = 400000) -'''4RGB_WS2812''' #color_chase(),rainbow_cycle()方法移至类里 +'''4RGB_WS2812''' from ws2812 import NeoPixel onboard_rgb = NeoPixel(Pin(8), 4, ORDER=(0, 1, 2, 3)) diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/ai_camera.py b/boards/default_src/micropython_esp32s3/origin/build/lib/ai_camera.py deleted file mode 100644 index fbd5b89f..00000000 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/ai_camera.py +++ /dev/null @@ -1,110 +0,0 @@ -""" -AI-Camera (Inherit C module) - -MicroPython library for the AI-Camera(Inherit C module) -======================================================= -@dahanzimin From the Mixly Team -""" - -import esp_ai -from micropython import const - -CODE_DETECTION = const(0) -COLOR_DETECTION = const(1) -MOTION_DEECTION = const(2) -CAT_FACE_DETECTION = const(3) -FACE_DETECTION = const(4) -FACE_RECOGNITION = const(5) - -class AI: - def __init__(self, function): - self._func = function - self._ai = None - self._once = True - - def _init(self, *args): - if self._func == CODE_DETECTION: - self._ai = esp_ai.code_recognition() - elif self._func == COLOR_DETECTION: - self._ai = esp_ai.color_detection(color=args[0]) - elif self._func == MOTION_DEECTION: - self._ai = esp_ai.motion_recognition(threshold=args[0]) - elif self._func == CAT_FACE_DETECTION: - self._ai = esp_ai.cat_detection() - elif self._func == FACE_DETECTION: - self._ai = esp_ai.face_detection() - elif self._func == FACE_RECOGNITION: - self._ai = esp_ai.face_recognition() - else: - raise AttributeError('AI model is not supported') - self._ai.start() #启动检测,可以通过LCD观察结果 - self._once = False - - def _result(self, res, _t, _s=0, _n=0): #_s:第几个, _n:细分第几个 - if not res: return None - if _t == 'len': - return res[0] - elif _t == 'pos': - if len(res) >= (5 + _s * 4): - return res[(1 + _s * 4):(5 + _s * 4)] - elif _t == 'keypoint': - if len(res) >= (7 + _s * 14 + _n * 2): - return res[(5 + _s * 14 + _n * 2):(7 + _s * 14 + _n * 2)] - - def code_recognition(self): - if self._func == CODE_DETECTION: - if self._once: self._init() - return self._ai.read() - else: - raise AttributeError('This model can only run QR code detection') - - def color_detection(self, color=0, event='pos', num=0): - if self._func == COLOR_DETECTION: - if self._once: self._init(color) - return self._result(self._ai.read(), event, num) - else: - raise AttributeError('This model can only run color detection') - - def motion_recognition(self, threshold=50): - if self._func == MOTION_DEECTION: - if self._once: self._init(threshold) - return bool(self._ai.read() >= threshold) - else: - raise AttributeError('This model can only run motion recognition') - - def cat_detection(self, event='pos', num=0): - if self._func == CAT_FACE_DETECTION: - if self._once: self._init() - return self._result(self._ai.read(), event, num) - else: - raise AttributeError('This model can only run cat face detection') - - def face_detection(self, event='pos', num=0, point=0): - if self._func == FACE_DETECTION: - if self._once: self._init() - return self._result(self._ai.read(), event, num, point) - else: - raise AttributeError('This model can only run face detection') - - def face_recognition(self, event='pos', num=0, point=0): - if self._func == FACE_RECOGNITION: - if self._once: self._init() - return self._result(self._ai.recognize(), event, num, point) - else: - raise AttributeError('This model can only run face recognition') - - def face_enroll(self): - if self._func == FACE_RECOGNITION: - return self._ai.enroll() - else: - raise AttributeError('This model can only run face recognition') - - def face_delete(self, _id): - if self._func == FACE_RECOGNITION: - self._ai.delete(_id) - else: - raise AttributeError('This model can only run face recognition') - - def stop(self): - if self._ai is not None: - self._ai.stop() diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/camera.py b/boards/default_src/micropython_esp32s3/origin/build/lib/camera.py index 8f690523..c4d8f693 100644 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/camera.py +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/camera.py @@ -1,69 +1,45 @@ """ -Camera GC032A/FrameBuffer(Inherit C module) +Camera -MicroPython library for the GC032A(Inherit C module) +MicroPython library for the Camera(Inherit C module) ======================================================= @dahanzimin From the Mixly Team """ import time -import base64 -from sensor import * +import base64, jpeg +from _camera import * +from jpeg import Encoder from machine import SoftI2C, Pin from mixgo_sant import onboard_bot -from esp_usb import CAM -class GC032A(Camera): - def __init__(self, framesize=LCD, hmirror=None, frame=1): - onboard_bot.cam_en(1, 500) - super().__init__(frame) - super().set_framesize(framesize) - time.sleep_ms(100) - if hmirror is not None: - super().set_hmirror(hmirror) - time.sleep_ms(100) - SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000) - SoftI2C(scl=Pin(47), sda=Pin(38), freq=400000) +class Camera(Camera): + def __init__(self, frame_size=FrameSize.R240X240, pixel_format=PixelFormat.RGB565, hmirror=False, vflip=False, **kwargs): + onboard_bot.cam_en(1, 150) + super().__init__(frame_size=frame_size, pixel_format=pixel_format, **kwargs) + self.set_hmirror(not hmirror) + time.sleep_ms(50) + self.set_vflip(not vflip) + time.sleep_ms(50) + SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000) #恢复I2C def deinit(self): super().deinit() onboard_bot.cam_en(0, 100) - def display(self, show=True): - if show: - super().display() + def snapshot(self, path=None, formats=0, quality=90, rotation=0): + if formats == 0 and path is None: + return self.capture() else: - super().display_stop() - - def snapshot(self, path=None, formats=0, quality=50): - if path is None: - _data = super().snapshot(formats=formats, quality=quality) - if formats >= 2: - return b'data:image/jpg;base64,' + base64.b64encode(_data) + _encoder = Encoder(pixel_format="RGB565_BE", quality=quality, rotation=rotation, width=self.get_pixel_width(), height=self.get_pixel_height()) + _jpeg = _encoder.encode(self.capture()) + del _encoder + if path is None: + if formats == 1: + return _jpeg + else: + return b'data:image/jpg;base64,' + base64.b64encode(_jpeg) else: - return _data - else: - return super().snapshot(path, quality=50) - -class UVC(CAM): - def __init__(self, framesize=QVGA): - super().__init__(framesize) - - def deinit(self): - super().deinit() - - def display(self, show=True): - if show: - super().display() - else: - super().display_stop() - - def snapshot(self, path=None, formats=0, quality=50): - if path is None: - _data = super().snapshot(formats=formats, quality=quality) - if formats >= 2: - return b'data:image/jpg;base64,' + base64.b64encode(_data) - else: - return _data - else: - return super().snapshot(path, quality=50) + with open(path, 'wb') as f: + f.write(_jpeg) + return True diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/esp_dl.py b/boards/default_src/micropython_esp32s3/origin/build/lib/esp_dl.py new file mode 100644 index 00000000..b071e74f --- /dev/null +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/esp_dl.py @@ -0,0 +1,17 @@ +""" +ESP-DL + +MicroPython library for the ESP-DL(Inherit C module) +======================================================= +@dahanzimin From the Mixly Team +""" +from espdl import * + +def analyze(results, keys=None, num=0): + if keys is None: + return results is not None + if results: + if keys == "len": + return len(results) + else: + return results[num][keys] diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_sant.py b/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_sant.py index cf1c7bad..f6b91e46 100644 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_sant.py +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_sant.py @@ -17,6 +17,9 @@ rtc_clock = RTC() inboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000) onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(38), freq=400000) +'''SPI-onboard''' +onboard_spi = SPI(1, baudrate=80000000, polarity=1, phase=1) + '''BOT035-Sensor''' try : import sant_bot @@ -25,7 +28,7 @@ except Exception as e: print("Warning: Failed to communicate with BOT035 (Coprocessor) or",e) '''TFT/240*240''' -onboard_tft = st7789_cf.ST7789(reset=onboard_bot.tft_reset, backlight=onboard_bot.tft_brightness, font_address=0xE00000) +onboard_tft = st7789_cf.ST7789(onboard_spi, 240, 240, dc_pin=45 ,reset=onboard_bot.tft_reset, backlight=onboard_bot.tft_brightness, font_address=0xF00000) '''ACC-Sensor''' try : @@ -73,7 +76,7 @@ from ws2812x import NeoPixel onboard_rgb = NeoPixel(onboard_bot.rgb_sync, 4) '''1Buzzer-Music''' -from musicx import MIDI +from music import MIDI onboard_music = MIDI(46, pa_ctrl=onboard_bot.spk_en) '''5KEY_Sensor''' diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero.py b/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero.py deleted file mode 100644 index c74c15ae..00000000 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero.py +++ /dev/null @@ -1,283 +0,0 @@ -""" -mixgo_zero Onboard resources - -Micropython library for the mixgo_zero Onboard resources -======================================================= - -#Preliminary composition 20240110 -#S3定时器ID(-1,0,1,2,3) - -@dahanzimin From the Mixly Team -""" -from machine import * -import time, gc, st7789_bf, math - -'''RTC''' -rtc_clock = RTC() - -'''I2C-onboard''' -#onboard_i2c = I2C(0) -onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000) -onboard_i2c_1 = SoftI2C(scl=Pin(47), sda=Pin(21), freq=400000) - -'''SPI-onboard''' -try: - import _boot - onboard_spi = _boot.onboard_spi - onboard_spi.init(baudrate=50000000) -except: - onboard_spi = SPI(1, baudrate=50000000, polarity=0, phase=0) - -'''TFT/320*240''' -onboard_tft = st7789_bf.ST7789(onboard_spi, 320, 240, dc_pin=18, cs_pin=45, bl_pin=46, font_address=0xE00000) - -'''ACC-Sensor''' -try : - import mxc6655xa - onboard_acc = mxc6655xa.MXC6655XA(onboard_i2c, front=True) -except Exception as e: - print("Warning: Failed to communicate with MXC6655XA (ACC) or",e) - -'''ALS_PS-Sensor *2''' -try : - import ltr553als - onboard_als_l = ltr553als.LTR_553ALS(onboard_i2c) -except Exception as e: - print("Warning: Failed to communicate with TR_553ALS (ALS&PS) or",e) - -try : - import ltr553als - onboard_als_r = ltr553als.LTR_553ALS(onboard_i2c_1) -except Exception as e: - print("Warning: Failed to communicate with TR_553ALS (ALS&PS) or",e) - -'''THS-Sensor''' -try : - import shtc3 - onboard_ths = shtc3.SHTC3(onboard_i2c) -except Exception as e: - print("Warning: Failed to communicate with GXHTC3 (THS) or",e) - -'''RFID-Sensor''' -try : - import rc522 - onboard_rfid = rc522.RC522(onboard_i2c) -except Exception as e: - print("Warning: Failed to communicate with RC522 (RFID) or",e) - -'''MGS-Sensor''' -try : - import mmc5603 - onboard_mgs = mmc5603.MMC5603(onboard_i2c) -except Exception as e: - print("Warning: Failed to communicate with MMC5603 (MGS) or",e) - -'''BPS-Sensor''' -try : - import spl06_001 - onboard_bps = spl06_001.SPL06(onboard_i2c) -except Exception as e: - print("Warning: Failed to communicate with SPL06-001 (BPS) or",e) - -'''2RGB_WS2812''' -from ws2812 import NeoPixel -onboard_rgb = NeoPixel(Pin(0), 6, multiplex=True, leds=2) - -'''5KEY_Sensor''' -class KEYSensor: - def __init__(self, pin, range): - self.pin = pin - self.adc = ADC(Pin(pin), atten=ADC.ATTN_0DB) - self.range = range - self.flag = True - - def _value(self): - values = [] - for _ in range(50): - values.append(self.adc.read()) - time.sleep_us(2) - return (self.range-200) < min(values) < (self.range+200) - - def get_presses(self, delay = 1): - last_time,presses = time.time(), 0 - while time.time() < last_time + delay: - time.sleep_ms(50) - if self.was_pressed(): - presses += 1 - return presses - - def is_pressed(self): - return self._value() - - def was_pressed(self): - if(self._value() != self.flag): - self.flag = self._value() - if self.flag : - return True - else: - return False - - def irq(self, handler, trigger): - Pin(self.pin, Pin.IN).irq(handler = handler, trigger = trigger) - -'''1KEY_Button''' -class Button(KEYSensor): - def __init__(self, pin): - self.pin = pin - self.key = Pin(pin, Pin.IN) - self.flag = True - - def _value(self): - return not self.key.value() - -B1key = Button(0) -B2key = KEYSensor(13,0) -A1key = KEYSensor(13,2900) -A2key = KEYSensor(13,2300) -A3key = KEYSensor(13,1650) -A4key = KEYSensor(13,850) - -'''2-TouchPad''' -class Touch_Pad: - __species = {} - __first_init = True - def __new__(cls, pin, *args, **kwargs): - if pin not in cls.__species.keys(): - cls.__first_init = True - cls.__species[pin]=object.__new__(cls) - return cls.__species[pin] - - def __init__(self, pin, default=30000): - if self.__first_init: - self.__first_init = False - from machine import TouchPad - self._pin = TouchPad(Pin(pin)) - self.raw = self._pin.read() - if self.raw >= default * 1.5: - self.raw = default - - def touch(self,value=None ): - return self._pin.read() > value if value else self._pin.read() - -#Touch with function call -def touched(pin,value=60000): - return Touch_Pad(pin).touch(value) - -def touch_slide(pina, pinb): - return ((Touch_Pad(pina).touch() - Touch_Pad(pina).raw) - (Touch_Pad(pinb).touch() - Touch_Pad(pinb).raw)) // 10 - -'''2LED-WS2812''' -class LED: - def __init__(self, rgb, num=2, color=3): - self._rgb = rgb - self._col = [color] * num - self._color = ((0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (0, 1, 1), (1, 0, 1), (1, 1, 1)) - - def setbrightness(self, index, value): - self._rgb.led_set(index - 1, (value if self._color[self._col[index-1]][0] else 0, - value if self._color[self._col[index-1]][1] else 0, - value if self._color[self._col[index-1]][2] else 0)) - self._rgb.write() - - def getbrightness(self, index): - color = self._rgb.led_get(index - 1) - return color[0] | color[1] | color[2] - - def setonoff(self, index, value): - if value == -1: - if self.getbrightness(index) < 50: - self.setbrightness(index, 100) - else: - self.setbrightness(index, 0) - elif value == 1: - self.setbrightness(index, 100) - elif value == 0: - self.setbrightness(index, 0) - - def getonoff(self, index): - return True if self.getbrightness(index) > 50 else False - - def setcolor(self, index, color): - self._col[index-1] = color - - def getcolor(self, index): - return self._col[index-1] - -onboard_led = LED(onboard_rgb) - -class Clock: - def __init__(self, x, y, radius, color, oled=onboard_tft): #定义时钟中心点和半径 - self.display = oled - self.xc = x - self.yc = y - self.r = radius - self.color= color - self.hour = 0 - self.min = 0 - self.sec = 0 - - def set_time(self, h, m, s): #设定时间 - self.hour = h - self.min = m - self.sec = s - - def set_rtctime(self): #设定时间 - t = rtc_clock.datetime() - self.hour = t[4] - self.min = t[5] - self.sec = t[6] - - def drawDial(self,color): #画钟表刻度 - r_tic1 = self.r - 1 - r_tic2 = self.r - 2 - - self.display.ellipse(self.xc, self.yc, self.r,self.r, self.color) - self.display.ellipse(self.xc, self.yc, 2, 2, self.color,True) - - for h in range(12): - at = math.pi * 2.0 * h / 12.0 - x1 = round(self.xc + r_tic1 * math.sin(at)) - x2 = round(self.xc + r_tic2 * math.sin(at)) - y1 = round(self.yc - r_tic1 * math.cos(at)) - y2 = round(self.yc - r_tic2 * math.cos(at)) - self.display.line(x1, y1, x2, y2, color) - - def drawHour(self,color): #画时针 - - r_hour = int(self.r / 10.0 * 5) - ah = math.pi * 2.0 * ((self.hour % 12) + self.min / 60.0) / 12.0 - xh = int(self.xc + r_hour * math.sin(ah)) - yh = int(self.yc - r_hour * math.cos(ah)) - self.display.line(self.xc, self.yc, xh, yh, color) - - def drawMin(self,color): #画分针 - - r_min = int(self.r / 10.0 * 7) - am = math.pi * 2.0 * self.min / 60.0 - - xm = round(self.xc + r_min * math.sin(am)) - ym = round(self.yc - r_min * math.cos(am)) - self.display.line(self.xc, self.yc, xm, ym, color) - - def drawSec(self,color): #画秒针 - - r_sec = int(self.r / 10.0 * 9) - asec = math.pi * 2.0 * self.sec / 60.0 - xs = round(self.xc + r_sec * math.sin(asec)) - ys = round(self.yc - r_sec * math.cos(asec)) - self.display.line(self.xc, self.yc, xs, ys, color) - - def draw_clock(self): #画完整钟表 - self.drawDial(self.color) - self.drawHour(self.color) - self.drawMin(self.color) - self.drawSec(self.color) - self.display.show() - - def clear(self,color=0): #清除 - self.drawHour(color) - self.drawMin(color) - self.drawSec(color) - -'''Reclaim memory''' -gc.collect() diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero_voice.py b/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero_voice.py deleted file mode 100644 index 582fccd1..00000000 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_zero_voice.py +++ /dev/null @@ -1,88 +0,0 @@ -""" -mixgo_zero Zi Voice Onboard resources - -Micropython library for the mixgo_zero Zi Onboard resources -======================================================= - -#Preliminary composition 20230818 - -dahanzimin From the Mixly Team -""" -import ustruct -import time -import music_spk -import es8374 -from machine import Pin, I2S -from mixgo_zero import onboard_i2c - -sample_rate = 22050 -ob_code = es8374.ES8374(onboard_i2c) -time.sleep(0.2) - -#ps 特殊改双全工i2s支持 -ob_audio = I2S(0, sck=Pin(39), ws=Pin(41), dout=Pin(42), din=Pin(40), mck=Pin(38), mode=I2S.RTX, bits=16, format=I2S.MONO, rate=sample_rate, ibuf=20000) - -spk_midi = music_spk.MIDI(ob_audio, sample_rate) - -def u2s(n): - return n if n < (1 << 15) else n - (1 << 16) - -def sound_level(): - buf = bytearray(100) - values = [] - ob_audio.readinto(buf) - for i in range(len(buf)//2): - values.append(u2s(buf[i * 2] | buf[i * 2 + 1]<<8)) - return max(values) - min(values) - -def play_audio(path): - file = open(path, 'rb') - header = file.read(44) - if header[8:12] != b'WAVE': - raise Error('not a WAVE file') - _rate = ustruct.unpack('> 6 - c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7 - read_bl_len = csd[5] & 0b1111 - capacity = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len) - self.sectors = capacity // 512 - else: - raise OSError("SD card CSD format not supported") - # CMD16: set block length to 512 bytes - if self.cmd(16, 512, 0) != 0: - raise OSError("can't set 512 block size") - # set to high data rate now that it's initialised - self.init_spi(baudrate) - - def init_card_v1(self): - for i in range(_CMD_TIMEOUT): - time.sleep_ms(50) - self.cmd(55, 0, 0) - if self.cmd(41, 0, 0) == 0: - # SDSC card, uses byte addressing in read/write/erase commands - self.cdv = 512 - # print("[SDCard] v1 card") - return - raise OSError("timeout waiting for v1 card") - - def init_card_v2(self): - for i in range(_CMD_TIMEOUT): - time.sleep_ms(50) - self.cmd(58, 0, 0, 4) - self.cmd(55, 0, 0) - if self.cmd(41, 0x40000000, 0) == 0: - self.cmd(58, 0, 0, -4) # 4-byte response, negative means keep the first byte - ocr = self.tokenbuf[0] # get first byte of response, which is OCR - if not ocr & 0x40: - # SDSC card, uses byte addressing in read/write/erase commands - self.cdv = 512 - else: - # SDHC/SDXC card, uses block addressing in read/write/erase commands - self.cdv = 1 - # print("[SDCard] v2 card") - return - raise OSError("timeout waiting for v2 card") - - def cmd(self, cmd, arg, crc, final=0, release=True, skip1=False): - self.cs(0) - - # create and send the command - buf = self.cmdbuf - buf[0] = 0x40 | cmd - buf[1] = arg >> 24 - buf[2] = arg >> 16 - buf[3] = arg >> 8 - buf[4] = arg - buf[5] = crc - self.spi.write(buf) - - if skip1: - self.spi.readinto(self.tokenbuf, 0xFF) - # wait for the response (response[7] == 0) - for i in range(_CMD_TIMEOUT): - self.spi.readinto(self.tokenbuf, 0xFF) - response = self.tokenbuf[0] - if not (response & 0x80): - if final < 0: - self.spi.readinto(self.tokenbuf, 0xFF) - final = -1 - final - for j in range(final): - self.spi.write(b"\xff") - if release: - self.cs(1) - self.spi.write(b"\xff") - return response - self.cs(1) - self.spi.write(b"\xff") - return -1 - - def readinto(self, buf): - self.cs(0) - for i in range(_CMD_TIMEOUT): - self.spi.readinto(self.tokenbuf, 0xFF) - if self.tokenbuf[0] == _TOKEN_DATA: - break - time.sleep_ms(1) - else: - self.cs(1) - raise OSError("timeout waiting for response") - mv = self.dummybuf_memoryview - if len(buf) != len(mv): - mv = mv[: len(buf)] - self.spi.write_readinto(mv, buf) - self.spi.write(b"\xff") - self.spi.write(b"\xff") - self.cs(1) - self.spi.write(b"\xff") - - def write(self, token, buf): - self.cs(0) - self.spi.read(1, token) - self.spi.write(buf) - self.spi.write(b"\xff") - self.spi.write(b"\xff") - if (self.spi.read(1, 0xFF)[0] & 0x1F) != 0x05: - self.cs(1) - self.spi.write(b"\xff") - return - while self.spi.read(1, 0xFF)[0] == 0: - pass - self.cs(1) - self.spi.write(b"\xff") - - def write_token(self, token): - self.cs(0) - self.spi.read(1, token) - self.spi.write(b"\xff") - while self.spi.read(1, 0xFF)[0] == 0x00: - pass - self.cs(1) - self.spi.write(b"\xff") - - def readblocks(self, block_num, buf): - # workaround for shared bus, required for (at least) some Kingston - self.spi.write(b"\xff") - - nblocks = len(buf) // 512 - assert nblocks and not len(buf) % 512, "Buffer length is invalid" - if nblocks == 1: - # CMD17: set read address for single block - if self.cmd(17, block_num * self.cdv, 0, release=False) != 0: - # release the card - self.cs(1) - raise OSError(5) # EIO - # receive the data and release card - self.readinto(buf) - else: - # CMD18: set read address for multiple blocks - if self.cmd(18, block_num * self.cdv, 0, release=False) != 0: - self.cs(1) - raise OSError(5) # EIO - offset = 0 - mv = memoryview(buf) - while nblocks: - self.readinto(mv[offset : offset + 512]) - offset += 512 - nblocks -= 1 - if self.cmd(12, 0, 0xFF, skip1=True): - raise OSError(5) # EIO - - def writeblocks(self, block_num, buf): - # workaround for shared bus, required for (at least) some Kingston - self.spi.write(b"\xff") - nblocks, err = divmod(len(buf), 512) - assert nblocks and not err, "Buffer length is invalid" - if nblocks == 1: - # CMD24: set write address for single block - if self.cmd(24, block_num * self.cdv, 0) != 0: - raise OSError(5) # EIO - self.write(_TOKEN_DATA, buf) - else: - # CMD25: set write address for first block - if self.cmd(25, block_num * self.cdv, 0) != 0: - raise OSError(5) # EIO - offset = 0 - mv = memoryview(buf) - while nblocks: - self.write(_TOKEN_CMD25, mv[offset : offset + 512]) - offset += 512 - nblocks -= 1 - self.write_token(_TOKEN_STOP_TRAN) - - def ioctl(self, op, arg): - if op == 4: # get number of blocks - return self.sectors - if op == 5: # get block size in bytes - return 512 diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py b/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py index 838cbd76..11670ed6 100644 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py @@ -1,29 +1,89 @@ """ -ST7789/FrameBuffer(Inherit C module) +ST7789/FrameBuffer -MicroPython library for the ST7789(Inherit C module) +MicroPython library for the ST7789(TFT-SPI) ======================================================= @dahanzimin From the Mixly Team """ import time, uframebuf -from tftlcd import LCD15 +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) class ST7789(uframebuf.FrameBuffer_Uincode): - def __init__(self, width=240, height=240, reset=None, backlight=None, direction=1, font_address=0x700000): - self.display = LCD15(portrait=direction) - self.display.deinit() - if reset is not None: - reset(0, 50) - reset(1, 100) - self.display = LCD15(portrait=direction) - self._width = width - self._height = height + def __init__(self, spi, width, height, dc_pin=None, backlight=None, reset=None, font_address=0x700000): + self.spi = spi + 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) self.font(font_address) - self.show() + self._init() + # self.show() + self._oneclight = True self._backlight = backlight - if backlight: self.set_brightness(0.5) + + def display(self, data=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 + else: + self._buffer[:] = data #后期做图像大小处理 + if sync: self.show() + return self._buffer + + def _write(self, cmd, dat=None): + self.dc.off() + self.spi.write(bytearray([cmd])) + if dat is not None: + self.dc.on() + self.spi.write(dat) + + 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), + (0xC0, b'\x2C', 10), + (0xC2, b'\x01', 10), + (0xC3, b'\x12', 10), + (0xC4, b'\x20', 10), + (0xC6, b'\x0F', 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), + ]: + self._write(cmd, data) + if delay: + time.sleep_us(delay) def get_brightness(self): return self._backlight() / 100 @@ -40,9 +100,11 @@ class ST7789(uframebuf.FrameBuffer_Uincode): else: return (red & 0xf8) << 8 | (green & 0xfc) << 3 | blue >> 3 - def picture(self, x, y, path): - self.display.Picture(x, y, path) - def show(self): """Refresh the display and show the changes.""" - self.display.write_buf(self._buffer, 0, 0, self._width, self._height) + 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)