SWM341_usb.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #ifndef __SWM341_USB_H__
  2. #define __SWM341_USB_H__
  3. #include <stdint.h>
  4. typedef struct {
  5. uint8_t bRequestType;
  6. uint8_t bRequest;
  7. uint16_t wValue;
  8. uint16_t wIndex;
  9. uint16_t wLength;
  10. } USB_Setup_Packet_t;
  11. /* bRequestType D7 Data Phase Transfer Direction */
  12. #define USB_REQ_DIR_MASK 0x80
  13. #define USB_REQ_H2D 0x00
  14. #define USB_REQ_D2H 0x80
  15. /* bRequestType D6..5 Type */
  16. #define USB_REQ_STANDARD 0x00
  17. #define USB_REQ_CLASS 0x20
  18. #define USB_REQ_VENDOR 0x40
  19. /* bRequestType D4..0 Recipient */
  20. #define USB_REQ_TO_DEVICE 0x00
  21. #define USB_REQ_TO_INTERFACE 0x01
  22. #define USB_REQ_TO_ENDPOINT 0x02
  23. /* USB Standard Request */
  24. #define USB_GET_STATUS 0x00
  25. #define USB_CLEAR_FEATURE 0x01
  26. #define USB_SET_FEATURE 0x03
  27. #define USB_SET_ADDRESS 0x05
  28. #define USB_GET_DESCRIPTOR 0x06
  29. #define USB_SET_DESCRIPTOR 0x07
  30. #define USB_GET_CONFIGURATION 0x08
  31. #define USB_SET_CONFIGURATION 0x09
  32. #define USB_GET_INTERFACE 0x0A
  33. #define USB_SET_INTERFACE 0x0B
  34. #define USB_SYNC_FRAME 0x0C
  35. /* USB Descriptor Type */
  36. #define USB_DESC_DEVICE 0x01
  37. #define USB_DESC_CONFIG 0x02
  38. #define USB_DESC_STRING 0x03
  39. #define USB_DESC_INTERFACE 0x04
  40. #define USB_DESC_ENDPOINT 0x05
  41. #define USB_DESC_QUALIFIER 0x06
  42. #define USB_DESC_OTHERSPEED 0x07
  43. #define USB_DESC_IFPOWER 0x08
  44. #define USB_DESC_OTG 0x09
  45. #define USB_DESC_BOS 0x0F
  46. #define USB_DESC_CAPABILITY 0x10
  47. #define USB_DESC_CS_INTERFACE 0x24 // Class Specific Interface
  48. /* USB HID Descriptor Type */
  49. #define USB_DESC_HID 0x21
  50. #define USB_DESC_HID_RPT 0x22
  51. /* USB Endpoint Type */
  52. #define USB_EP_CTRL 0x00
  53. #define USB_EP_ISO 0x01
  54. #define USB_EP_BULK 0x02
  55. #define USB_EP_INT 0x03
  56. #define USB_EP_IN 0x80
  57. #define USB_EP_OUT 0x00
  58. /* USB Feature Selector */
  59. #define USB_FEATURE_REMOTE_WAKEUP 0x01
  60. #define USB_FEATURE_ENDPOINT_HALT 0x00
  61. /* USB HID Class Report Type */
  62. #define HID_RPT_TYPE_INPUT 0x01
  63. #define HID_RPT_TYPE_OUTPUT 0x02
  64. #define HID_RPT_TYPE_FEATURE 0x03
  65. /* Define HID Class Specific Request */
  66. #define USB_HID_GET_REPORT 0x01
  67. #define USB_HID_GET_IDLE 0x02
  68. #define USB_HID_GET_PROTOCOL 0x03
  69. #define USB_HID_SET_REPORT 0x09
  70. #define USB_HID_SET_IDLE 0x0A
  71. #define USB_HID_SET_PROTOCOL 0x0B
  72. /* Class */
  73. #define USB_CDC_CLASS 0x02 // for Device
  74. #define USB_CDC_CTRL_CLASS 0x02 // for Interface
  75. #define USB_CDC_DATA_CLASS 0x0A // for Interface
  76. #define USB_HID_CLASS 0x03 // for Interface
  77. #define USB_MTP_CLASS 0x06 // for Interface
  78. #define USB_MSC_CLASS 0x08 // for Interface
  79. #define USB_UVC_CLASS 0x0E // for Interface
  80. /* SubClass */
  81. #define USB_CDC_ACM 0x02 // Abstract Control Model
  82. #define USB_HID_BOOT 0x01
  83. #define USB_UVC_VIDEOCONTROL 0x01
  84. #define USB_UVC_VIDEOSTREAMING 0x02
  85. #define USB_UVC_VIDEO_INTERFACE_COLLECTION 0x03
  86. /* Protocol */
  87. #define USB_CDC_ATCMD 0x01 // AT Commands defined by ITU-T V.250
  88. #define USB_HID_NONE 0x00
  89. #define USB_HID_KEYBD 0x01
  90. #define USB_HID_MOUSE 0x02
  91. #define USB_MSC_BOT 0x50 // Bulk-Only Transport
  92. typedef struct {
  93. uint8_t bLength;
  94. uint8_t bDescriptorType;
  95. } USB_DescHeader_t;
  96. typedef struct __attribute__((packed)) {
  97. uint8_t bLength;
  98. uint8_t bDescriptorType;
  99. uint16_t bcdUSB; // USB Specification Number which device complies to
  100. uint8_t bDeviceClass; // 0x00: each interface specifies its own class code
  101. uint8_t bDeviceSubClass;
  102. uint8_t bDeviceProtocol;
  103. uint8_t bMaxPacketSize;
  104. uint16_t idVendor; // Vendor ID (Assigned by USB Org)
  105. uint16_t idProduct; // Product ID (Assigned by Manufacturer)
  106. uint16_t bcdDevice; // Device Release Number
  107. uint8_t iManufacturer; // Index of Manufacturer String Descriptor
  108. uint8_t iProduct; // Index of Product String Descriptor
  109. uint8_t iSerialNumber; // Index of Serial Number String Descriptor
  110. uint8_t bNumConfigurations; // Number of Possible Configurations
  111. } USB_DevDesc_t;
  112. typedef struct __attribute__((packed)) {
  113. uint8_t bLength;
  114. uint8_t bDescriptorType;
  115. uint16_t wTotalLength; // Total Length
  116. uint8_t bNumInterfaces; // Number of Interfaces
  117. uint8_t bConfigurationValue; // Value to use as an argument to select this configuration
  118. uint8_t iConfiguration; // Index of String Descriptor Describing this configuration
  119. uint8_t bmAttributes; // D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)
  120. uint8_t bMaxPower; // Maximum Power Consumption
  121. } USB_CfgDesc_t;
  122. typedef struct __attribute__((packed)) {
  123. uint8_t bLength;
  124. uint8_t bDescriptorType;
  125. uint8_t bInterfaceNumber;
  126. uint8_t bAlternateSetting; // Value used to select alternative setting
  127. uint8_t bNumEndpoints; // Number of Endpoints used for this interface
  128. uint8_t bInterfaceClass;
  129. uint8_t bInterfaceSubClass;
  130. uint8_t bInterfaceProtocol;
  131. uint8_t iInterface; // Index of String Descriptor Describing this interface
  132. } USB_IntfDesc_t;
  133. typedef struct __attribute__((packed)) {
  134. uint8_t bLength;
  135. uint8_t bDescriptorType;
  136. uint8_t bEndpointAddress; // indicates what endpoint this descriptor is describing
  137. uint8_t bmAttributes; // specifies the transfer type.
  138. uint16_t wMaxPacketSize; // Maximum Packet Size this endpoint is capable of sending or receiving
  139. uint8_t bInterval; // is used to specify the polling interval of certain transfers.
  140. } USB_EpDesc_t;
  141. typedef struct __attribute__((packed)) {
  142. uint8_t bLength;
  143. uint8_t bDescriptorType;
  144. uint16_t bcdHID; // indicates what endpoint this descriptor is describing
  145. uint8_t bCountryCode;
  146. uint8_t bNumDescriptors;
  147. uint8_t bReportDescriptorType;
  148. uint16_t wItemLength;
  149. } USB_HIDDesc_t;
  150. /* Header Functional Descriptor, which marks the beginning of the
  151. concatenated set of functional descriptors for the interface. */
  152. typedef struct __attribute__((packed)) {
  153. uint8_t bLength;
  154. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  155. uint8_t bDescriptorSubType; // 0x00
  156. uint16_t bcdCDC;
  157. } USB_CDC_HeaderFuncDesc_t;
  158. /* Call Management Functional Descriptor */
  159. typedef struct __attribute__((packed)) {
  160. uint8_t bLength;
  161. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  162. uint8_t bDescriptorSubType; // 0x01
  163. uint8_t bmCapabilities;
  164. uint8_t bDataInterface;
  165. } USB_CDC_CallMgmtFuncDesc_t;
  166. /* Abstract Control Management Functional Descriptor */
  167. typedef struct __attribute__((packed)) {
  168. uint8_t bLength;
  169. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  170. uint8_t bDescriptorSubType; // 0x02
  171. uint8_t bmCapabilities;
  172. } USB_CDC_AbstCntrlMgmtFuncDesc_t;
  173. /* Union Functional Descriptor */
  174. typedef struct __attribute__((packed)) {
  175. uint8_t bLength;
  176. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  177. uint8_t bDescriptorSubType; // 0x06
  178. uint8_t bMasterInterface; // Interface number of the Communication or Data Class interface
  179. uint8_t bSlaveInterface0; // Interface number of first slave
  180. } USB_CDC_UnionFuncDesc_t;
  181. #endif //__SWM341_USB_H__