diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_soar.py b/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_soar.py index 3fca0d9e..4b422c8c 100644 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_soar.py +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/mixgo_soar.py @@ -59,14 +59,12 @@ except Exception as e: print("Warning: Failed to communicate with MMC5603 (MGS) or", e) '''TFT/240*240''' -onboard_tft = st7789_bf.ST7789(onboard_spi, 240, 240, dc_pin=46, cs_pin=45, bl_pin=onboard_bot.tft_brightness, brightness=0, font_address=0x700000) +onboard_tft = st7789_bf.ST7789(onboard_spi, 240, 240, dc_pin=46, cs_pin=45, bl_pin=onboard_bot.tft_brightness, brightness=0.6, font_address=0x700000) '''2RGB_WS2812''' onboard_rgb = NeoPixel(Pin(40), 4) '''5KEY_Sensor''' - - class KEYSensor: def __init__(self, pin, range): self.pin = pin @@ -103,10 +101,7 @@ class KEYSensor: 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 @@ -116,7 +111,6 @@ class Button(KEYSensor): def _value(self): return not self.key.value() - B1key = Button(0) B2key = KEYSensor(17, 0) A1key = KEYSensor(17, 2300) @@ -125,8 +119,6 @@ A3key = KEYSensor(17, 800) A4key = KEYSensor(17, 2900) '''2LED-Independent''' - - class LED: def __init__(self, pins=[]): self._pins = [PWM(Pin(pin), duty_u16=0) for pin in pins] @@ -153,10 +145,8 @@ class LED: def getonoff(self, index): return True if self.getbrightness(index) > 50 else False - onboard_led = LED([38, 39]) - class Clock: def __init__(self, x, y, radius, color, oled=onboard_tft): # 定义时钟中心点和半径 self.display = oled @@ -227,7 +217,5 @@ class Clock: def clear(self, color=0): # 清除 self.display.ellipse(self.xc, self.yc, self.r, self.r, color, True) - '''Reclaim memory''' gc.collect() -onboard_tft.set_brightness(0.6) diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_bf.py b/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_bf.py index a5c56050..6ef9dc18 100644 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_bf.py +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_bf.py @@ -3,32 +3,11 @@ ST7789/FrameBuffer MicroPython library for the ST7789(TFT-SPI) ======================================================= -#Preliminary composition 20240110 - @dahanzimin From the Mixly Team """ import time import 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, brightness=0.6, font_address=0x700000): @@ -39,15 +18,10 @@ class ST7789(uframebuf.FrameBuffer_Uincode): super().__init__(self._buffer, width, height, uframebuf.RGB565) self.font(font_address) self._init() - self.show() - if brightness > 0: - time.sleep_ms(100) + # self.show() + self.bl_led = bl_pin if callable(bl_pin) else PWM(Pin(bl_pin)) + self._oneclight = True self._brightness = brightness - if callable(bl_pin): - self.bl_led = bl_pin - else: - self.bl_led = PWM(Pin(bl_pin), duty_u16=int( - self._brightness * 60000)) if bl_pin else None def _write(self, cmd, dat=None): self.cs.off() @@ -63,26 +37,24 @@ class ST7789(uframebuf.FrameBuffer_Uincode): 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), + (0x11, None, 120000), + (0x36, b'\x00', 10), + (0x3A, b'\x05', 10), + (0xB2, b'\x1F\x1F\x00\x33\x33', 10), + (0xB7, b'\x00', 10), + (0xBB, b'\x3F', 10), (0xC0, b'\x2C', 10), (0xC2, b'\x01', 10), - (0xC3, b'\x12', 10), + (0xC3, b'\x0F', 10), (0xC4, b'\x20', 10), - (0xC6, b'\x0F', 10), + (0xC6, b'\x13', 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), + (0xD6, b'\xA1', 10), + (0xE0, b'\xF0\x06\x0D\x0B\x0A\x07\x2E\x43\x45\x38\x14\x13\x25\x29', 10), + (0xE1, b'\xF0\x07\x0A\x08\x07\x23\x2E\x33\x44\x3A\x16\x17\x26\x2C', 10), + (0xE4, b'\x1D\x00\x00', 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: @@ -112,7 +84,7 @@ class ST7789(uframebuf.FrameBuffer_Uincode): if callable(self.bl_led): self.bl_led(brightness * 100) elif isinstance(self.bl_led, PWM): - self.bl_led.duty_u16(int(brightness*60000)) + 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.""" @@ -123,6 +95,9 @@ 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_RASET, b'\x00\x00\x00\xef') - self._write(_CMD_RAMWR, self._buffer) + if self._oneclight: + self.set_brightness(self._brightness) + self._oneclight = False + self._write(0x2A, b'\x00\x00\x00\xef') + self._write(0x2B, b'\x00\x00\x00\xef') + self._write(0x2C, self._buffer) 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 8f30d2d9..81a0c2ad 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 @@ -9,17 +9,6 @@ import time import uframebuf from machine import Pin from camera import Image, IMG -from micropython import const - -_CMD_SWRESET = const(0x01) -_CMD_SLPOUT = const(0x11) -_CMD_INVON = const(0x21) -_CMD_DISPON = const(0x29) -_CMD_CASET = const(0x2A) -_CMD_RASET = const(0x2B) -_CMD_RAMWR = const(0x2C) -_CMD_COLMOD = const(0x3A) -_CMD_MADCTL = const(0x36) class ST7789(uframebuf.FrameBuffer_Uincode): def __init__(self, spi, width, height, dc_pin=None, backlight=None, reset=None, font_address=0x700000): @@ -27,16 +16,16 @@ class ST7789(uframebuf.FrameBuffer_Uincode): 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) + if reset: reset(1, 100) self.font(font_address) self._init() # self.show() self._oneclight = True self._backlight = backlight - def display(self, data=None, x=None, y=None, rotation=0, sync=True): + def display(self, data=None, x=None, y=None, scale_width=None, scale_height=None, rotation=0, sync=True): if type(data) is str: - data = Image.open(data, rotation) + data = Image.open(data, scale_width, scale_height, self.width, self.height, rotation=rotation) if sync: self.fill(0x0, sync=False) self.blit_rgb565(data.image, data.width, data.height, x, y) if sync: self.show() @@ -57,23 +46,24 @@ class ST7789(uframebuf.FrameBuffer_Uincode): 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), + (0x11, None, 120000), + (0x36, b'\x00', 50), + (0x3A, b'\x05', 50), + (0xB2, b'\x1F\x1F\x00\x33\x33', 10), + (0xB7, b'\x00', 10), + (0xBB, b'\x36', 10), (0xC0, b'\x2C', 10), (0xC2, b'\x01', 10), - (0xC3, b'\x12', 10), + (0xC3, b'\x13', 10), (0xC4, b'\x20', 10), - (0xC6, b'\x0F', 10), + (0xC6, b'\x13', 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), + (0xD6, b'\xA1', 10), + (0xE0, b'\xF0\x08\x0E\x09\x08\x04\x2F\x33\x45\x36\x13\x12\x2A\x2D', 10), + (0xE1, b'\xF0\x0E\x12\x0C\x0A\x15\x2E\x32\x44\x39\x17\x18\x2B\x2F', 10), + (0xE4, b'\x1D\x00\x00', 10), + (0x21, None, 10), + (0x29, None, 10), ]: self._write(cmd, data) if delay: @@ -100,6 +90,6 @@ class ST7789(uframebuf.FrameBuffer_Uincode): 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) + self._write(0x2A, b'\x00\x00\x00\xef') + self._write(0x2B, b'\x00\x00\x00\xef') + self._write(0x2C, self._buffer)