usb_vendor_desc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "include.h"
  2. #include "usb_desc.h"
  3. #if USB_VENDOR_EN
  4. AT(.rodata.usb.desc)
  5. const uint8_t desc_itf_vendor[] = {
  6. //Interface Descriptor:
  7. 9, /* Num bytes of this descriptor */
  8. INTERFACE_DESCRIPTOR, /* Interface descriptor type */
  9. USB_VENDOR_ITF_INDEX, /* Interface Number*/
  10. 0, /* Alternate interface number */
  11. 2, /* Num endpoints of this interface */
  12. 0x03, /* Interface Sub Class: Human Interface Device */
  13. 0, /* Interface Sub Class: */
  14. 0, /* Class specific protocol: */
  15. 0, /* Index of Interface string descriptor */
  16. //HID Descriptor:
  17. 9, /* Num bytes of this descriptor */
  18. HID_DESCRIPTOR, /* HID Type */
  19. 0x11, 0x01, /* HID Class Specification compliance */
  20. 0x00, /* Country Code: none */
  21. 0x01, /* Number of descriptors to follow */
  22. HID_REPORT_DESCRIPTOR, /* Report descriptor type */
  23. BYTE0(VENDOR_REPORT_DESC_SIZE), /* Len of Report descriptor ,sizeof(desc_vendor_report) */
  24. BYTE1(VENDOR_REPORT_DESC_SIZE),
  25. //Endpoint Descriptor: (OUT)
  26. 0x07, /* Num bytes of this descriptor */
  27. ENDPOINT_DESCRIPTOR, /* Endpoint descriptor type */
  28. USB_VENDOR_EP_OUT_INDEX, /* Endpoint address: */
  29. EP_TYPE_INTR, /* Endpoint type: */
  30. BYTE0(VENDOR_EP_OUT_MAX_SIZE), /* Maximum packet size */
  31. BYTE1(VENDOR_EP_OUT_MAX_SIZE),
  32. 0x01, /* Poll */
  33. //Endpoint Descriptor: (IN)
  34. 0x07, /* Num bytes of this descriptor */
  35. ENDPOINT_DESCRIPTOR, /* Endpoint descriptor type */
  36. USB_VENDOR_EP_IN_INDEX | 0x80, /* Endpoint address: */
  37. EP_TYPE_INTR, /* Endpoint type: */
  38. BYTE0(VENDOR_EP_IN_MAX_SIZE), /* Maximum packet size */
  39. BYTE1(VENDOR_EP_IN_MAX_SIZE),
  40. 0x01, /* Poll */
  41. };
  42. //HID report
  43. AT(.rodata.usb.desc)
  44. const u8 desc_vendor_report[] = {
  45. 0x06, 0xAB, 0xFF, /* Usage Page (Vendor Defined) */
  46. 0x09, 0x00, /* Usage (Undefined) */
  47. 0xA1, 0x01, /* Collection */
  48. 0x85, USB_VENDOR_REPORT_ID_APP, /* Report ID (...) */
  49. 0x15, 0x00, /* Logical Minimum (0) */
  50. 0x25, 0xFF, /* Logical Maximum (255) */
  51. 0x19, 0x00, /* Usage Minimum (0) */
  52. 0x29, 0xFF, /* Usage Maximum (255) */
  53. 0x95, (VENDOR_EP_IN_MAX_SIZE-1), /* Report Count (64) */
  54. 0x75, 0x08, /* Report Size (8) */
  55. 0x81, 0x02, /* Input (Data, Variable, Absolute) */
  56. 0x19, 0x00, /* Usage Minimum (0) */
  57. 0x29, 0xFF, /* Usage Maximum (255) */
  58. 0x95, (VENDOR_EP_OUT_MAX_SIZE-1), /* Report Count (64) */
  59. 0x75, 0x08, /* Report Size (8) */
  60. 0x91, 0x02, /* Output (Data, Variable, Absolute) */
  61. 0xC0, /* End Collection */
  62. };
  63. /* Return the desc to the lib by rewriting this func */
  64. uint8_t *usb_vendor_itf_desc_get(uint8_t *length)
  65. {
  66. if (VENDOR_REPORT_DESC_SIZE != sizeof(desc_vendor_report)){
  67. printf("--->desc_hid_report_size_err: %d,%d\n", VENDOR_REPORT_DESC_SIZE, sizeof(desc_vendor_report));
  68. while(1);
  69. }
  70. *length = sizeof(desc_itf_vendor);
  71. return (u8 *)desc_itf_vendor;
  72. }
  73. uint8_t *usb_vendor_report_desc_get(uint8_t *length)
  74. {
  75. *length = sizeof(desc_vendor_report);
  76. return (u8 *)desc_vendor_report;
  77. }
  78. AT(.com_text.usb.vendor.desc)
  79. uint32_t usb_vendor_fmt_size_get(uint8_t report_id)
  80. {
  81. if (report_id == USB_VENDOR_REPORT_ID_APP) {
  82. return 64;
  83. }
  84. return 0;
  85. }
  86. #endif