瀏覽代碼

fix: set CFG_TUD_HID=6 everywhere; have CI use make build/reversepuck (#159)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot 3 月之前
父節點
當前提交
a8b1c1e73a
共有 6 個文件被更改,包括 21 次插入 和 47 次删除
  1. 2 14
      .github/workflows/build.yml
  2. 3 21
      .github/workflows/release.yml
  3. 1 3
      AGENTS.md
  4. 1 1
      CODE_MAP.md
  5. 11 5
      Makefile
  6. 3 3
      docs/BUILD_AND_DEPLOY.md

+ 2 - 14
.github/workflows/build.yml

@@ -89,13 +89,7 @@ jobs:
       - name: Compile OpenPuck
         run: |
           mkdir -p build/openpuck build/cache/openpuck
-          arduino-cli compile \
-            -b adafruit:nrf52:feather52840 \
-            --clean \
-            --build-path build/cache/openpuck \
-            --output-dir build/openpuck \
-            --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DCFG_TUD_TASK_QUEUE_SZ=64 -DCFG_TUD_VENDOR_TX_BUFSIZE=256" \
-            OpenPuck
+          make build BUILD_PATH=build/cache/openpuck OUTPUT_DIR=build/openpuck
 
       - name: Generate UF2 (OpenPuck)
         # The Adafruit nRF52 core leaves its UF2 objcopy recipe commented out in
@@ -106,13 +100,7 @@ jobs:
       - name: Compile ReversePuckFirmware
         run: |
           mkdir -p build/reversepuck build/cache/reversepuck
-          arduino-cli compile \
-            -b adafruit:nrf52:feather52840 \
-            --clean \
-            --build-path build/cache/reversepuck \
-            --output-dir build/reversepuck \
-            --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_TASK_QUEUE_SZ=64 -DCFG_TUD_VENDOR_TX_BUFSIZE=256" \
-            ReversePuckFirmware
+          make reversepuck BUILD_PATH=build/cache/reversepuck OUTPUT_DIR=build/reversepuck
 
       - name: Generate UF2 (ReversePuckFirmware)
         run: ./gen_uf2.sh build/reversepuck/ReversePuckFirmware.ino.hex build/reversepuck/ReversePuckFirmware.ino.uf2

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

@@ -110,13 +110,7 @@ jobs:
       - name: Compile OpenPuck
         run: |
           mkdir -p build/openpuck build/cache/openpuck
-          arduino-cli compile \
-            -b adafruit:nrf52:feather52840 \
-            --clean \
-            --build-path build/cache/openpuck \
-            --output-dir build/openpuck \
-            --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DCFG_TUD_TASK_QUEUE_SZ=64 -DCFG_TUD_VENDOR_TX_BUFSIZE=256" \
-            OpenPuck
+          make build BUILD_PATH=build/cache/openpuck OUTPUT_DIR=build/openpuck
 
       - name: Generate UF2 (standard)
         run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2
@@ -124,13 +118,7 @@ jobs:
       - name: Compile ReversePuckFirmware
         run: |
           mkdir -p build/reversepuck build/cache/reversepuck
-          arduino-cli compile \
-            -b adafruit:nrf52:feather52840 \
-            --clean \
-            --build-path build/cache/reversepuck \
-            --output-dir build/reversepuck \
-            --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_TASK_QUEUE_SZ=64 -DCFG_TUD_VENDOR_TX_BUFSIZE=256" \
-            ReversePuckFirmware
+          make reversepuck BUILD_PATH=build/cache/reversepuck OUTPUT_DIR=build/reversepuck
 
       - name: Generate UF2 (ReversePuckFirmware)
         run: ./gen_uf2.sh build/reversepuck/ReversePuckFirmware.ino.hex build/reversepuck/ReversePuckFirmware.ino.uf2
@@ -138,13 +126,7 @@ jobs:
       - name: Compile recovery build
         run: |
           mkdir -p build/openpuck-recovery build/cache/openpuck-recovery
-          arduino-cli compile \
-            -b adafruit:nrf52:feather52840 \
-            --clean \
-            --build-path build/cache/openpuck-recovery \
-            --output-dir build/openpuck-recovery \
-            --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DCFG_TUD_TASK_QUEUE_SZ=64 -DCFG_TUD_VENDOR_TX_BUFSIZE=256 -DOPK_FACTORY_RESET=1" \
-            OpenPuck
+          make build-recovery BUILD_PATH=build/cache/openpuck-recovery OUTPUT_DIR=build/openpuck-recovery
 
       - name: Generate UF2 (recovery)
         run: ./gen_uf2.sh build/openpuck-recovery/OpenPuck.ino.hex build/openpuck-recovery/OpenPuck.ino.uf2

+ 1 - 3
AGENTS.md

@@ -61,9 +61,7 @@ CI rejects a PR immediately if either fails. The lint lives in
 ## Build / compile-check (no hardware needed)
 
 ```sh
-arduino-cli compile -b adafruit:nrf52:feather52840 \
-  --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \
-  OpenPuck
+make build
 ```
 
 `OpenPuck/git_version.h` is generated by `gen_version.sh` and gitignored —

+ 1 - 1
CODE_MAP.md

@@ -2,7 +2,7 @@
 
 nRF52840 / Adafruit Arduino core / TinyUSB. The device impersonates a Valve Steam
 Controller 2 "puck" over USB and talks to SC2 controllers over a bare-metal nRF52
-RADIO (ESB-style, **no SoftDevice**) protocol. Built with `-DCFG_TUD_HID=4`.
+RADIO (ESB-style, **no SoftDevice**) protocol. Built with `-DCFG_TUD_HID=6`.
 
 > This map describes what the **code actually does**. Source comments in this repo
 > are known to be misleading and were ignored.

+ 11 - 5
Makefile

@@ -30,6 +30,10 @@ FORMAT_FILES := $(shell find OpenPuck ReversePuckFirmware puck_sniffer pairtui \
 # or add your own defines:     make build EXTRA_FLAGS="-DOPK_LOG=1"
 FQBN ?= adafruit:nrf52:feather52840
 CFG_TUD_HID ?= 6
+# Optional output paths; when set, --clean is implied and build artifacts land in OUTPUT_DIR.
+# Used by CI: make build BUILD_PATH=build/cache/openpuck OUTPUT_DIR=build/openpuck
+BUILD_PATH ?=
+OUTPUT_DIR ?=
 # Deep so a loop()-context sendReport never blocks on a full usbd event queue (the watchdog path). Sends run
 # from loop() now (usbTxPump) for stable RF timing, so this depth is what keeps that block from happening.
 CFG_TUD_TASK_QUEUE_SZ ?= 512
@@ -39,6 +43,8 @@ CFG_TUD_VENDOR_TX_BUFSIZE ?= 256
 EXTRA_FLAGS ?=
 # {build.flags.usb} is expanded by arduino-cli (VID/PID/strings); pass it through verbatim.
 USB_EXTRA_FLAGS = -DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=$(CFG_TUD_HID) -DCFG_TUD_TASK_QUEUE_SZ=$(CFG_TUD_TASK_QUEUE_SZ) -DCFG_TUD_VENDOR_TX_BUFSIZE=$(CFG_TUD_VENDOR_TX_BUFSIZE) $(EXTRA_FLAGS)
+# When BUILD_PATH is set, --clean + path flags are injected; omitted for fast incremental dev builds.
+_PATH_FLAGS = $(if $(BUILD_PATH),--clean --build-path $(BUILD_PATH) --output-dir $(OUTPUT_DIR))
 
 # `flash`/`deploy` take the serial port as a REQUIRED POSITIONAL arg: `make flash /dev/cu.usbmodem1101`.
 # (No auto-detect -- uploading to a guessed serial port risks writing to the wrong device. List with
@@ -58,15 +64,15 @@ RP_UPLOAD = arduino-cli upload -b $(FQBN) -p "$(FLASH_PORT)" ReversePuckFirmware
 ## Compile the firmware with the required USB flags baked in. Override CFG_TUD_HID / CFG_TUD_TASK_QUEUE_SZ /
 ## EXTRA_FLAGS / FQBN as make variables if needed.
 build:
-	arduino-cli compile -b $(FQBN) --build-property "build.extra_flags=$(USB_EXTRA_FLAGS)" OpenPuck
+	arduino-cli compile -b $(FQBN) $(_PATH_FLAGS) --build-property "build.extra_flags=$(USB_EXTRA_FLAGS)" OpenPuck
 
 ## One-time factory-reset recovery image (wipes persistent storage once on first boot). See §6 of the build doc.
 build-recovery:
-	$(MAKE) build EXTRA_FLAGS="$(EXTRA_FLAGS) -DOPK_FACTORY_RESET=1"
+	$(MAKE) build BUILD_PATH=$(BUILD_PATH) OUTPUT_DIR=$(OUTPUT_DIR) EXTRA_FLAGS="$(EXTRA_FLAGS) -DOPK_FACTORY_RESET=1"
 
 ## Compile the ReversePuck controller dongle firmware (28DE:1302) with its WebUSB vendor flags baked in.
 reversepuck:
-	arduino-cli compile -b $(FQBN) --build-property "build.extra_flags=$(RP_USB_FLAGS)" ReversePuckFirmware
+	arduino-cli compile -b $(FQBN) $(_PATH_FLAGS) --build-property "build.extra_flags=$(RP_USB_FLAGS)" ReversePuckFirmware
 
 ## Upload the most recent ReversePuck build. Usage: make reversepuck-flash <port>
 reversepuck-flash:
@@ -76,7 +82,7 @@ reversepuck-flash:
 ## Build then upload the ReversePuck dongle in one step. Usage: make reversepuck-deploy <port>
 reversepuck-deploy:
 	@[ -n "$(FLASH_PORT)" ] || { echo "usage: make reversepuck-deploy <port>   e.g. make reversepuck-deploy /dev/cu.usbmodem1101"; exit 1; }
-	$(MAKE) reversepuck
+	$(MAKE) reversepuck BUILD_PATH=$(BUILD_PATH) OUTPUT_DIR=$(OUTPUT_DIR)
 	$(RP_UPLOAD)
 
 ## Upload the most recent build. Usage: make flash <port>   e.g.  make flash /dev/cu.usbmodem1101
@@ -89,7 +95,7 @@ flash:
 ## Build then upload in one step. Usage: make deploy <port>   (same build overrides as `build`).
 deploy:
 	@[ -n "$(FLASH_PORT)" ] || { echo "usage: make deploy <port>   e.g. make deploy /dev/cu.usbmodem1101"; exit 1; }
-	$(MAKE) build
+	$(MAKE) build BUILD_PATH=$(BUILD_PATH) OUTPUT_DIR=$(OUTPUT_DIR)
 	$(UPLOAD)
 
 # Swallow the positional <port> arg so make doesn't error trying to build it as a target. Scoped to things

+ 3 - 3
docs/BUILD_AND_DEPLOY.md

@@ -54,8 +54,8 @@ make build
 
 That's the whole command — the USB flags the firmware needs are baked in, so you don't pass them yourself:
 
-- `CFG_TUD_HID=4` — Steam mode exposes four HID interfaces (the Adafruit nRF core defaults to 2).
-- `CFG_TUD_TASK_QUEUE_SZ=64` — a deeper TinyUSB device event queue; the default of 16 can deadlock the firmware's loop under heavy USB traffic and trip the watchdog.
+- `CFG_TUD_HID=6` — Steam mode exposes four HID interfaces (the Adafruit nRF core defaults to 2); one extra for mouse and one for WebUSB brings the total to 6.
+- `CFG_TUD_TASK_QUEUE_SZ=512` — a deeper TinyUSB device event queue; the default of 16 can deadlock the firmware's loop under heavy USB traffic and trip the watchdog.
 - `CFG_TUD_VENDOR_TX_BUFSIZE=256` — the WebUSB status blob (~118 B) must fit the vendor TX FIFO in one write; the default 64 is too small and the panel (which drops frames rather than block the loop) would send nothing — a blank dashboard.
 
 **Overriding the defaults** (only if you need to) — pass them as `make` variables:
@@ -70,7 +70,7 @@ make build FQBN=adafruit:nrf52:somethingelse          # a different nRF52840 boa
 `#error`s without them (so a forgotten flag fails loudly instead of shipping a broken/deadlock-prone image):
 
 ```bash
-arduino-cli compile -b adafruit:nrf52:feather52840 --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DCFG_TUD_TASK_QUEUE_SZ=64 -DCFG_TUD_VENDOR_TX_BUFSIZE=256" OpenPuck
+arduino-cli compile -b adafruit:nrf52:feather52840 --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=6 -DCFG_TUD_TASK_QUEUE_SZ=512 -DCFG_TUD_VENDOR_TX_BUFSIZE=256" OpenPuck
 ```
 
 ## 5. Upload the firmware