USB100.H
上传用户:lyfy_2008
上传日期:2014-07-13
资源大小:3016k
文件大小:7k
源码类别:

USB编程

开发平台:

Visual C++

  1. #ifndef   __USB100_H__
  2. #define   __USB100_H__
  3. #define MAXIMUM_USB_STRING_LENGTH 255
  4. // values for the bits returned by the USB GET_STATUS command
  5. #define USB_GETSTATUS_SELF_POWERED                0x01
  6. #define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED       0x02
  7. #define USB_DEVICE_DESCRIPTOR_TYPE                0x01
  8. #define USB_CONFIGURATION_DESCRIPTOR_TYPE         0x02
  9. #define USB_STRING_DESCRIPTOR_TYPE                0x03
  10. #define USB_INTERFACE_DESCRIPTOR_TYPE             0x04
  11. #define USB_ENDPOINT_DESCRIPTOR_TYPE              0x05
  12. #define USB_POWER_DESCRIPTOR_TYPE                 0x06
  13. #define USB_DESCRIPTOR_MAKE_TYPE_AND_INDEX(d, i) ((USHORT)((USHORT)d<<8 | i))
  14. //
  15. // Values for bmAttributes field of an
  16. // endpoint descriptor
  17. //
  18. #define USB_ENDPOINT_TYPE_MASK                    0x03
  19. #define USB_ENDPOINT_TYPE_CONTROL                 0x00
  20. #define USB_ENDPOINT_TYPE_ISOCHRONOUS             0x01
  21. #define USB_ENDPOINT_TYPE_BULK                    0x02
  22. #define USB_ENDPOINT_TYPE_INTERRUPT               0x03
  23. //
  24. // definitions for bits in the bmAttributes field of a 
  25. // configuration descriptor.
  26. //
  27. #define USB_CONFIG_POWERED_MASK                   0xc0
  28. #define USB_CONFIG_BUS_POWERED                    0x80
  29. #define USB_CONFIG_SELF_POWERED                   0x40
  30. #define USB_CONFIG_REMOTE_WAKEUP                  0x20
  31. //
  32. // Endpoint direction bit, stored in address
  33. //
  34. #define USB_ENDPOINT_DIRECTION_MASK               0x80
  35. // test direction bit in the bEndpointAddress field of
  36. // an endpoint descriptor.
  37. #define USB_ENDPOINT_DIRECTION_OUT(addr)          (!((addr) & USB_ENDPOINT_DIRECTION_MASK))
  38. #define USB_ENDPOINT_DIRECTION_IN(addr)           ((addr) & USB_ENDPOINT_DIRECTION_MASK)
  39. //
  40. // USB defined request codes
  41. // see chapter 9 of the USB 1.0 specifcation for
  42. // more information.
  43. //
  44. // These are the correct values based on the USB 1.0
  45. // specification
  46. #define USB_REQUEST_GET_STATUS                    0x00
  47. #define USB_REQUEST_CLEAR_FEATURE                 0x01
  48. #define USB_REQUEST_SET_FEATURE                   0x03
  49. #define USB_REQUEST_SET_ADDRESS                   0x05
  50. #define USB_REQUEST_GET_DESCRIPTOR                0x06
  51. #define USB_REQUEST_SET_DESCRIPTOR                0x07
  52. #define USB_REQUEST_GET_CONFIGURATION             0x08
  53. #define USB_REQUEST_SET_CONFIGURATION             0x09
  54. #define USB_REQUEST_GET_INTERFACE                 0x0A
  55. #define USB_REQUEST_SET_INTERFACE                 0x0B
  56. #define USB_REQUEST_SYNC_FRAME                    0x0C
  57. //
  58. // defined USB device classes
  59. //
  60. #define USB_DEVICE_CLASS_RESERVED           0x00
  61. #define USB_DEVICE_CLASS_AUDIO              0x01
  62. #define USB_DEVICE_CLASS_COMMUNICATIONS     0x02
  63. #define USB_DEVICE_CLASS_HUMAN_INTERFACE    0x03
  64. #define USB_DEVICE_CLASS_MONITOR            0x04
  65. #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
  66. #define USB_DEVICE_CLASS_POWER              0x06
  67. #define USB_DEVICE_CLASS_PRINTER            0x07
  68. #define USB_DEVICE_CLASS_STORAGE            0x08
  69. #define USB_DEVICE_CLASS_HUB                0x09
  70. #define USB_DEVICE_CLASS_VENDOR_SPECIFIC    0xFF
  71. //
  72. // USB defined Feature selectors
  73. //
  74. #define USB_FEATURE_ENDPOINT_STALL          0x0000
  75. #define USB_FEATURE_REMOTE_WAKEUP           0x0001
  76. #define USB_FEATURE_POWER_D0                0x0002
  77. #define USB_FEATURE_POWER_D1                0x0003
  78. #define USB_FEATURE_POWER_D2                0x0004
  79. #define USB_FEATURE_POWER_D3                0x0005
  80. typedef struct _USB_DEVICE_DESCRIPTOR {
  81.     UCHAR bLength;
  82.     UCHAR bDescriptorType;
  83.     USHORT bcdUSB;
  84.     UCHAR bDeviceClass;
  85.     UCHAR bDeviceSubClass;
  86.     UCHAR bDeviceProtocol;
  87.     UCHAR bMaxPacketSize0;
  88.     USHORT idVendor;
  89.     USHORT idProduct;
  90.     USHORT bcdDevice;
  91.     UCHAR iManufacturer;
  92.     UCHAR iProduct;
  93.     UCHAR iSerialNumber;
  94.     UCHAR bNumConfigurations;
  95. } USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
  96. typedef struct _USB_ENDPOINT_DESCRIPTOR {
  97.     UCHAR bLength;
  98.     UCHAR bDescriptorType;
  99.     UCHAR bEndpointAddress;
  100.     UCHAR bmAttributes;
  101.     USHORT wMaxPacketSize;
  102.     UCHAR bInterval;
  103. } USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
  104. //
  105. // values for bmAttributes Field in
  106. // USB_CONFIGURATION_DESCRIPTOR
  107. //
  108. #define BUS_POWERED                           0x80
  109. #define SELF_POWERED                          0x40
  110. #define REMOTE_WAKEUP                         0x20
  111. typedef struct _USB_CONFIGURATION_DESCRIPTOR {
  112.     UCHAR bLength;
  113.     UCHAR bDescriptorType;
  114.     USHORT wTotalLength;
  115.     UCHAR bNumInterfaces;
  116.     UCHAR bConfigurationValue;
  117.     UCHAR iConfiguration;
  118.     UCHAR bmAttributes;
  119.     UCHAR MaxPower;
  120. } USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;     
  121.     
  122. typedef struct _USB_INTERFACE_DESCRIPTOR {
  123.     UCHAR bLength;
  124.     UCHAR bDescriptorType;
  125.     UCHAR bInterfaceNumber;   
  126.     UCHAR bAlternateSetting;
  127.     UCHAR bNumEndpoints;
  128.     UCHAR bInterfaceClass;
  129.     UCHAR bInterfaceSubClass;
  130.     UCHAR bInterfaceProtocol;
  131.     UCHAR iInterface;
  132. } USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
  133. typedef struct _USB_STRING_DESCRIPTOR {
  134.     UCHAR bLength;
  135.     UCHAR bDescriptorType;
  136.     UCHAR bString[1];
  137. } USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
  138. //
  139. // USB power descriptor added to core specification
  140. //
  141. #define USB_SUPPORT_D0_COMMAND      0x01
  142. #define USB_SUPPORT_D1_COMMAND      0x02
  143. #define USB_SUPPORT_D2_COMMAND      0x04
  144. #define USB_SUPPORT_D3_COMMAND      0x08
  145. #define USB_SUPPORT_D1_WAKEUP       0x10
  146. #define USB_SUPPORT_D2_WAKEUP       0x20
  147. typedef struct _USB_POWER_DESCRIPTOR {
  148.     UCHAR bLength;
  149.     UCHAR bDescriptorType;
  150.     UCHAR bCapabilitiesFlags;
  151.     USHORT EventNotification;
  152.     USHORT D1LatencyTime;
  153.     USHORT D2LatencyTime;
  154.     USHORT D3LatencyTime;
  155.     UCHAR PowerUnit;
  156.     USHORT D0PowerConsumption;
  157.     USHORT D1PowerConsumption;
  158.     USHORT D2PowerConsumption;
  159. } USB_POWER_DESCRIPTOR, *PUSB_POWER_DESCRIPTOR;
  160. typedef struct _USB_COMMON_DESCRIPTOR {
  161.     UCHAR bLength;
  162.     UCHAR bDescriptorType;
  163. } USB_COMMON_DESCRIPTOR, *PUSB_COMMON_DESCRIPTOR;
  164. //
  165. // Standard USB HUB definitions 
  166. //
  167. // See Chapter 11
  168. //
  169. typedef struct _USB_HUB_DESCRIPTOR {
  170.     UCHAR        bDescriptorLength;      // Length of this descriptor
  171.     UCHAR        bDescriptorType;        // Hub configuration type
  172.     UCHAR        bNumberOfPorts;         // number of ports on this hub
  173.     USHORT       wHubCharacteristics;    // Hub Charateristics
  174.     UCHAR        bPowerOnToPowerGood;    // port power on till power good in 2ms
  175.     UCHAR        bHubControlCurrent;     // max current in mA
  176.     //
  177.     // room for 255 ports power control and removable bitmask
  178.     UCHAR        bRemoveAndPowerMask[64];
  179. } USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
  180. #endif   /* __USB100_H__ */