#!/usr/bin/env bash set -euo pipefail PORT="${PORT:-/dev/ttyACM0}" ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" FIRMWARE="$ROOT/firmware/adafruit-circuitpython-espressif_esp32s3_devkitc_1_n8r8-en_US-10.2.1.bin" CIRCUITPY_MOUNT="${CIRCUITPY_MOUNT:-}" if [[ ! -f "$FIRMWARE" ]]; then echo "Firmware not found: $FIRMWARE" >&2 exit 1 fi if [[ ! -r "$PORT" || ! -w "$PORT" ]]; then cat >&2 < Probing ESP32-S3 on $PORT" uvx esptool --chip esp32s3 --port "$PORT" flash-id echo "==> Erasing flash" uvx esptool --chip esp32s3 --port "$PORT" erase-flash echo "==> Flashing CircuitPython N8R8 firmware" uvx esptool --chip esp32s3 --port "$PORT" --baud 460800 write-flash -z 0x0 "$FIRMWARE" echo "==> Waiting for CIRCUITPY mount" for _ in $(seq 1 60); do if [[ -n "$CIRCUITPY_MOUNT" && -d "$CIRCUITPY_MOUNT" ]]; then break fi for candidate in \ "/media/$USER/CIRCUITPY" \ "/run/media/$USER/CIRCUITPY" \ "/media/$(id -un)/CIRCUITPY" \ "/Volumes/CIRCUITPY"; do if [[ -d "$candidate" ]]; then CIRCUITPY_MOUNT="$candidate" break 2 fi done sleep 1 done if [[ -z "$CIRCUITPY_MOUNT" || ! -d "$CIRCUITPY_MOUNT" ]]; then cat >&2 < Deploying prototype to $CIRCUITPY_MOUNT" mkdir -p "$CIRCUITPY_MOUNT/lib" cp "$ROOT/circuitpython/code.py" "$CIRCUITPY_MOUNT/code.py" cp "$ROOT/circuitpython/lib/"*.py "$CIRCUITPY_MOUNT/lib/" cp "$ROOT/circuitpython/lib/"*.mpy "$CIRCUITPY_MOUNT/lib/" sync echo "==> Deployed. Files on CIRCUITPY:" find "$CIRCUITPY_MOUNT" -maxdepth 2 -type f | sort echo "==> Done. Reset the board if it does not reload automatically."