usb_hid_desc.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "include.h"
  2. #include "usb_desc.h"
  3. #if USB_HID_EN
  4. //Config descriptor: HID
  5. AT(.usbdev.com.table)
  6. const u8 desc_config_hid[] = {
  7. //Interface Descriptor:
  8. 9, /* Num bytes of this descriptor */
  9. INTERFACE_DESCRIPTOR, /* Interface descriptor type */
  10. USB_HID_ITF_INDEX, /* Interface Number*/
  11. 0, /* Alternate interface number */
  12. 2, /* Num endpoints of this interface */
  13. 0x03, /* Interface Sub Class: Human Interface Device */
  14. 0, /* Interface Sub Class: */
  15. 0, /* Class specific protocol: */
  16. 0, /* Index of Interface string descriptor */
  17. //HID Descriptor:
  18. 9, /* Num bytes of this descriptor */
  19. HID_DESCRIPTOR, /* HID Type */
  20. 0x11, 0x01, /* HID Class Specification compliance */
  21. 0x00, /* Country Code: none */
  22. 0x01, /* Number of descriptors to follow */
  23. HID_REPORT_DESCRIPTOR, /* Report descriptor type */
  24. BYTE0(HID_REPORT_DESC_SIZE), /* Len of Report descriptor ,sizeof(desc_hid_report) */
  25. BYTE1(HID_REPORT_DESC_SIZE),
  26. //EndpointDescriptor:
  27. 7, /* Num bytes of this descriptor */
  28. ENDPOINT_DESCRIPTOR, /* Endpoint descriptor type */
  29. USB_HID_EP_OUT_INDEX, /* Endpoint address: */
  30. EP_TYPE_INTR, /* Interrupt Endpoint */
  31. BYTE0(HID_EP_OUT_MAX_SIZE), /* Maximum packet size */
  32. BYTE1(HID_EP_OUT_MAX_SIZE),
  33. 0x01, /* Poll every 1 msec seconds */
  34. //EndpointDescriptor:
  35. 7, /* Num bytes of this descriptor */
  36. ENDPOINT_DESCRIPTOR, /* Endpoint descriptor type */
  37. USB_HID_EP_IN_INDEX | 0x80, /* Endpoint address: */
  38. EP_TYPE_INTR, /* Interrupt Endpoint */
  39. BYTE0(HID_EP_IN_MAX_SIZE), /* Maximum packet size */
  40. BYTE1(HID_EP_IN_MAX_SIZE),
  41. 0x01, /* Poll every 1 msec seconds */
  42. };
  43. //HID report
  44. AT(.rodata.usb.desc)
  45. const u8 desc_hid_report[HID_REPORT_DESC_SIZE] = {
  46. HID_REP_MAP_CONSUMER(1),
  47. #if 0
  48. 0x05, 0x0C, /* Usage Page (Consumer) */
  49. 0x09, 0x01, /* Usage (Consumer Control) */
  50. 0xA1, 0x01, /* Collection (Application) */
  51. 0x85, 0x01, /* Report ID (1) */
  52. 0x1A, 0x00, 0x00, /* Usage Minimum (Unassigned) */
  53. 0x2A, 0x9C, 0x02, /* Usage Maximum (AC Distribute Vertically) */
  54. 0x16, 0x00, 0x00, /* Logical minimum (0) */
  55. 0x26, 0x9C, 0x02, /* Logical maximum (668) */
  56. 0x75, 0x10, /* Report Size (16) */
  57. 0x95, 0x01, /* Report Count (1) */
  58. 0x81, 0x00, /* Input (Data,Array,Absolute,Bit Field) */
  59. 0x75, 0x08, /* REPORT_SIZE (8) */
  60. 0x95, 0x02, /* REPORT_COUNT (2) */
  61. 0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */
  62. 0xC0, /* End Collection */
  63. #endif
  64. HID_REP_MAP_KEYBOARD(2),
  65. #if 0
  66. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  67. 0x09, 0x06, /* USAGE (Keyboard) */
  68. 0xA1, 0x01, /* COLLECTION (Application) */
  69. 0x85, 0x02, /* Report ID (2) */
  70. 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
  71. 0x19, 0xE0, /* USAGE_MINIMUM (Keyboard LeftControl) */
  72. 0x29, 0xE7, /* USAGE_MAXIMUM (Keyboard Right GUI) */
  73. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
  74. 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
  75. 0x75, 0x01, /* REPORT_SIZE (1) */
  76. 0x95, 0x08, /* REPORT_COUNT (8) */
  77. 0x81, 0x02, /* INPUT (Data,Var,Abs) */
  78. 0x95, 0x03, /* REPORT_COUNT (3) */
  79. 0x75, 0x08, /* REPORT_SIZE (8) */
  80. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
  81. 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */
  82. 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
  83. 0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */
  84. 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */
  85. 0x81, 0x00, /* INPUT (Data,Ary,Abs) */
  86. 0xC0, /* END_COLLECTION */
  87. #endif
  88. HID_REP_MAP_MOUSE(3),
  89. #if 0
  90. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  91. 0x09, 0x02, /* USAGE (Mouse) */
  92. 0xa1, 0x01, /* COLLECTION (Application) */
  93. 0x85, 0x03, /* Report ID (3) */
  94. 0x09, 0x01, /* USAGE (Pointer) */
  95. 0xa1, 0x00, /* COLLECTION (Physical) */
  96. 0x05, 0x09, /* USAGE_PAGE (Button) */
  97. 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */
  98. 0x29, 0x05, /* USAGE_MAXIMUM (Button 5) */
  99. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
  100. 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
  101. 0x75, 0x01, /* REPORT_SIZE (1) */
  102. 0x95, 0x05, /* REPORT_COUNT (5) */
  103. 0x81, 0x02, /* INPUT (Data,Var,Abs) */
  104. 0x75, 0x03, /* REPORT_SIZE (3) */
  105. 0x95, 0x01, /* REPORT_COUNT (1) */
  106. 0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */
  107. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  108. 0x09, 0x38, /* USAGE (Wheel) */
  109. 0x09, 0x30, /* USAGE (X) */
  110. 0x09, 0x31, /* USAGE (Y) */
  111. 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */
  112. 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */
  113. 0x75, 0x08, /* REPORT_SIZE (8) */
  114. 0x95, 0x03, /* REPORT_COUNT (3) */
  115. 0x81, 0x06, /* INPUT (Data,Var,Rel) */
  116. 0xc0, /* END_COLLECTION */
  117. 0xc0, /* END_COLLECTION */
  118. #endif
  119. };
  120. uint8_t *usb_hid_itf_desc_get(uint8_t *length)
  121. {
  122. if (HID_REPORT_DESC_SIZE != sizeof(desc_hid_report)){
  123. printf("--->desc_hid_report_size_err: %d,%d\n", HID_REPORT_DESC_SIZE, sizeof(desc_hid_report));
  124. while(1);
  125. }
  126. *length = sizeof(desc_config_hid);
  127. return (u8 *)desc_config_hid;
  128. }
  129. uint8_t *usb_hid_report_desc_get(uint8_t *length)
  130. {
  131. *length = sizeof(desc_hid_report);
  132. return (u8 *)desc_hid_report;
  133. }
  134. #endif