ctrl_bonds.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. // ctrl_bonds.h -- the emulated controller's bonds to pucks.
  2. //
  3. // A real Steam Controller bonds to up to two pucks under the Zephyr settings keys `esb/bond` (slot 0)
  4. // and `esb/bond_2` (slot 1). We support MORE: an array of slots, each holding the 24-byte bond record
  5. // rec = [proteus_uuid 4 LE][ibex_uuid 4 LE][puck_serial 16]
  6. // -- the SAME 24-byte shape Steam writes to the puck via 0xA2, except the trailing serial is the
  7. // PUCK's (the peer), not the controller's. The 8-byte uuid key is identical on both sides and is what
  8. // matches the puck's E1 host frame at reconnect. Pairing a new puck find-or-allocates a free slot by
  9. // uuid (so an arbitrary number can be bonded); the Deck GUI can clear a slot. Persists to LittleFS
  10. // `/ctrlbond.bin`.
  11. #pragma once
  12. #include <stdint.h>
  13. #define NBOND 8
  14. struct CtrlBond {
  15. uint8_t rec[24]; // [proteus_uuid 4][ibex_uuid 4][puck_serial 16]
  16. bool used;
  17. // feature-report reply staging (filled in ISR, read on GET)
  18. uint8_t resp[63];
  19. uint16_t resp_len;
  20. };
  21. extern CtrlBond g_bond[NBOND];
  22. extern volatile bool g_bondDirty; // bonds changed -> flush to flash from loop()
  23. bool ctrlRecEmpty(const uint8_t *r);
  24. void loadCtrlBonds();
  25. void saveCtrlBonds();
  26. // Find a bond slot matching a puck E1 host frame's [proteus_uuid 4][ibex_uuid 4]; -1 if none.
  27. int ctrlBondMatch(const uint8_t *proteus_uuid, const uint8_t *ibex_uuid);
  28. // Slot for a 24-byte record: reuse the slot whose uuid (rec[0..8]) matches, else first free; -1 if full.
  29. int ctrlBondFindOrAlloc(const uint8_t *rec24);
  30. // Clear (un-bond) a slot and mark the store dirty. Out-of-range slots are ignored.
  31. void ctrlBondClear(int slot);