修改 mixgo_sant
This commit is contained in:
BIN
boards/default/micropython_esp32s3/build/Mixgo_Sant-v1.23.0.bin
Normal file
BIN
boards/default/micropython_esp32s3/build/Mixgo_Sant-v1.23.0.bin
Normal file
Binary file not shown.
23
boards/default/micropython_esp32s3/build/lib/mini_g2.py
Normal file
23
boards/default/micropython_esp32s3/build/lib/mini_g2.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
MINI G2 -MixGo MINI EXT G2
|
||||
|
||||
MicroPython library for the MINI G2 (Expansion board for MixGo MINI)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
|
||||
import gc
|
||||
from machine import Pin, SoftI2C
|
||||
|
||||
'''i2c-extboard'''
|
||||
ext_i2c = SoftI2C(scl=Pin(7), sda=Pin(8), freq=400000)
|
||||
|
||||
'''RFID_Sensor'''
|
||||
try :
|
||||
import rc522
|
||||
ext_rfid = rc522.RC522(ext_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with SI522A (RFID) or",e)
|
||||
|
||||
'''Reclaim memory'''
|
||||
gc.collect()
|
||||
239
boards/default/micropython_esp32s3/build/lib/mixgo_sant.py
Normal file
239
boards/default/micropython_esp32s3/build/lib/mixgo_sant.py
Normal file
@@ -0,0 +1,239 @@
|
||||
"""
|
||||
mixgo_sant Onboard resources
|
||||
|
||||
Micropython library for the mixgo_sant Onboard resources
|
||||
=======================================================
|
||||
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
from machine import *
|
||||
import time, gc, st7789_cf, math
|
||||
|
||||
'''RTC'''
|
||||
rtc_clock = RTC()
|
||||
|
||||
'''I2C-onboard'''
|
||||
#onboard_i2c = I2C(0)
|
||||
onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000)
|
||||
|
||||
'''SPI-onboard'''
|
||||
onboard_spi = SPI(1, baudrate=50000000, polarity=0, phase=0)
|
||||
|
||||
'''TFT/320*240'''
|
||||
onboard_tft = st7789_cf.ST7789(onboard_spi, 240, 240, dc_pin=40, cs_pin=None, bl_pin=None, font_address=0xE00000)
|
||||
|
||||
'''BOT035-Sensor'''
|
||||
try :
|
||||
import sant_bot
|
||||
onboard_bot = sant_bot.BOT035(onboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with BOT035 (Coprocessor) or",e)
|
||||
|
||||
'''ACC-Sensor'''
|
||||
try :
|
||||
import sc7a20
|
||||
onboard_acc = sc7a20.SC7A20(onboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with SC7A20H (ACC) or",e)
|
||||
|
||||
'''ALS_PS_CS-Sensor'''
|
||||
try :
|
||||
import mk_pb4023
|
||||
onboard_als = mk_pb4023.MK_PB4023(onboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with MK_PB4023 (ALS&PS&CS) 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)
|
||||
|
||||
'''ASR-Sensor'''
|
||||
try :
|
||||
import ci130x
|
||||
onboard_asr = ci130x.CI130X(onboard_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with CI130X (ASR) 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(21), 4)
|
||||
|
||||
'''1Buzzer-Music'''
|
||||
from music import MIDI
|
||||
onboard_music =MIDI(16)
|
||||
|
||||
'''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(15,0)
|
||||
A1key = KEYSensor(15,2900)
|
||||
A2key = KEYSensor(15,2300)
|
||||
A3key = KEYSensor(15,1650)
|
||||
A4key = KEYSensor(15,850)
|
||||
|
||||
'''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 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)
|
||||
|
||||
def getbrightness(self, index):
|
||||
return self._brightness[index - 1]
|
||||
|
||||
def setonoff(self, index, val):
|
||||
if val == -1:
|
||||
self.setbrightness(index, 100) if self.getbrightness(index) < 50 else self.setbrightness(index, 0)
|
||||
elif val == 1:
|
||||
self.setbrightness(index, 100)
|
||||
elif val == 0:
|
||||
self.setbrightness(index, 0)
|
||||
|
||||
def getonoff(self, index):
|
||||
return True if self.getbrightness(index) > 50 else False
|
||||
|
||||
onboard_led = LED(pins=[45, 46])
|
||||
|
||||
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()
|
||||
82
boards/default/micropython_esp32s3/build/lib/sant_bot.py
Normal file
82
boards/default/micropython_esp32s3/build/lib/sant_bot.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
SANT_WCH
|
||||
|
||||
Micropython library for the SANT_WCH(---)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
_BOT035_ADDRESS = const(0x13)
|
||||
_BOT5_TOUCH = const(0x01)
|
||||
_BOT035_ADC = const(0x05)
|
||||
_BOT035_PWM = const(0x07)
|
||||
|
||||
_BOT035_KB = const(0x10)
|
||||
_BOT035_MS = const(0x14)
|
||||
_BOT035_STR = const(0x18)
|
||||
|
||||
class BOT035:
|
||||
def __init__(self, i2c_bus):
|
||||
self._i2c = i2c_bus
|
||||
|
||||
def _wreg(self, reg, val):
|
||||
'''Write memory address'''
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, reg, val.to_bytes(1, 'little'))
|
||||
|
||||
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]
|
||||
|
||||
def key_adc(self):
|
||||
return (self._rreg(_BOT035_ADC) | self._rreg(_BOT035_ADC + 1) << 8)
|
||||
|
||||
def touch(self, index, value=None):
|
||||
index = max(min(index, 1), 0)
|
||||
touch = 4095 - (self._rreg(_BOT5_TOUCH + index * 2) | self._rreg(_BOT5_TOUCH + index * 2 + 1) << 8)
|
||||
return touch > value if value else touch
|
||||
|
||||
def touched(self, index, value=600):
|
||||
return self.touch(index, value)
|
||||
|
||||
def touch_slide(self):
|
||||
values = []
|
||||
for i in range(30):
|
||||
values.append((self.touch(1) - self._touchs[1]) - (self.touch(0) - self._touchs[0]))
|
||||
return round(sorted(values)[15] / 10)
|
||||
|
||||
def usben(self, index=1, duty=None, freq=None):
|
||||
index = max(min(index, 3), 1) - 1
|
||||
if duty is not None:
|
||||
duty = max(min(duty, 100), 0)
|
||||
self._wreg(_BOT035_PWM + index + 2, int(duty))
|
||||
if freq is not None:
|
||||
freq = max(min(freq, 65535), 10)
|
||||
self._wreg(_BOT035_PWM, freq & 0xFF)
|
||||
self._wreg(_BOT035_PWM + 1, freq >> 8)
|
||||
if freq is None and duty is None:
|
||||
return self._rreg(_BOT035_PWM + index + 2), self._rreg(_BOT035_PWM) | self._rreg(_BOT035_PWM + 1) << 8
|
||||
|
||||
def hid_keyboard(self, special=0, general=0, release=True):
|
||||
self._buf = bytearray(4)
|
||||
self._buf[0] = special
|
||||
if type(general) in (tuple, list):
|
||||
for i in range(len(general)):
|
||||
if i > 2: break
|
||||
self._buf[i + 1] = general[i]
|
||||
else:
|
||||
self._buf[1] = general
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_KB, self._buf)
|
||||
if release:
|
||||
time.sleep_ms(10)
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_KB, bytes(4))
|
||||
|
||||
def hid_keyboard_str(self, string, delay=0):
|
||||
for char in str(string):
|
||||
self._wreg(_BOT035_STR, ord(char) & 0xFF)
|
||||
time.sleep_ms(20 + delay)
|
||||
|
||||
def hid_mouse(self, keys=0, move=(0, 0), wheel=0, release=True):
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_MS, bytes([keys & 0x0F, move[0] & 0xFF, move[1] & 0xFF, wheel & 0xFF]))
|
||||
if release:
|
||||
time.sleep_ms(10)
|
||||
self._i2c.writeto_mem(_BOT035_ADDRESS, _BOT035_MS, bytes(4))
|
||||
30
boards/default/micropython_esp32s3/build/lib/sant_g2.py
Normal file
30
boards/default/micropython_esp32s3/build/lib/sant_g2.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
SANT G2 -MixGo SANT EXT G2
|
||||
|
||||
MicroPython library for the SANT G2 (Expansion board for MixGo SANT)
|
||||
=======================================================
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
|
||||
import gc
|
||||
from machine import Pin, SoftI2C
|
||||
|
||||
'''i2c-extboard'''
|
||||
ext_i2c = SoftI2C(scl=Pin(5), sda=Pin(6), freq=400000)
|
||||
|
||||
'''RFID_Sensor'''
|
||||
try :
|
||||
import rc522
|
||||
ext_rfid = rc522.RC522(ext_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with SI522A (RFID) or",e)
|
||||
|
||||
'''RADAR_Sensor'''
|
||||
try :
|
||||
import cbr817
|
||||
ext_mmw = cbr817.CBR817(ext_i2c)
|
||||
except Exception as e:
|
||||
print("Warning: Failed to communicate with CBR817 (RADAR) or",e)
|
||||
|
||||
'''Reclaim memory'''
|
||||
gc.collect()
|
||||
107
boards/default/micropython_esp32s3/build/lib/st7789_cf.py
Normal file
107
boards/default/micropython_esp32s3/build/lib/st7789_cf.py
Normal file
@@ -0,0 +1,107 @@
|
||||
"""
|
||||
ST7789/FrameBuffer
|
||||
|
||||
MicroPython library for the ST7789(TFT-SPI)
|
||||
=======================================================
|
||||
#Preliminary composition 20240110
|
||||
|
||||
@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)
|
||||
|
||||
class ST7789(uframebuf.FrameBuffer_Uincode):
|
||||
def __init__(self, spi, width, height, dc_pin=None, cs_pin=None, bl_pin=None, font_address=0x700000):
|
||||
if height != 240 or width not in [320, 240, 135]:
|
||||
raise ValueError("Unsupported display. 320x240, 240x240 and 135x240 are supported.")
|
||||
self.spi = spi
|
||||
self.dc = Pin(dc_pin, Pin.OUT, value=1)
|
||||
self.cs = Pin(cs_pin, Pin.OUT, value=1) if cs_pin is not None else None
|
||||
self._buffer = bytearray(width * height * 2)
|
||||
super().__init__(self._buffer, width, height, uframebuf.RGB565)
|
||||
self.font(font_address)
|
||||
self._init()
|
||||
self.show()
|
||||
time.sleep_ms(100)
|
||||
self._brightness = 0.6
|
||||
self.bl_led = PWM(Pin(bl_pin), duty_u16=int(self._brightness * 60000)) if bl_pin is not None else None
|
||||
|
||||
def _write(self, cmd, dat = None):
|
||||
if self.cs: self.cs.off()
|
||||
self.dc.off()
|
||||
self.spi.write(bytearray([cmd]))
|
||||
if self.cs: self.cs.on()
|
||||
if dat is not None:
|
||||
if self.cs: self.cs.off()
|
||||
self.dc.on()
|
||||
self.spi.write(dat)
|
||||
if self.cs: self.cs.on()
|
||||
|
||||
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),
|
||||
(0x21, None, 10),
|
||||
(0x29, None, 10),
|
||||
# (_CMD_INVOFF, None, 10),
|
||||
# (_CMD_NORON, None, 10),
|
||||
# (_CMD_DISPON, None, 200),
|
||||
]:
|
||||
self._write(cmd, data)
|
||||
if delay:
|
||||
time.sleep_us(delay)
|
||||
|
||||
def get_brightness(self):
|
||||
return self._brightness
|
||||
|
||||
def set_brightness(self, brightness):
|
||||
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.bl_led.duty_u16(int(brightness*60000))
|
||||
|
||||
def color(self, red, green=None, blue=None):
|
||||
""" Convert red, green and blue values (0-255) into a 16-bit 565 encoding."""
|
||||
if green is None or blue is None:
|
||||
return red
|
||||
else:
|
||||
return (red & 0xf8) << 8 | (green & 0xfc) << 3 | blue >> 3
|
||||
|
||||
def show(self):
|
||||
"""Refresh the display and show the changes."""
|
||||
self._write(_CMD_CASET, b'\x00\x00\x01\x3f')
|
||||
self._write(_CMD_RASET, b'\x00\x00\x00\xef')
|
||||
self._write(_CMD_RAMWR, self._buffer)
|
||||
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"board": {
|
||||
"元控青春": "micropython:esp32s3:mixgo_nova",
|
||||
"元控": "micropython:esp32s3:mixgo_zero",
|
||||
"MixGo Sant": "micropython:esp32c3:mixgo_sant"
|
||||
"元控自强": "micropython:esp32s3:mixgo_sant"
|
||||
},
|
||||
"language": "MicroPython",
|
||||
"burn": {
|
||||
|
||||
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
Reference in New Issue
Block a user