config.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // config.h -- USB-presentation modes + persisted, runtime-tunable settings.
  2. //
  3. // One puck speaks the SAME RF protocol no matter which USB face it wears; only the USB enumeration and the
  4. // input-report mapping change. The active face is g_usbMode, persisted to flash (cfg.bin). Tunables here
  5. // (mouse sensitivity, back-paddle mapping, A/B swap, chord assignments, QoS) are set over the CDC console
  6. // (serial_console.cpp) and the WebUSB panel (webusb_config.cpp) and likewise persist.
  7. #pragma once
  8. #include <stdint.h>
  9. // ---- USB presentation modes (g_usbMode). RF poll/relay is identical across all; only USB enumeration +
  10. // report mapping differ. ----
  11. #define MODE_STEAM 0 // Valve puck; auto-lizard when Steam closed
  12. #define MODE_XBOX 1 // XInput + right-pad mouse
  13. #define MODE_SW_HORI 2 // HORIPAD (Switch console whitelist)
  14. #define MODE_LIZARD 3 // Puck HID; always keyboard+mouse (ignores Steam heartbeat)
  15. #define MODE_SW_PRO 4 // Nintendo Switch Pro Controller (057E:2009) + gyro
  16. #define MODE_PS5 5 // Sony DualSense (054C:0CE6) + gyro + split trackpad
  17. #define MODE_HIDGYRO 6 // DS4-layout generic HID gamepad + gyro (Fortnite-friendly)
  18. #define MODE_MAX 6
  19. static inline bool modeIsPuck(uint8_t m){ return m==MODE_STEAM || m==MODE_LIZARD; }
  20. static inline bool modeValid(uint8_t m){ return m<=MODE_MAX; }
  21. extern uint8_t g_usbMode; // loaded from flash at boot
  22. extern bool g_xbox; // true for all non-puck presentations (cached !modeIsPuck(g_usbMode))
  23. extern uint8_t g_chordBtn[3]; // back4+B/X/Y -> these modes (A always STEAM)
  24. // Mode persistence policy: by DEFAULT every fresh power-on/reconnect lands in STEAM mode (0). An explicit
  25. // mode switch still works for the session via a ONE-SHOT bootMode (honored once, then cleared, so the next
  26. // cold boot reverts to Steam). The WebUI "persist last mode" toggle (g_persistMode) instead remembers the
  27. // last selected mode across reboots.
  28. extern bool g_persistMode; // false (default) = always boot Steam; true = boot into last mode
  29. extern uint8_t g_bootMode; // one-shot: boot into this mode once then clear (!persistMode + explicit switch)
  30. // One-shot debug CDC. Puck mode normally DROPS the CDC serial console to free the USB endpoint its wake-mouse
  31. // interface needs (so puck can wake a sleeping Windows host). Arming this keeps CDC for the NEXT boot only --
  32. // dropping the wake mouse that boot -- so someone can attach the serial debugger; the boot after reverts to
  33. // normal automatically. Mirrors the g_bootMode one-shot. Armed from the WebUSB panel or CDC 'D' command.
  34. extern bool g_debugCdcThisBoot; // decision for THIS boot: true => keep CDC, skip the wake interface
  35. void armDebugCdcNextBoot(); // persist the one-shot (caller reboots)
  36. // persisted, runtime-tunable config:
  37. extern int g_mDiv, g_mFric; // xbox/lizard mouse sensitivity divisor / friction%
  38. extern uint8_t g_abSwap; // 1 = swap A/B and X/Y (Nintendo face-button layout)
  39. extern uint8_t g_back[4]; // back paddles L4,R4,L5,R5 -> button codes (5=LB 6=RB 7=L3 8=R3)
  40. #define POLL_US_DEFAULT 4000u // 250 Hz -- matches SC2 input report rate (1000000/250 = 4000 us)
  41. #define USB_STREAM_MS 4u // host-side HID stream cadence for translated modes (~250 Hz)
  42. extern const uint32_t g_pollUs; // RF poll cadence (us). FIXED -- not configurable (see loadCfg).
  43. void loadCfg();
  44. void saveCfg();
  45. // Mode switch (chord / WebUI): persist mode if the toggle is on, else arm a one-shot so this reboot lands in
  46. // the new mode but the next cold boot returns to Steam. Either way saveCfg + caller reboots.
  47. void saveMode(uint8_t m);