Provide BOOT-triggered USB CDC maintenance mode for file updates, plus onboard LED activity flashes and enhanced display status information.
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""Local USB-REPL maintenance-mode selection for the T-Dongle-S3."""
|
|
|
|
import time
|
|
from machine import Pin
|
|
|
|
# The T-Dongle-S3 BOOT switch connects GPIO0 to ground.
|
|
_BUTTON_PIN = 0
|
|
_WINDOW_MS = 1500
|
|
|
|
active = False
|
|
_button = None
|
|
|
|
|
|
def button_pressed():
|
|
"""Return whether the BOOT button is currently pressed."""
|
|
global _button
|
|
if _button is None:
|
|
_button = Pin(_BUTTON_PIN, Pin.IN, Pin.PULL_UP)
|
|
return not _button.value()
|
|
|
|
|
|
def check_button():
|
|
"""Return true when BOOT is pressed shortly after a normal reset.
|
|
|
|
Do not hold BOOT while resetting: GPIO0 is also an ESP ROM boot strap and
|
|
that combination intentionally enters the download bootloader instead.
|
|
"""
|
|
global active
|
|
deadline = time.ticks_add(time.ticks_ms(), _WINDOW_MS)
|
|
while time.ticks_diff(deadline, time.ticks_ms()) > 0:
|
|
if button_pressed():
|
|
# Debounce the switch and leave the user enough time to release it.
|
|
time.sleep_ms(40)
|
|
if button_pressed():
|
|
active = True
|
|
return True
|
|
time.sleep_ms(20)
|
|
active = False
|
|
return False
|