hid_defines.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * @File name :
  3. * @Author : Bluetrum IOT Team K.
  4. * @Date : 2024-07-25
  5. * @Description :
  6. *
  7. * Copyright (c) by Bluetrum, All Rights Reserved.
  8. */
  9. #ifndef _HID_DEFINES_H
  10. #define _HID_DEFINES_H
  11. #define HID_REP_MAP_CONSUMER_SWAP(...) \
  12. 0x05, 0x0C, /* Usage Page (Consumer) */ \
  13. 0x09, 0x01, /* Usage (Consumer Control) */ \
  14. /* 0xA1, 0x01, */ /* Collection (Application) */ \
  15. __VA_ARGS__, /* Report ID (...) */ \
  16. 0x1A, 0x00, 0x00, /* Usage Minimum (Unassigned) */ \
  17. 0x2A, 0x9C, 0x02, /* Usage Maximum (AC Distribute Vertically) */ \
  18. 0x16, 0x00, 0x00, /* Logical minimum (0) */ \
  19. 0x26, 0x9C, 0x02, /* Logical maximum (668) */ \
  20. 0x75, 0x10, /* Report Size (16) */ \
  21. 0x95, 0x01, /* Report Count (1) */ \
  22. 0x81, 0x00, /* Input (Data,Array,Absolute,Bit Field) */ \
  23. 0x75, 0x08, /* REPORT_SIZE (8) */ \
  24. 0x95, 0x02, /* REPORT_COUNT (2) */ \
  25. 0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */ \
  26. 0xC0 /* End Collection */ \
  27. #define HID_REP_MAP_KEYBOARD_SWAP(...) \
  28. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
  29. 0x09, 0x06, /* USAGE (Keyboard) */ \
  30. /* 0xA1, 0x01, */ /* COLLECTION (Application) */ \
  31. __VA_ARGS__, /* Report ID (...) */ \
  32. 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \
  33. 0x19, 0xE0, /* USAGE_MINIMUM (Keyboard LeftControl) */ \
  34. 0x29, 0xE7, /* USAGE_MAXIMUM (Keyboard Right GUI) */ \
  35. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
  36. 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
  37. 0x75, 0x01, /* REPORT_SIZE (1) */ \
  38. 0x95, 0x08, /* REPORT_COUNT (8) */ \
  39. 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
  40. 0x95, 0x03, /* REPORT_COUNT (3) */ \
  41. 0x75, 0x08, /* REPORT_SIZE (8) */ \
  42. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
  43. 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */ \
  44. 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \
  45. 0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */ \
  46. 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */ \
  47. 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ \
  48. 0x95, 0x05, /* REPORT_COUNT (5) */ \
  49. 0x75, 0x01, /* REPORT_SIZE (1) */ \
  50. 0x05, 0x08, /* USAGE_PAGE (LEDs) */ \
  51. 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */ \
  52. 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */ \
  53. 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ \
  54. 0x95, 0x01, /* REPORT_COUNT (1) */ \
  55. 0x75, 0x03, /* REPORT_SIZE (3) */ \
  56. 0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */ \
  57. 0xC0 /* END_COLLECTION */
  58. #define HID_REP_MAP_MOUSE_SWAP(...) \
  59. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
  60. 0x09, 0x02, /* USAGE (Mouse) */ \
  61. /* 0xa1, 0x01, */ /* COLLECTION (Application) */ \
  62. __VA_ARGS__, /* Report ID (...) */ \
  63. 0x09, 0x01, /* USAGE (Pointer) */ \
  64. 0xa1, 0x00, /* COLLECTION (Physical) */ \
  65. 0x05, 0x09, /* USAGE_PAGE (Button) */ \
  66. 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \
  67. 0x29, 0x05, /* USAGE_MAXIMUM (Button 5) */ \
  68. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
  69. 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
  70. 0x75, 0x01, /* REPORT_SIZE (1) */ \
  71. 0x95, 0x05, /* REPORT_COUNT (5) */ \
  72. 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
  73. 0x75, 0x03, /* REPORT_SIZE (3) */ \
  74. 0x95, 0x01, /* REPORT_COUNT (1) */ \
  75. 0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */ \
  76. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
  77. 0x09, 0x38, /* USAGE (Wheel) */ \
  78. 0x09, 0x30, /* USAGE (X) */ \
  79. 0x09, 0x31, /* USAGE (Y) */ \
  80. 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ \
  81. 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ \
  82. 0x75, 0x08, /* REPORT_SIZE (8) */ \
  83. 0x95, 0x03, /* REPORT_COUNT (3) */ \
  84. 0x81, 0x06, /* INPUT (Data,Var,Rel) */ \
  85. 0xc0, /* END_COLLECTION */ \
  86. 0xc0 /* END_COLLECTION */
  87. #define HID_REP_MAP_CONSUMER_NO_ID() HID_REP_MAP_CONSUMER_SWAP(0xa1, 0x01)
  88. #define HID_REP_MAP_CONSUMER(id) HID_REP_MAP_CONSUMER_SWAP(0xa1, 0x01, 0x85, id)
  89. #define HID_REP_MAP_KEYBOARD_NO_ID() HID_REP_MAP_KEYBOARD_SWAP(0xa1, 0x01)
  90. #define HID_REP_MAP_KEYBOARD(id) HID_REP_MAP_KEYBOARD_SWAP(0xa1, 0x01, 0x85, id)
  91. #define HID_REP_MAP_MOUSE_NO_ID() HID_REP_MAP_MOUSE_SWAP(0xa1, 0x01)
  92. #define HID_REP_MAP_MOUSE(id) HID_REP_MAP_MOUSE_SWAP(0xa1, 0x01, 0x85, id)
  93. /**
  94. * @brief Determine by Peer/Local USB HID Report Map
  95. */
  96. #define HID_REP_ID_CONSUMER 1
  97. #define HID_REP_ID_KEYBOARD 2
  98. #define HID_REP_ID_LED 2
  99. #define HID_REP_ID_MOUSE 3
  100. typedef struct PACKED {
  101. union {
  102. struct {
  103. uint8_t btn_left : 1;
  104. uint8_t btn_right : 1;
  105. uint8_t btn_central : 1;
  106. uint8_t btn_4 : 1;
  107. uint8_t btn_5 : 1;
  108. uint8_t reserved : 3;
  109. };
  110. uint8_t button;
  111. };
  112. int8_t wheel;
  113. int8_t x;
  114. int8_t y;
  115. } hid_rep_mouse_t;
  116. typedef struct PACKED {
  117. uint16_t code;
  118. uint8_t reserved[2];
  119. } hid_rep_consumer_t;
  120. typedef struct PACKED {
  121. union {
  122. struct {
  123. uint8_t left_ctrl : 1;
  124. uint8_t left_shift : 1;
  125. uint8_t left_alt : 1;
  126. uint8_t left_gui : 1;
  127. uint8_t rigth_ctrl : 1;
  128. uint8_t rigth_shift : 1;
  129. uint8_t rigth_alt : 1;
  130. uint8_t rigth_gui : 1;
  131. };
  132. uint8_t modify;
  133. };
  134. uint8_t key[3];
  135. } hid_rep_keyboard_t;
  136. typedef struct PACKED {
  137. union {
  138. struct {
  139. uint8_t num_lock : 1;
  140. uint8_t caps_lock : 1;
  141. uint8_t scroll_lock : 1;
  142. uint8_t compose : 1;
  143. uint8_t kana : 1;
  144. uint8_t reserved : 3;
  145. };
  146. uint8_t led;
  147. };
  148. } hid_rep_led_t;
  149. typedef struct PACKED {
  150. uint8_t report_id;
  151. union {
  152. /* all elt length is same */
  153. hid_rep_mouse_t mouse;
  154. hid_rep_consumer_t consumer;
  155. hid_rep_keyboard_t keyboard;
  156. hid_rep_led_t led;
  157. } pdu;
  158. } hid_rep_info_t;
  159. #endif // _HID_DEFINES_H