usb_descriptors.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: BSD-3-Clause
  2. // Copyright (c) 2022, Alex Taradov <alex@taradov.com>. All rights reserved.
  3. #ifndef _USB_DESCRIPTORS_H_
  4. #define _USB_DESCRIPTORS_H_
  5. /*- Includes ----------------------------------------------------------------*/
  6. #include "usb_std.h"
  7. #include "usb_cdc.h"
  8. #include "usb_hid.h"
  9. #include "usb_winusb.h"
  10. #include "hal_config.h"
  11. /*- Definitions -------------------------------------------------------------*/
  12. #define USB_ENABLE_BOS
  13. #define USB_BCD_VERSION 0x0210
  14. #define USB_DAP_EP_SIZE 512
  15. #define USB_VCP_DATA_EP_SIZE 512
  16. #define USB_VCP_COMM_EP_SIZE 64
  17. enum
  18. {
  19. USB_STR_ZERO,
  20. USB_STR_MANUFACTURER,
  21. USB_STR_PRODUCT,
  22. USB_STR_SERIAL_NUMBER,
  23. USB_STR_CMSIS_DAP_V1,
  24. USB_STR_CMSIS_DAP_V2,
  25. #ifdef HAL_CONFIG_ENABLE_VCP
  26. USB_STR_COM_PORT,
  27. #endif
  28. USB_STR_COUNT,
  29. };
  30. enum
  31. {
  32. USB_HID_EP_SEND = 1,
  33. USB_HID_EP_RECV = 2,
  34. USB_BULK_EP_RECV = 3,
  35. USB_BULK_EP_SEND = 4,
  36. USB_CDC_EP_COMM = 5,
  37. USB_CDC_EP_SEND = 6,
  38. USB_CDC_EP_RECV = 7,
  39. };
  40. enum
  41. {
  42. USB_INTF_HID,
  43. USB_INTF_BULK,
  44. #ifdef HAL_CONFIG_ENABLE_VCP
  45. USB_INTF_CDC_COMM,
  46. USB_INTF_CDC_DATA,
  47. #endif
  48. USB_INTF_COUNT,
  49. };
  50. /*- Types -------------------------------------------------------------------*/
  51. typedef struct USB_PACK
  52. {
  53. usb_configuration_descriptor_t configuration;
  54. usb_interface_descriptor_t hid_interface;
  55. usb_hid_descriptor_t hid;
  56. usb_endpoint_descriptor_t hid_ep_in;
  57. usb_endpoint_descriptor_t hid_ep_out;
  58. usb_interface_descriptor_t bulk_interface;
  59. usb_endpoint_descriptor_t bulk_ep_out;
  60. usb_endpoint_descriptor_t bulk_ep_in;
  61. #ifdef HAL_CONFIG_ENABLE_VCP
  62. usb_interface_association_descriptor_t iad;
  63. usb_interface_descriptor_t interface_comm;
  64. usb_cdc_header_functional_descriptor_t cdc_header;
  65. usb_cdc_abstract_control_managment_descriptor_t cdc_acm;
  66. usb_cdc_call_managment_functional_descriptor_t cdc_call_mgmt;
  67. usb_cdc_union_functional_descriptor_t cdc_union;
  68. usb_endpoint_descriptor_t ep_comm;
  69. usb_interface_descriptor_t interface_data;
  70. usb_endpoint_descriptor_t ep_in;
  71. usb_endpoint_descriptor_t ep_out;
  72. #endif
  73. } usb_configuration_hierarchy_t;
  74. typedef struct USB_PACK
  75. {
  76. usb_binary_object_store_descriptor_t bos;
  77. usb_winusb_capability_descriptor_t winusb;
  78. } usb_bos_hierarchy_t;
  79. typedef struct USB_PACK
  80. {
  81. usb_winusb_subset_header_function_t header;
  82. usb_winusb_feature_compatble_id_t comp_id;
  83. usb_winusb_feature_reg_property_guids_t property;
  84. } usb_msos_descriptor_subset_t;
  85. typedef struct USB_PACK
  86. {
  87. usb_winusb_set_header_descriptor_t header;
  88. usb_msos_descriptor_subset_t subset;
  89. } usb_msos_descriptor_set_t;
  90. //-----------------------------------------------------------------------------
  91. extern const usb_device_descriptor_t usb_device_descriptor;
  92. extern const usb_configuration_hierarchy_t usb_configuration_hierarchy;
  93. extern const usb_bos_hierarchy_t usb_bos_hierarchy;
  94. extern const usb_msos_descriptor_set_t usb_msos_descriptor_set;
  95. extern const uint8_t usb_hid_report_descriptor[30];
  96. extern const usb_string_descriptor_zero_t usb_string_descriptor_zero;
  97. extern const char *usb_strings[];
  98. #ifdef HAL_CONFIG_ENABLE_VCP
  99. extern const usb_class_handler_t usb_class_handlers[3];
  100. #else
  101. extern const usb_class_handler_t usb_class_handlers[2];
  102. #endif
  103. extern char usb_serial_number[16];
  104. #endif // _USB_DESCRIPTORS_H_