SWM341_usb.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. /* USB HID Descriptor Type */
  48. #define USB_DESC_HID 0x21
  49. #define USB_DESC_HID_RPT 0x22
  50. /* USB Endpoint Type */
  51. #define USB_EP_CTRL 0x00
  52. #define USB_EP_ISO 0x01
  53. #define USB_EP_BULK 0x02
  54. #define USB_EP_INT 0x03
  55. #define USB_EP_IN 0x80
  56. #define USB_EP_OUT 0x00
  57. /* USB Feature Selector */
  58. #define USB_FEATURE_REMOTE_WAKEUP 0x01
  59. #define USB_FEATURE_ENDPOINT_HALT 0x00
  60. /* USB HID Class Report Type */
  61. #define HID_RPT_TYPE_INPUT 0x01
  62. #define HID_RPT_TYPE_OUTPUT 0x02
  63. #define HID_RPT_TYPE_FEATURE 0x03
  64. /* Define HID Class Specific Request */
  65. #define USB_HID_GET_REPORT 0x01
  66. #define USB_HID_GET_IDLE 0x02
  67. #define USB_HID_GET_PROTOCOL 0x03
  68. #define USB_HID_SET_REPORT 0x09
  69. #define USB_HID_SET_IDLE 0x0A
  70. #define USB_HID_SET_PROTOCOL 0x0B
  71. /* Class */
  72. #define USB_CDC_CLASS 0x02 // for Device
  73. #define USB_CDC_CTRL_CLASS 0x02 // for Interface
  74. #define USB_CDC_DATA_CLASS 0x0A // for Interface
  75. #define USB_HID_CLASS 0x03 // for Interface
  76. #define USB_MSC_CLASS 0x08 // for Interface
  77. /* SubClass */
  78. #define USB_CDC_ACM 0x02 // Abstract Control Model
  79. #define USB_HID_BOOT 0x01
  80. /* Protocol */
  81. #define USB_CDC_ATCMD 0x01 // AT Commands defined by ITU-T V.250
  82. #define USB_HID_NONE 0x00
  83. #define USB_HID_KEYBD 0x01
  84. #define USB_HID_MOUSE 0x02
  85. #define USB_MSC_BOT 0x50 // Bulk-Only Transport
  86. typedef struct {
  87. uint8_t bLength;
  88. uint8_t bDescriptorType;
  89. } USB_DescHeader_t;
  90. typedef struct __attribute__((packed)) {
  91. uint8_t bLength;
  92. uint8_t bDescriptorType;
  93. uint16_t bcdUSB; // USB Specification Number which device complies to
  94. uint8_t bDeviceClass; // 0x00: each interface specifies its own class code
  95. uint8_t bDeviceSubClass;
  96. uint8_t bDeviceProtocol;
  97. uint8_t bMaxPacketSize;
  98. uint16_t idVendor; // Vendor ID (Assigned by USB Org)
  99. uint16_t idProduct; // Product ID (Assigned by Manufacturer)
  100. uint16_t bcdDevice; // Device Release Number
  101. uint8_t iManufacturer; // Index of Manufacturer String Descriptor
  102. uint8_t iProduct; // Index of Product String Descriptor
  103. uint8_t iSerialNumber; // Index of Serial Number String Descriptor
  104. uint8_t bNumConfigurations; // Number of Possible Configurations
  105. } USB_DevDesc_t;
  106. typedef struct __attribute__((packed)) {
  107. uint8_t bLength;
  108. uint8_t bDescriptorType;
  109. uint16_t wTotalLength; // Total Length
  110. uint8_t bNumInterfaces; // Number of Interfaces
  111. uint8_t bConfigurationValue; // Value to use as an argument to select this configuration
  112. uint8_t iConfiguration; // Index of String Descriptor Describing this configuration
  113. uint8_t bmAttributes; // D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)
  114. uint8_t bMaxPower; // Maximum Power Consumption
  115. } USB_CfgDesc_t;
  116. typedef struct __attribute__((packed)) {
  117. uint8_t bLength;
  118. uint8_t bDescriptorType;
  119. uint8_t bInterfaceNumber;
  120. uint8_t bAlternateSetting; // Value used to select alternative setting
  121. uint8_t bNumEndpoints; // Number of Endpoints used for this interface
  122. uint8_t bInterfaceClass;
  123. uint8_t bInterfaceSubClass;
  124. uint8_t bInterfaceProtocol;
  125. uint8_t iInterface; // Index of String Descriptor Describing this interface
  126. } USB_IntfDesc_t;
  127. typedef struct __attribute__((packed)) {
  128. uint8_t bLength;
  129. uint8_t bDescriptorType;
  130. uint8_t bEndpointAddress; // indicates what endpoint this descriptor is describing
  131. uint8_t bmAttributes; // specifies the transfer type.
  132. uint16_t wMaxPacketSize; // Maximum Packet Size this endpoint is capable of sending or receiving
  133. uint8_t bInterval; // is used to specify the polling interval of certain transfers.
  134. } USB_EpDesc_t;
  135. typedef struct __attribute__((packed)) {
  136. uint8_t bLength;
  137. uint8_t bDescriptorType;
  138. uint16_t bcdHID; // indicates what endpoint this descriptor is describing
  139. uint8_t bCountryCode;
  140. uint8_t bNumDescriptors;
  141. uint8_t bReportDescriptorType;
  142. uint16_t wItemLength;
  143. } USB_HIDDesc_t;
  144. /* Header Functional Descriptor, which marks the beginning of the
  145. concatenated set of functional descriptors for the interface. */
  146. typedef struct __attribute__((packed)) {
  147. uint8_t bLength;
  148. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  149. uint8_t bDescriptorSubType; // 0x00
  150. uint16_t bcdCDC;
  151. } USB_CDC_HeaderFuncDesc_t;
  152. /* Call Management Functional Descriptor */
  153. typedef struct __attribute__((packed)) {
  154. uint8_t bLength;
  155. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  156. uint8_t bDescriptorSubType; // 0x01
  157. uint8_t bmCapabilities;
  158. uint8_t bDataInterface;
  159. } USB_CDC_CallMgmtFuncDesc_t;
  160. /* Abstract Control Management Functional Descriptor */
  161. typedef struct __attribute__((packed)) {
  162. uint8_t bLength;
  163. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  164. uint8_t bDescriptorSubType; // 0x02
  165. uint8_t bmCapabilities;
  166. } USB_CDC_AbstCntrlMgmtFuncDesc_t;
  167. /* Union Functional Descriptor */
  168. typedef struct __attribute__((packed)) {
  169. uint8_t bLength;
  170. uint8_t bDescriptorType; // CS_INTERFACE (0x24)
  171. uint8_t bDescriptorSubType; // 0x06
  172. uint8_t bMasterInterface; // Interface number of the Communication or Data Class interface
  173. uint8_t bSlaveInterface0; // Interface number of first slave
  174. } USB_CDC_UnionFuncDesc_t;
  175. #endif //__SWM341_USB_H__