# boot.py - runs once at power-on (before USB connects); decides who owns the filesystem.
#
# DEFAULT = appliance mode: the FIRMWARE owns the drive, so it can save your practice log to
# /history.json and write /programs.json that the editor pushes over USB-MIDI. The drive is then
# READ-ONLY to the computer - which also protects the firmware from accidental deletion.
#
# HOLD BUTTON A (GP12 on the Pico Scroll Pack) WHILE PLUGGING IN = editor mode: the drive is
# writable by the computer, so you can drag programs.json / app.mpy on from any OS or browser
# (the universal fallback). Reset afterwards to return to appliance mode.
#
# Also frees a USB endpoint (disables unused HID) and makes sure USB-MIDI is available.
import board, digitalio, storage, usb_hid, usb_midi
try: usb_hid.disable()
except Exception: pass
usb_midi.enable()
a = digitalio.DigitalInOut(board.GP12)
a.switch_to_input(pull=digitalio.Pull.UP)
appliance = a.value            # value True (pull-up, not pressed) -> appliance mode
a.deinit()
if appliance:
    try: storage.remount("/", readonly=False)   # writable by code, read-only to the computer
    except Exception: pass
