Browse Source

Merge remote-tracking branch 'origin/main' into modern-standby-wake-fix

copilot-swe-agent[bot] 4 tháng trước cách đây
mục cha
commit
4e46da441c
4 tập tin đã thay đổi với 71 bổ sung và 4 xóa
  1. 6 0
      .github/workflows/build.yml
  2. 11 3
      .github/workflows/release.yml
  3. 2 1
      OpenPuck/puck_hid.cpp
  4. 52 0
      gen_uf2.sh

+ 6 - 0
.github/workflows/build.yml

@@ -47,6 +47,12 @@ jobs:
             --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \
             OpenPuck
 
+      - name: Generate UF2
+        # The Adafruit nRF52 core leaves its UF2 objcopy recipe commented out in
+        # platform.txt, so arduino-cli only emits .hex/.zip. Convert the .hex to
+        # a drag-and-drop .uf2 ourselves.
+        run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2
+
       - name: List build outputs
         run: |
           find build/openpuck -maxdepth 1 -type f -print | sort

+ 11 - 3
.github/workflows/release.yml

@@ -48,6 +48,9 @@ jobs:
             --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \
             OpenPuck
 
+      - name: Generate UF2 (standard)
+        run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2
+
       - name: Compile recovery build
         run: |
           mkdir -p build/openpuck-recovery build/cache/openpuck-recovery
@@ -59,6 +62,9 @@ jobs:
             --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DOPK_FACTORY_RESET=1" \
             OpenPuck
 
+      - name: Generate UF2 (recovery)
+        run: ./gen_uf2.sh build/openpuck-recovery/OpenPuck.ino.hex build/openpuck-recovery/OpenPuck.ino.uf2
+
       - name: Collect artifacts
         run: |
           mkdir -p release_assets
@@ -71,14 +77,16 @@ jobs:
             -maxdepth 1 -type f \
             \( -name '*.uf2' -o -name '*.zip' \) \
             -print | while read -r f; do
-            base="$(basename "$f")"
+            # Keep only the extension; the arduino base name (OpenPuck.ino.*)
+            # is redundant once we prefix with OpenPuck-<version>-<flavor>.
+            ext="${f##*.}"
             dir="$(basename "$(dirname "$f")")"
             if [ "$dir" = "openpuck-recovery" ]; then
               flavor="factory-reset"
             else
               flavor="standard"
             fi
-            cp "$f" "release_assets/OpenPuck-${VERSION}-${flavor}-${base}"
+            cp "$f" "release_assets/OpenPuck-${VERSION}-${flavor}.${ext}"
           done
           test -n "$(find release_assets -maxdepth 1 -type f -print -quit)"
           ls -la release_assets
@@ -100,6 +108,6 @@ jobs:
             ### Files included:
 
             - `.zip` files for Adafruit DFU tool
-            - `.uf2` files for drag-and-drop flashing, if generated by the board core
+            - `.uf2` files for drag-and-drop flashing (BOOT/UF2 drive)
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 2 - 1
OpenPuck/puck_hid.cpp

@@ -626,8 +626,9 @@ void SteamPuckController::task()
 		// so it shows ON_BATTERY + % rather than UNKNOWN. Skipped until the controller has reported a level.
 		if (conn && g_battery[s] && millis() - last43[s] >= 2000) {
 			uint8_t st = g_batteryState[s];
+			// EChargeState discharging -> SDL_POWERSTATE_ON_BATTERY
 			if (st != 1 && st != 2 && st != 4)
-				st = 1; // EChargeState discharging -> SDL_POWERSTATE_ON_BATTERY
+				st = 1;
 			uint8_t b43[14] = { 0 };
 			b43[0] = st; // ucChargeState
 			b43[1] = g_battery[s]; // ucBatteryLevel (percent)

+ 52 - 0
gen_uf2.sh

@@ -0,0 +1,52 @@
+#!/bin/sh
+# gen_uf2.sh -- convert a compiled .hex into a .uf2 for drag-and-drop flashing.
+#
+# The Adafruit nRF52 core ships uf2conv.py but leaves the UF2 objcopy recipe
+# COMMENTED OUT in platform.txt (recipe.objcopy.uf2.pattern), so `arduino-cli
+# compile` only ever emits .hex/.zip and never a .uf2. This regenerates the
+# .uf2 from the .hex after the compile step.
+#
+# Usage: ./gen_uf2.sh <input.hex> <output.uf2> [family]
+set -e
+
+HEX="$1"
+OUT="$2"
+# nRF52840 UF2 family id (boards.txt: feather52840.build.uf2_family=0xADA52840).
+FAMILY="${3:-0xADA52840}"
+
+if [ -z "$HEX" ] || [ -z "$OUT" ]; then
+	echo "usage: $0 <input.hex> <output.uf2> [family]" >&2
+	exit 2
+fi
+if [ ! -f "$HEX" ]; then
+	echo "gen_uf2.sh: input hex not found: $HEX" >&2
+	exit 1
+fi
+
+# Locate uf2conv.py inside the installed Adafruit nRF52 core. Honor a custom
+# Arduino data dir (config get), falling back to the per-OS defaults.
+DATA_DIR="$(arduino-cli config get directories.data 2>/dev/null || true)"
+if [ -z "$DATA_DIR" ]; then
+	if [ -d "$HOME/Library/Arduino15" ]; then
+		DATA_DIR="$HOME/Library/Arduino15"
+	else
+		DATA_DIR="$HOME/.arduino15"
+	fi
+fi
+
+UF2CONV="$(find "$DATA_DIR/packages/adafruit/hardware/nrf52" -name uf2conv.py 2>/dev/null | sort | tail -n1)"
+if [ -z "$UF2CONV" ]; then
+	echo "gen_uf2.sh: could not find uf2conv.py under $DATA_DIR" >&2
+	exit 1
+fi
+
+# Prefer python3; fall back to a bare python (the CI runner's setup-python
+# provides `python`, while macOS only ships `python3`). uf2conv.py is py3-safe.
+PYTHON="$(command -v python3 || command -v python || true)"
+if [ -z "$PYTHON" ]; then
+	echo "gen_uf2.sh: no python interpreter found" >&2
+	exit 1
+fi
+
+"$PYTHON" "$UF2CONV" -f "$FAMILY" -c -o "$OUT" "$HEX"
+echo "gen_uf2.sh: wrote $OUT (family $FAMILY)"