webusb_ctrl.h 2.2 KB

123456789101112131415161718192021222324252627282930
  1. // webusb_ctrl.h -- the ReversePuck dongle's WebUSB configuration channel (28DE:1302).
  2. //
  3. // Adds a vendor interface so the OpenPuck browser panel (docs/index.html) can connect to the CONTROLLER
  4. // dongle -- distinct from the puck's own panel (28DE:1304). It exposes a SUBSET of the puck's WebUSB
  5. // protocol (webusb_config.h), reusing the SAME firmware-update opcodes + 0xAB ack framing so the panel's
  6. // existing streaming flasher and DFU buttons work against the dongle unchanged. The panel branches on the
  7. // USB product id (0x1302 vs 0x1304) to show the reduced controller UI.
  8. //
  9. // Binary framed protocol:
  10. // host->dev: 0x01 GET -> reply the paired-pucks list (0xAC frame)
  11. // 0x0B reboot into serial DFU (adafruit-nrfutil)
  12. // 0x0C reboot into UF2 bootloader (USB mass storage)
  13. // 0x20 <size u32> <crc32 u32> firmware update: begin staging (disarms any previous)
  14. // 0x21 <off u32> <len> <data...> firmware update: sequential chunk (len<=128, %4==0)
  15. // 0x22 firmware update: verify staged image + COMMIT (applies on next reboot)
  16. // 0x23 clean reboot (after 0x22: boots the freshly staged firmware)
  17. // 0x24 firmware update: abort/disarm
  18. // 0x25 "WIPE" FULL BOARD WIPE (debug): erase app+bonds+bl-settings, reboot app-less
  19. // 0x30 <slot> un-bond (remove) one paired puck by firmware slot, then reply 0xAC
  20. // dev->host: 0xAC <len> <ver=1> <flags> <count> [ per bond: slot, alive, puuid4, iuuid4, serial16 (26B) ]
  21. // paired-pucks list (flags bit0=forwarding, bit1=link up)
  22. // 0xAB 5 <status> <nextOff u32> firmware-update ack, one per 0x20/0x21/0x22/0x24 (fw_update.h)
  23. // No setLandingPage() on purpose -- it would pop a Chrome "open <url>?" prompt on every plug-in.
  24. #pragma once
  25. #include <Adafruit_TinyUSB.h>
  26. extern Adafruit_USBD_WebUSB usb_web;
  27. void webusbCtrlBegin(); // add the vendor interface; call in setup() BEFORE USBDevice.attach()
  28. void webusbCtrlPoll(); // drain host commands + flush replies; call every loop()