deck_input.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // deck_input.h -- the USB-CDC link to the Steam Deck forwarder app.
  2. //
  3. // The Deck app (deck/) streams the Deck's grabbed controls as INPUT frames; we decode them into g_in
  4. // (report45.cpp then encodes the RF report 0x45). We stream STATUS frames back so the app's UI can show
  5. // which bonded pucks are live. One framed binary protocol both ways; the reader resynchronizes on a
  6. // 2-byte sync word so a serial monitor's stray text is harmless. The wire format is mirrored exactly in
  7. // deck/frame.py.
  8. //
  9. // frame = [0xA5][0x5A][type][len][payload(len)][sum8(type,len,payload...)]
  10. //
  11. // Deck -> nRF: 0x01 INPUT (38B fields), 0x02 CONTROL ([sub][..]: sub 0x01=set-forwarding[0/1],
  12. // sub 0x02=clear-bond[slot]), 0x03 REQUEST_STATUS (no payload)
  13. // nRF -> Deck: 0x10 STATUS, 0x11 HAPTIC (relayed Steam rumble), 0x1F TEXT(debug)
  14. #pragma once
  15. #include <stdint.h>
  16. #define DECK_SYNC0 0xA5
  17. #define DECK_SYNC1 0x5A
  18. #define DECK_T_INPUT 0x01
  19. #define DECK_T_CONTROL 0x02
  20. #define DECK_T_REQ_STATUS 0x03
  21. #define DECK_T_STATUS 0x10
  22. #define DECK_T_HAPTIC 0x11
  23. #define DECK_T_TEXT 0x1F
  24. // Pump the CDC RX state machine: parse any complete frames, fill g_in, update forwarding state.
  25. void deckInputPoll();
  26. // Emit a STATUS frame (bond list + link state) to the Deck. Rate-limited internally; call each loop.
  27. void deckStatusTask();
  28. // Flush the newest staged haptic (from deckForwardHaptic) to the Deck. Rate-limited; call each loop.
  29. void deckHapticTask();
  30. // Send a debug text line as a 0x1F frame (skipped by the app unless it shows debug).
  31. void deckText(const char *s);
  32. // Forward a relayed Steam haptic/rumble to the Deck as a HAPTIC frame (the app plays it as Deck rumble).
  33. // rid = the relayed report id (0x80 SDL Triton rumble, 0x82/0x8F haptic pulse); d/n = its raw payload.
  34. void deckForwardHaptic(uint8_t rid, const uint8_t *d, uint8_t n);
  35. // Is the app currently forwarding (user tapped a puck)? When false, ctrl_link sends a neutral report.
  36. bool deckForwarding();
  37. // millis() of the last INPUT frame; ctrl_link sends neutral if input goes stale while forwarding.
  38. unsigned long deckLastInputMs();