usb_device.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __USB_DEVICE_H__
  22. #define __USB_DEVICE_H__
  23. #include "usb_define.h"
  24. enum
  25. {
  26. USBD_IDX_LANGID_STR = 0,
  27. USBD_IDX_MANUFACTURER_STR,
  28. USBD_IDX_PRODUCT_STR,
  29. USBD_IDX_SERIAL_STR,
  30. USBD_IDX_CONFIG_STR,
  31. USBD_IDX_INTERFACE0_STR,
  32. USBD_BUS_TYPE_SUSPEND = 0,
  33. USBD_BUS_TYPE_RESUME,
  34. USBD_BUS_TYPE_RESET,
  35. USBD_BUS_TYPE_NEW_SOF,
  36. USBD_BUS_TYPE_DISCONNECT,
  37. USBD_BUS_TYPE_ENABLE_CONNECT,
  38. USB_DEVICE_SPEED_FULL_SPEED = 0,
  39. USB_DEVICE_SPEED_HIGH_SPEED,
  40. USB_DEVICE_SPEED_SUPER_SPEED,
  41. USB_DEVICE_SPEED_QTY,
  42. };
  43. #define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
  44. #define USB_LEN_DEV_DESC 0x12U
  45. #define USB_LEN_CFG_DESC 0x09U
  46. #define USB_LEN_ASSOC_IF_DESC 0x08U
  47. #define USB_LEN_IF_DESC 0x09U
  48. #define USB_LEN_EP_DESC 0x07U
  49. #define USB_LEN_OTG_DESC 0x03U
  50. #define USB_LEN_LANGID_STR_DESC 0x04U
  51. #define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U
  52. typedef struct
  53. {
  54. usb_interface_descriptor_t *pInterfaceDesc;
  55. usb_endpoint_descriptor_t *pEndpointDesc;
  56. usb_endpoint_ss_comp_descriptor_t *pEndpointSSCompDesc;
  57. CBFuncEx_t GetOtherDesc;
  58. uint8_t EndpointNum;
  59. }usb_full_interface_t;
  60. typedef struct
  61. {
  62. usb_config_descriptor_t *pConfigDesc;
  63. usb_interface_assoc_descriptor_t *pInterfaceAssocDesc;
  64. usb_full_interface_t *pInterfaceFullDesc;
  65. uint8_t InterfaceNum;
  66. }usb_full_config_t;
  67. typedef struct
  68. {
  69. usb_device_qualifier_t *pQualifierDesc;
  70. usb_full_config_t *pFullConfig[USB_DEVICE_SPEED_QTY];
  71. }USB_FullConfigStruct;
  72. typedef struct
  73. {
  74. usb_device_descriptor_t *pDeviceDesc; //静态处理,不会释放内存
  75. USB_FullConfigStruct *pConfigInfo; //静态处理,不会释放内存
  76. USB_FullConfigStruct *pCurConfigInfo;//当前用到的配置
  77. Buffer_Struct *pString; //字符串描述, 动态处理
  78. CBFuncEx_t CB;
  79. void *pUserData;
  80. uint8_t ConfigNum; //配置总数
  81. uint8_t StringNum; //字符串描述总数
  82. uint8_t CurSpeed;
  83. }USB_SetupInfoStruct; //USB2.0设备配置信息,支持到高速设备,不能支持USB3.0的超高速设备
  84. #endif