parse_hid.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #define HIDINPUT(size) (0x80 | size)
  3. #define HIDOUTPUT(size) (0x90 | size)
  4. #define FEATURE(size) (0xb0 | size)
  5. #define COLLECTION(size) (0xa0 | size)
  6. #define END_COLLECTION(size) (0xc0 | size)
  7. /* Global items */
  8. #define USAGE_PAGE(size) (0x04 | size)
  9. #define LOGICAL_MINIMUM(size) (0x14 | size)
  10. #define LOGICAL_MAXIMUM(size) (0x24 | size)
  11. #define PHYSICAL_MINIMUM(size) (0x34 | size)
  12. #define PHYSICAL_MAXIMUM(size) (0x44 | size)
  13. #define UNIT_EXPONENT(size) (0x54 | size)
  14. #define UNIT(size) (0x64 | size)
  15. #define REPORT_SIZE(size) (0x74 | size) //bits
  16. #define REPORT_ID(size) (0x84 | size)
  17. #define REPORT_COUNT(size) (0x94 | size) //bytes
  18. #define PUSH(size) (0xa4 | size)
  19. #define POP(size) (0xb4 | size)
  20. /* Local items */
  21. #define USAGE(size) (0x08 | size)
  22. #define USAGE_MINIMUM(size) (0x18 | size)
  23. #define USAGE_MAXIMUM(size) (0x28 | size)
  24. #define DESIGNATOR_INDEX(size) (0x38 | size)
  25. #define DESIGNATOR_MINIMUM(size) (0x48 | size)
  26. #define DESIGNATOR_MAXIMUM(size) (0x58 | size)
  27. #define STRING_INDEX(size) (0x78 | size)
  28. #define STRING_MINIMUM(size) (0x88 | size)
  29. #define STRING_MAXIMUM(size) (0x98 | size)
  30. #define DELIMITER(size) (0xa8 | size)
  31. #define GENERIC_DESKTOP_POINTER 0x01
  32. #define GENERIC_DESKTOP_MOUSE 0x02
  33. #define GENERIC_DESKTOP_JOYSTICK 0x04
  34. #define GENERIC_DESKTOP_GAMEPAD 0x05
  35. #define GENERIC_DESKTOP_KEYBAORD 0x06
  36. #define GENERIC_DESKTOP_KEYPAD 0x07
  37. #define GENERIC_DESKTOP_MULTIAXIS 0x08
  38. #define GENERIC_DESKTOP_BUTTON 0x09
  39. #define GENERIC_DESKTOP_X 0x30
  40. #define GENERIC_DESKTOP_Y 0x31
  41. #define GENERIC_DESKTOP_WHEEL 0x38
  42. typedef struct {
  43. struct
  44. {
  45. uint16_t bits_start;
  46. uint8_t count;
  47. uint8_t size; // bits
  48. uint16_t value; // up to 16 buttons
  49. uint8_t reserved; // number of dummy bits
  50. }buttons __attribute__((packed));
  51. struct
  52. {
  53. uint16_t bits_start;
  54. uint8_t count;
  55. uint8_t size; // bits
  56. uint8_t* value;
  57. }axis_x __attribute__((packed));
  58. struct
  59. {
  60. uint16_t bits_start;
  61. uint8_t count;
  62. uint8_t size; // bits
  63. uint8_t* value;
  64. }axis_y __attribute__((packed));
  65. struct
  66. {
  67. uint16_t bits_start;
  68. uint8_t count;
  69. uint8_t size; // bits
  70. uint8_t* value;
  71. }axes __attribute__((packed));
  72. struct
  73. {
  74. uint16_t bits_start;
  75. uint8_t count;
  76. uint8_t size; // bits
  77. uint8_t* value;
  78. }wheel __attribute__((packed));
  79. }hid_mouse_t;
  80. hid_mouse_t* get_mouse_struct();
  81. uint8_t get_buttons(uint8_t* data);
  82. int16_t get_x_axis(uint8_t* data);
  83. int16_t get_y_axis(uint8_t* data);
  84. int8_t get_wheel(uint8_t* data);