wake_hid.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "wake_hid.h"
  2. #include "usb_tx.h"
  3. #include <Adafruit_TinyUSB.h>
  4. // Boot MOUSE descriptor -- proven to enumerate and wake Windows. The host enumerates a "HID-compliant mouse"
  5. // child and arms IT as the wake source, so the wake nudge (wakeHidMove, driven from the puck wake path) must
  6. // ride THIS interface -- a report on the gamepad slot lands on an interface the host never allow-listed. (A boot
  7. // keyboard didn't enumerate on Windows and suppressed the wake the mouse class provides.)
  8. static const uint8_t WAKE_HID_DESC[] = { TUD_HID_REPORT_DESC_MOUSE() };
  9. static Adafruit_USBD_HID g_wakeHid;
  10. static bool g_wakeHidPresent = false;
  11. void wakeHidBegin()
  12. {
  13. // boot mouse = a wake device class honored by Windows + Linux
  14. g_wakeHid.setBootProtocol(HID_ITF_PROTOCOL_MOUSE);
  15. g_wakeHid.setStringDescriptor("OpenPuck Wake");
  16. g_wakeHid.setReportDescriptor(WAKE_HID_DESC, sizeof WAKE_HID_DESC);
  17. g_wakeHid.setPollInterval(10);
  18. g_wakeHid.begin();
  19. g_wakeHidPresent = true;
  20. }
  21. bool wakeHidPresent()
  22. {
  23. return g_wakeHidPresent;
  24. }
  25. bool wakeHidReady()
  26. {
  27. return g_wakeHidPresent && g_wakeHid.ready();
  28. }
  29. bool wakeHidMove(int8_t dx, int8_t dy)
  30. {
  31. if (!wakeHidReady())
  32. return false;
  33. // boot mouse descriptor has no report ID -> report_id 0; buttons=0 so we move but never click. Queued for
  34. // the usbd task (usbTxHid) rather than sent inline, like every other report -- loop() issues no tud_* call.
  35. hid_mouse_report_t m;
  36. m.buttons = 0;
  37. m.x = dx;
  38. m.y = dy;
  39. m.wheel = 0;
  40. m.pan = 0;
  41. usbTxHid(&g_wakeHid, 0, &m, sizeof m);
  42. return true;
  43. }
  44. void wakeHidAddInterface()
  45. {
  46. TinyUSBDevice.addInterface(g_wakeHid);
  47. }