diff --git a/boards/default_src/micropython_esp32s3/origin/build/Mixgo_Sant-v1.13.0.bin b/boards/default_src/micropython_esp32s3/origin/build/Mixgo_Sant-v1.13.0.bin new file mode 100644 index 00000000..dc91df00 Binary files /dev/null and b/boards/default_src/micropython_esp32s3/origin/build/Mixgo_Sant-v1.13.0.bin differ diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/camera.py b/boards/default_src/micropython_esp32s3/origin/build/lib/camera.py new file mode 100644 index 00000000..4e29192b --- /dev/null +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/camera.py @@ -0,0 +1,30 @@ +""" +Camera GC032A/FrameBuffer(Inherit C module) + +MicroPython library for the GC032A(Inherit C module) +======================================================= +@dahanzimin From the Mixly Team +""" + +import time +from sensor import * +from machine import SoftI2C, Pin +from mixgo_sant import onboard_bot + +class GC032A(Camera): + def __init__(self, framesize=LCD, hmirror=None): + onboard_bot.cam_en(0) + time.sleep_ms(500) + super().__init__() + 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) + + def deinit(self): + super().deinit() + time.sleep_ms(100) + onboard_bot.cam_en(1) diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/ci130xx.py b/boards/default_src/micropython_esp32s3/origin/build/lib/ci130xx.py new file mode 100644 index 00000000..13a5eda1 --- /dev/null +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/ci130xx.py @@ -0,0 +1,98 @@ +""" +CI130X + +MicroPython library for the CI130X (ASR-I2C) +======================================================= +@dahanzimin From the Mixly Team +""" +import time +from struct import pack +from micropython import const + +_CI_ADDRESS = const(0x64) +_CI_ID_GET = const(0x02) +_CI_ID_SET = const(0x03) +_CI_ID_NUM = const(0x06) +_CI_ID_CLE = const(0x07) +_CI_ID_PACTRL = const(0x09) +_CI_ID_END = const(0x5A) + +class CI130X: + def __init__(self, i2c_bus, func=None, addr=_CI_ADDRESS): + self._device = i2c_bus + self._address = addr + self._cmd_id = None + self._func = func + + def _wreg(self, reg): + '''Write memory address''' + try: + self._device.writeto(self._address, reg) + except: + self._func(1) #打开电源 + time.sleep_ms(500) + self._device.writeto(self._address, reg) + + def _rreg(self, reg, nbytes=1): + '''Read memory address''' + try: + return self._device.readfrom_mem(self._address, reg, nbytes) + except: + self._func(1) #打开电源 + time.sleep_ms(500) + return self._device.readfrom_mem(self._address, reg, nbytes) + + + def status(self): + """返回 (是否唤醒, 是否播放)""" + _buf = self._rreg(_CI_ID_GET, 3) + return (bool(_buf[1] & 0x01), bool(_buf[1] & 0x10)) if _buf[2] == _CI_ID_END else (None, None) + + def cmd_id(self, repeat=False): + """返回 识别命令词对应ID""" + _buf = self._rreg(_CI_ID_GET, 3) + if not repeat: + self._wreg(bytes([_CI_ID_CLE, 0, 0, _CI_ID_END])) + time.sleep_ms(50) + self._cmd_id = _buf[0] if _buf[2] == _CI_ID_END else None + return self._cmd_id + + def result(self, ext_id=None): + """获取比较结果 或者输出结果""" + return self._cmd_id if ext_id is None else bool(self._cmd_id == ext_id) + + def sys_cmd(self, value, blocking=True): + """系统命令,1,2唤醒 202~205音量调整 206,207回复播报开关 208退出唤醒""" + self.play_id(value, blocking) + + def play_id(self, value, blocking=True): + """播放命令词对应ID语音""" + self._wreg(bytes([_CI_ID_SET, value, 0, _CI_ID_END])) + while blocking: + time.sleep_ms(10) + if not self.status()[1]: + break + + def play_num(self, value, blocking=True): + """播放浮点数据的合成语音""" + self._wreg(bytes([_CI_ID_NUM]) + pack('d', float(value)) + bytes([0, _CI_ID_END])) + while blocking: + time.sleep_ms(10) + if not self.status()[1]: + break + + def play(self, star=None, num=None, end=None, delay=10): + """组合播报名词+数值+单位""" + if star is not None: + self.play_id(star) + time.sleep_ms(delay) + if num is not None: + self.play_num(num) + time.sleep_ms(delay) + if end is not None: + self.play_id(end) + time.sleep_ms(delay) + + def pa_ctrl(self, value=True, delay=10): + self._wreg(bytes([_CI_ID_PACTRL, int(value), 0, _CI_ID_END])) + if value: time.sleep_ms(delay) 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 c98273d4..35503040 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 @@ -1,5 +1,5 @@ """ -mixgo_sant Onboard resources +mixgo_sant Onboard resources(v1.9) Micropython library for the mixgo_sant Onboard resources ======================================================= @@ -13,79 +13,68 @@ import time, gc, st7789_cf, math rtc_clock = RTC() '''I2C-onboard''' -#onboard_i2c = I2C(0) -onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000) +#inboard_i2c = I2C(0) +inboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000) +onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(38), freq=400000) '''BOT035-Sensor''' try : import sant_bot - onboard_bot = sant_bot.BOT035(onboard_i2c) + onboard_bot = sant_bot.BOT035(inboard_i2c) except Exception as e: print("Warning: Failed to communicate with BOT035 (Coprocessor) or",e) -'''SPI-onboard''' -onboard_spi = SPI(1, baudrate=80000000, polarity=1, phase=1) - -onboard_bot.tft_reset(0) -time.sleep_ms(50) -onboard_bot.tft_reset(1) -time.sleep_ms(150) - -'''SPI-onboard''' -onboard_spi = SPI(1, baudrate=80000000, polarity=1, phase=1) - '''TFT/240*240''' -onboard_tft = st7789_cf.ST7789(onboard_spi, 240, 240, dc_pin=40, backlight=onboard_bot.tft_brightness, font_address=0xE00000) +onboard_tft = st7789_cf.ST7789(reset=onboard_bot.tft_reset, backlight=onboard_bot.tft_brightness, font_address=0xE00000) '''ACC-Sensor''' try : import sc7a20 - onboard_acc = sc7a20.SC7A20(onboard_i2c) + onboard_acc = sc7a20.SC7A20(inboard_i2c) except Exception as e: print("Warning: Failed to communicate with SC7A20H (ACC) or",e) -'''ALS_PS_CS-Sensor''' +'''ALS_PS-Sensor *2''' try : - import mk_pb4023 - onboard_als = mk_pb4023.MK_PB4023(onboard_i2c) + import ltr553als + onboard_als_l = ltr553als.LTR_553ALS(onboard_i2c) except Exception as e: - print("Warning: Failed to communicate with MK_PB4023 (ALS&PS&CS) or",e) + print("Warning: Failed to communicate with TR_553ALS-L (ALS&PS) or",e) + +try : + #import ltr553als + onboard_als_r = ltr553als.LTR_553ALS(inboard_i2c) +except Exception as e: + print("Warning: Failed to communicate with TR_553ALS-R (ALS&PS) or",e) '''THS-Sensor''' try : import shtc3 - onboard_ths = shtc3.SHTC3(onboard_i2c) + onboard_ths = shtc3.SHTC3(inboard_i2c) except Exception as e: print("Warning: Failed to communicate with GXHTC3 (THS) or",e) '''MGS-Sensor''' try : import mmc5603 - onboard_mgs = mmc5603.MMC5603(onboard_i2c) + onboard_mgs = mmc5603.MMC5603(inboard_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) - '''ASR-Sensor''' try : - import ci130x - onboard_asr = ci130x.CI130X(onboard_i2c) + from ci130xx import CI130X + onboard_asr = CI130X(inboard_i2c, onboard_bot.asr_en) except Exception as e: print("Warning: Failed to communicate with CI130X (ASR) or",e) '''2RGB_WS2812''' -from ws2812 import NeoPixel -onboard_rgb = NeoPixel(Pin(21), 4) +from ws2812x import NeoPixel +onboard_rgb = NeoPixel(onboard_bot.rgb_sync, 4) '''1Buzzer-Music''' -from music import MIDI -onboard_music = MIDI(16, pa_ctrl=onboard_asr.pa_ctrl) +from musicx import MIDI +onboard_music = MIDI(46, pa_ctrl=onboard_bot.spk_en) '''5KEY_Sensor''' class KEYSensor: @@ -94,7 +83,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): @@ -135,26 +124,22 @@ class Button(KEYSensor): return not self.key.value() B1key = Button(0) -B2key = KEYSensor(15,0) -A1key = KEYSensor(15,2300) -A2key = KEYSensor(15,1650) -A3key = KEYSensor(15,850) -A4key = KEYSensor(15,2900) +B2key = KEYSensor(17, 0) +A1key = KEYSensor(17, 1600) +A2key = KEYSensor(17, 1100) +A3key = KEYSensor(17, 550) +A4key = KEYSensor(17, 2100) '''2-LED''' class LED: - def __init__(self, pins=[]): - self._pins = [PWM(Pin(pin), duty_u16=0) for pin in pins] - self._brightness = [0 for _ in range(len(self._pins))] + def __init__(self, func): + self._func = func def setbrightness(self, index, val): - if not 0 <= val <= 100: - raise ValueError("Brightness must be in the range: 0-100%") - self._brightness[index - 1] = val - self._pins[index - 1].duty_u16(val * 65535 // 100) + self._func(index, val) def getbrightness(self, index): - return self._brightness[index - 1] + return self._func(index) def setonoff(self, index, val): if val == -1: @@ -167,7 +152,7 @@ class LED: def getonoff(self, index): return True if self.getbrightness(index) > 50 else False -onboard_led = LED(pins=[45, 46]) +onboard_led = LED(onboard_bot.led_pwm) class Voice_Energy: def read(self): diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/musicx.py b/boards/default_src/micropython_esp32s3/origin/build/lib/musicx.py new file mode 100644 index 00000000..5a273906 --- /dev/null +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/musicx.py @@ -0,0 +1,162 @@ +""" +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 +""" + +from time import sleep_ms +from machine import Pin, PWM + +normal_tone = { + 'A1': 55, 'B1': 62, 'C1': 33, 'D1': 37, 'E1': 41, 'F1': 44, 'G1': 49, + 'A2': 110, 'B2': 123, 'C2': 65, 'D2': 73, 'E2': 82, 'F2': 87, 'G2': 98, + 'A3': 220, 'B3': 247, 'C3': 131, 'D3': 147, 'E3': 165, 'F3': 175, 'G3': 196, + 'A4': 440, 'B4': 494, 'C4': 262, 'D4': 294, 'E4': 330, 'F4': 349, 'G4': 392, + 'A5': 880, 'B5': 988, 'C5': 523, 'D5': 587, 'E5': 659, 'F5': 698, 'G5': 784, + 'A6': 1760, 'B6': 1976, 'C6': 1047, 'D6': 1175, 'E6': 1319, 'F6': 1397, 'G6': 1568, + 'A7': 3520, 'B7': 3951, 'C7': 2093, 'D7': 2349, 'E7': 2637, 'F7': 2794, 'G7': 3135, + 'A8': 7040, 'B8': 7902, 'C8': 4186, 'D8': 4699, 'E8': 5274, 'F8': 5588, 'G8': 6271, + 'A9': 14080, 'B9': 15804 } + +Letter = 'ABCDEFG#R' + +class MIDI(): + def __init__(self, pin, volume=100, invert=0, pa_ctrl=None): + self.reset() + self._invert=invert + self._pin = pin + self._volume = volume + self._pwm = None + self._pa_ctrl = pa_ctrl + + def set_volume(self,volume): + if not 0 <= volume <= 100: + raise ValueError("Volume value is in the range: 0-100") + self._volume=volume + + def set_tempo(self, ticks=4, bpm=120): + self.ticks = ticks + self.bpm = bpm + self.beat = 60000 / self.bpm / self.ticks + + def set_octave(self, octave=4): + self.octave = octave + + def set_duration(self, duration=4): + self.duration = duration + + def get_tempo(self): + return (self.ticks, self.bpm) + + def get_octave(self): + return self.octave + + def get_duration(self): + return self.duration + + def reset(self): + self.set_duration() + self.set_octave() + self.set_tempo() + + def parse(self, tone, dict): + time = self.beat * self.duration + pos = tone.find(':') + if pos != -1: + time = self.beat * int(tone[(pos + 1):]) + tone = tone[:pos] + freq, tone_size = 1, len(tone) + if 'R' in tone: + freq = 40000 + elif tone_size == 1: + freq = dict[tone[0] + str(self.octave)] + elif tone_size == 2: + freq = dict[tone] + self.set_octave(tone[1:]) + return int(freq), int(time) + + def midi(self, tone): + pos = tone.find('#') + if pos != -1: + return self.parse(tone.replace('#', ''), normal_tone) + pos = tone.find('B') + if pos != -1 and pos != 0: + return self.parse(tone.replace('B', ''), normal_tone) + return self.parse(tone, normal_tone) + + def set_default(self, tone): + pos = tone.find(':') + if pos != -1: + self.set_duration(int(tone[(pos + 1):])) + tone = tone[:pos] + + def play(self, tune, duration=None): + if self._pa_ctrl: self._pa_ctrl(1) + self._pwm = PWM(Pin(self._pin), duty=1023 if self._invert else 0) + if duration is None: + self.set_default(tune[0]) + else: + self.set_duration(duration) + for tone in tune: + tone = tone.upper() + 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]) + sleep_ms(midi[1]) + self._pwm.freq(40000) + sleep_ms(1) + if self._pa_ctrl: self._pa_ctrl(0) + self._pwm.deinit() + sleep_ms(10) + + 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 pitch_time(self, freq, delay): + 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)) + sleep_ms(delay) + if self._pa_ctrl: self._pa_ctrl(0) + self._pwm.deinit() + sleep_ms(10) + + def stop(self): + if self._pa_ctrl: self._pa_ctrl(0) + if self._pwm: self._pwm.deinit() + sleep_ms(10) + + DADADADUM=['r4:2','g','g','g','eb:8','r:2','f','f','f','d:8'] + ENTERTAINER=['d4:1','d#','e','c5:2','e4:1','c5:2','e4:1','c5:3','c:1','d','d#','e','c','d','e:2','b4:1','d5:2','c:4'] + PRELUDE=['c4:1','e','g','c5','e','g4','c5','e','c4','e','g','c5','e','g4','c5','e','c4','d','g','d5','f','g4','d5','f','c4','d','g','d5','f','g4','d5','f','b3','d4','g','d5','f','g4','d5','f','b3','d4','g','d5','f','g4','d5','f','c4','e','g','c5','e','g4','c5','e','c4','e','g','c5','e','g4','c5','e'] + ODE=['e4','e','f','g','g','f','e','d','c','c','d','e','e:6','d:2','d:8','e:4','e','f','g','g','f','e','d','c','c','d','e','d:6','c:2','c:8'] + NYAN=['f#5:1','g#','c#:1','d#:2','b4:1','d5:1','c#','b4:2','b','c#5','d','d:1','c#','b4:1','c#5:1','d#','f#','g#','d#','f#','c#','d','b4','c#5','b4','d#5:2','f#','g#:1','d#','f#','c#','d#','b4','d5','d#','d','c#','b4','c#5','d:2','b4:1','c#5','d#','f#','c#','d','c#','b4','c#5:2','b4','c#5','b4','f#:1','g#','b:2','f#:1','g#','b','c#5','d#','b4','e5','d#','e','f#','b4:2','b','f#:1','g#','b','f#','e5','d#','c#','b4','f#','d#','e','f#','b:2','f#:1','g#','b:2','f#:1','g#','b','b','c#5','d#','b4','f#','g#','f#','b:2','b:1','a#','b','f#','g#','b','e5','d#','e','f#','b4:2','c#5'] + RINGTONE=['c4:1','d','e:2','g','d:1','e','f:2','a','e:1','f','g:2','b','c5:4'] + FUNK=['c2:2','c','d#','c:1','f:2','c:1','f:2','f#','g','c','c','g','c:1','f#:2','c:1','f#:2','f','d#'] + BLUES=['c2:2','e','g','a','a#','a','g','e','c2:2','e','g','a','a#','a','g','e','f','a','c3','d','d#','d','c','a2','c2:2','e','g','a','a#','a','g','e','g','b','d3','f','f2','a','c3','d#','c2:2','e','g','e','g','f','e','d'] + BIRTHDAY=['c4:4','c:1','d:4','c:4','f','e:8','c:3','c:1','d:4','c:4','g','f:8','c:3','c:1','c5:4','a4','f','e','d','a#:3','a#:1','a:4','f','g','f:8'] + WEDDING=['c4:4','f:3','f:1','f:8','c:4','g:3','e:1','f:8','c:4','f:3','a:1','c5:4','a4:3','f:1','f:4','e:3','f:1','g:8'] + FUNERAL=['c3:4','c:3','c:1','c:4','d#:3','d:1','d:3','c:1','c:3','b2:1','c3:4'] + PUNCHLINE=['c4:3','g3:1','f#','g','g#:3','g','r','b','c4'] + PYTHON=['d5:1','b4','r','b','b','a#','b','g5','r','d','d','r','b4','c5','r','c','c','r','d','e:5','c:1','a4','r','a','a','g#','a','f#5','r','e','e','r','c','b4','r','b','b','r','c5','d:5','d:1','b4','r','b','b','a#','b','b5','r','g','g','r','d','c#','r','a','a','r','a','a:5','g:1','f#:2','a:1','a','g#','a','e:2','a:1','a','g#','a','d','r','c#','d','r','c#','d:2','r:3'] + BADDY=['c3:3','r','d:2','d#','r','c','r','f#:8'] + CHASE=['a4:1','b','c5','b4','a:2','r','a:1','b','c5','b4','a:2','r','a:2','e5','d#','e','f','e','d#','e','b4:1','c5','d','c','b4:2','r','b:1','c5','d','c','b4:2','r','b:2','e5','d#','e','f','e','d#','e'] + BA_DING=['b5:1','e6:3'] + WAWAWAWAA=['e3:3','r:1','d#:3','r:1','d:4','r:1','c#:8'] + JUMP_UP=['c5:1','d','e','f','g'] + JUMP_DOWN=['g5:1','f','e','d','c'] + POWER_UP=['g4:1','c5','e4','g5:2','e5:1','g5:3'] + POWER_DOWN=['g5:1','d#','c','g4:2','b:1','c5:3'] 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 ec5ad213..4eb750fb 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,75 +1,29 @@ """ -ST7789/FrameBuffer +ST7789/FrameBuffer(Inherit C module) -MicroPython library for the ST7789(TFT-SPI) +MicroPython library for the ST7789(Inherit C module) ======================================================= @dahanzimin From the Mixly Team """ import time, uframebuf -from machine import Pin, PWM -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 tftlcd import LCD15 class ST7789(uframebuf.FrameBuffer_Uincode): - def __init__(self, spi, width, height, dc_pin=None, backlight=None, font_address=0x700000): - self.spi = spi - self.dc = Pin(dc_pin, Pin.OUT, value=1) + def __init__(self, width=240, height=240, reset=None, backlight=None, direction=1, font_address=0x700000): + if reset is not None: + reset(0) + time.sleep_ms(50) + reset(1) + time.sleep_ms(100) + self.display = LCD15(portrait=direction) + self._width = width + self._height = height self._buffer = bytearray(width * height * 2) super().__init__(self._buffer, width, height, uframebuf.RGB565) self.font(font_address) - self._init() self.show() self._backlight = backlight - self.set_brightness(0.5) - - 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) + if backlight: self.set_brightness(0.5) def get_brightness(self): return self._backlight() / 100 @@ -86,8 +40,9 @@ 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._write(_CMD_CASET, b'\x00\x00\x00\xef') - self._write(_CMD_RASET, b'\x00\x00\x00\xef') - self._write(_CMD_RAMWR, self._buffer) + self.display.write_buf(self._buffer, 0, 0, self._width, self._height) diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/ws2812x.py b/boards/default_src/micropython_esp32s3/origin/build/lib/ws2812x.py new file mode 100644 index 00000000..d081492e --- /dev/null +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/ws2812x.py @@ -0,0 +1,66 @@ +""" +WS2812 RGB(x035) + +Micropython library for the WS2812 NeoPixel-RGB(method inheritance) +======================================================= +@dahanzimin From the Mixly Team +""" +from time import sleep + +class NeoPixel: + def __init__(self, func, n, bpp=3, ORDER=(1, 0, 2, 3)): + self.func = func + self.bpp = bpp + self.rgbs = n + self.ORDER = ORDER + self.rgb_buf = bytearray(self.rgbs * bpp) + self.write() + + def __len__(self): + return self.rgbs + + def __setitem__(self, n, v): + for i in range(self.bpp): + self.rgb_buf[n * self.bpp + self.ORDER[i]] = v[i] + + def __getitem__(self, n): + return tuple(self.rgb_buf[n * self.bpp + self.ORDER[i]] for i in range(self.bpp)) + + def fill(self, v): + for i in range(self.bpp): + j = self.ORDER[i] + while j < self.rgbs * self.bpp: + self.rgb_buf[j] = v[i] + j += self.bpp + + def write(self): + self.func(self.rgb_buf) + + def color_chase(self,R, G, B, wait): + for i in range(self.rgbs): + self.__setitem__(i,(R, G, B)) + self.write() + sleep(wait/1000) + + def rainbow_cycle(self, wait, clear=True): + for j in range(255): + for i in range(self.rgbs): + rc_index = (i * 256 // self.rgbs) + j + self.__setitem__(i,self.wheel(rc_index & 255)) + self.write() + sleep(wait / 1000 / 256) + if clear: + self.fill((0, 0, 0)) + self.write() + + def wheel(self,pos): + if pos < 0 or pos > 255: + return (0, 0, 0) + elif pos < 85: + return (pos * 3, 255 - pos * 3, 0) + elif pos < 170: + pos -= 85 + return (255 - pos * 3, 0, pos * 3) + else: + pos -= 170 + return (0, pos * 3, 255 - pos * 3)