This commit is contained in:
fredqian
2025-01-21 07:44:29 +08:00
parent ec6e6c7a92
commit 847bddd52f
24 changed files with 440 additions and 53900 deletions

View File

@@ -54,16 +54,16 @@
"math",
"ws2812",
"music",
"sant_bot",
"sc7a20",
"mk_pb4023",
"shtc3",
"mmc5603",
"spl06_001",
"sant_bot",
"ci130x"
],
"__file__": true,
"__size__": 6779,
"__size__": 6968,
"__name__": "mixgo_sant.py"
},
"mixgo_zero": {
@@ -128,7 +128,7 @@
"micropython"
],
"__file__": true,
"__size__": 3237,
"__size__": 3783,
"__name__": "sant_bot.py"
},
"sant_g2": {
@@ -171,7 +171,7 @@
"micropython"
],
"__file__": true,
"__size__": 3421,
"__size__": 2825,
"__name__": "st7789_cf.py"
}
}

View File

@@ -16,11 +16,26 @@ rtc_clock = RTC()
#onboard_i2c = I2C(0)
onboard_i2c = SoftI2C(scl=Pin(47), sda=Pin(48), freq=400000)
'''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)
'''SPI-onboard'''
onboard_spi = SPI(1, baudrate=50000000, polarity=0, phase=0)
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, cs_pin=None, bl_pin=None, font_address=0xE00000)
onboard_tft = st7789_cf.ST7789(onboard_spi, 240, 240, dc_pin=40, backlight=onboard_bot.tft_brightness, font_address=0xE00000)
'''ACC-Sensor'''
try :
@@ -57,13 +72,6 @@ try :
except Exception as e:
print("Warning: Failed to communicate with SPL06-001 (BPS) or",e)
'''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)
'''ASR-Sensor'''
try :
import ci130x
@@ -77,7 +85,7 @@ onboard_rgb = NeoPixel(Pin(21), 4)
'''1Buzzer-Music'''
from music import MIDI
onboard_music =MIDI(16)
onboard_music = MIDI(16)
'''5KEY_Sensor'''
class KEYSensor:
@@ -128,10 +136,10 @@ class Button(KEYSensor):
B1key = Button(0)
B2key = KEYSensor(15,0)
A1key = KEYSensor(15,2900)
A2key = KEYSensor(15,2300)
A3key = KEYSensor(15,1650)
A4key = KEYSensor(15,850)
A1key = KEYSensor(15,2300)
A2key = KEYSensor(15,1650)
A3key = KEYSensor(15,850)
A4key = KEYSensor(15,2900)
'''2-LED'''
class LED:

View File

@@ -12,7 +12,8 @@ _BOT035_ADDRESS = const(0x13)
_BOT5_TOUCH = const(0x01)
_BOT035_ADC = const(0x05)
_BOT035_PWM = const(0x07)
_BOT035_LED = const(0x0C)
_BOT035_CMD = const(0x0D)
_BOT035_KB = const(0x10)
_BOT035_MS = const(0x14)
_BOT035_STR = const(0x18)
@@ -60,6 +61,15 @@ class BOT035:
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 tft_brightness(self, brightness=None):
if brightness is None:
return self._rreg(_BOT035_LED)
else:
self._wreg(_BOT035_LED, max(min(brightness, 100), 0))
def tft_reset(self, value):
self._wreg(_BOT035_CMD, (self._rreg(_BOT035_CMD) & 0x7F) | (value << 7))
def hid_keyboard(self, special=0, general=0, release=True):
self._buf = bytearray(4)
self._buf[0] = special
@@ -79,6 +89,10 @@ class BOT035:
self._wreg(_BOT035_STR, ord(char) & 0xFF)
time.sleep_ms(20 + delay)
def hid_keyboard_state(self):
state = self._rreg(_BOT035_CMD)
return bool(state & 0x10), bool(state & 0x20), bool(state & 0x40)
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:

View File

@@ -3,8 +3,6 @@ ST7789/FrameBuffer
MicroPython library for the ST7789(TFT-SPI)
=======================================================
#Preliminary composition 20240110
@dahanzimin From the Mixly Team
"""
import time, uframebuf
@@ -30,31 +28,23 @@ _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.")
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)
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(200)
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
self._backlight = backlight
self.set_brightness(0.5)
def _write(self, cmd, dat = None):
if self.cs: self.cs.off()
def _write(self, cmd, dat=None):
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"""
@@ -74,24 +64,20 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
(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),
(_CMD_INVON, None, 10),
(_CMD_DISPON, None, 10),
]:
self._write(cmd, data)
if delay:
time.sleep_us(delay)
def get_brightness(self):
return self._brightness
return self._backlight() / 100
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))
self._backlight(int(brightness * 100))
def color(self, red, green=None, blue=None):
""" Convert red, green and blue values (0-255) into a 16-bit 565 encoding."""
@@ -102,6 +88,6 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
def show(self):
"""Refresh the display and show the changes."""
self._write(_CMD_CASET, b'\x00\x00\x01\x3f')
self._write(_CMD_CASET, b'\x00\x00\x00\xef')
self._write(_CMD_RASET, b'\x00\x00\x00\xef')
self._write(_CMD_RAMWR, self._buffer)

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

File diff suppressed because one or more lines are too long