⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbstd.h

📁 CE下 NET2778 NDIS Drivers, 在每个平台上都可以使用
💻 H
字号:
/********************************************************************

USBSTD.H

USB Standard Definitions

Copyright NetChip Technology, 1997

Changes
971127  Ryan    Genesis - USB definitions

********************************************************************/

/////////////////////////////////////////////////////////////////////
#ifndef USBSTD_H
#define USBSTD_H

/////////////////////////////////////////////////////////////////////
#ifdef DRIVER

/////////////////////////////////////////////////////////////////////
// Disable warning for zero-sized arrays (warning C4200)
// MSDN: Compiler Warning (levels 2 and 4) C4200: nonstandard extension used:
// zero-sized array in struct/union. A structure or union contained an array with zero size.
#pragma warning (disable: 4200)
#endif

/////////////////////////////////////////////////////////////////////
#define USBSPEC 0x0200                  // USB Specification Release (BCD)

/////////////////////////////////////////////////////////////////////
// Standard Request Codes (in bRequest)
#define GET_STATUS              0x00    // 
#define CLEAR_FEATURE           0x01    // 
#define SET_FEATURE             0x03    // 
#define SET_ADDRESS             0x05    // 
#define GET_DESCRIPTOR          0x06    // 
#define SET_DESCRIPTOR          0x07    // 
#define GET_CONFIGURATION       0x08    // 
#define SET_CONFIGURATION       0x09    // 
#define GET_INTERFACE           0x0a    // 
#define SET_INTERFACE           0x0b    // 
#define SYNCH_FRAME             0x0c    // 

/////////////////////////////////////////////////////////////////////
// Descriptor Types (in wValue) (See USB 1.1, Table 9-5)
#define DEVICE_DESC                     0x01    // 
#define CONFIGURATION_DESC              0x02    // 
#define STRING_DESC                     0x03    // 
#define INTERFACE_DESC                  0x04    // 
#define ENDPOINT_DESC                   0x05    // 
// Added for USB 2.0
#define DEVICE_QUALIFIER_DESC           0x06    //
#define OTHER_SPEED_CONFIGURATION_DESC  0x07    //
#define INTERFACE_POWER_DESC            0x08    //

/////////////////////////////////////////////////////////////////////
// Feature selectors (in wValue) (See USB 2.0: 9.4.5)
#define DEVICE_REMOTE_WAKEUP    0x0001          // Not to be confused with Remote Wakeup in bmAttributes!
#define ENDPOINT_STALL          0x0000          //
// Added for USB 2.0
#define TEST_MODE               0x0002          //

/////////////////////////////////////////////////////////////////////
// Test mode selectors (in wIndex) (See USB 2.0: 9.4.9)
#define USB_TEST_J              0x01
#define USB_TEST_K              0x02
#define USB_TEST_SE0_NAK        0x03
#define USB_TEST_PACKET         0x04
#define USB_TEST_FORCE_ENABLE   0x05

/////////////////////////////////////////////////////////////////////
// bmRequestType bits (in bmRequestType)
//  - See USB 2.0: 9.3.1, Table 9-2
#define HOST_TO_DEVICE          (0<<7)  // xfer direction OUT
#define DEVICE_TO_HOST          (1<<7)  // xfer direction IN
//
#define STANDARD                (0<<5)  // Type
#define CLASS                   (1<<5)  // Type
#define VENDOR                  (2<<5)  // Type
#define RESERVED                (3<<5)  // Type
// 
#define RECIPIENT_DEVICE        0       // Recipient
#define RECIPIENT_INTERFACE     1       // Recipient
#define RECIPIENT_ENDPOINT      2       // Recipient
#define RECIPIENT_OTHER         3       // Recipient

/////////////////////////////////////////////////////////////////////
// Transfer type (in bmAttributes of Endpoint Descriptors)
//  - Maps to matching in NetChip endpoint configuration register
//  - See USB 2.0: Table 9-13
#define CTRL                    0x00    // 1-0: 00:Control
#define ISOC                    0x01    // 1-0: 01:Isochronous
#define BULK                    0x02    // 1-0: 10:Bulk
#define INTR                    0x03    // 1-0: 11:Interrupt

/////////////////////////////////////////////////////////////////////
// Endpoint direction (usually OR'd with bEndpointAddress in bits 3-0)
//  - Note: Not to be confused with endpoint direction programming in chip
//  - See USB 2.0: Table 9-13
#define EP_OUT                  0x00    // 7: Endpoint direction OUT
#define EP_IN                   0x80    // 7: Endpoint direction IN
#define EP_DIRECTION_IN            7

/////////////////////////////////////////////////////////////////////
// Endpoint counts
#define MAX_DATA_ENDPOINTS_PER_DIRECTION    15                                          // 15 IN or 15 OUT
#define MAX_DATA_ENDPOINTS                  (2*MAX_DATA_ENDPOINTS_PER_DIRECTION)        // 15 IN plus 15 OUT
#define MAX_ENDPOINTS                       (2*(MAX_DATA_ENDPOINTS_PER_DIRECTION + 1))  // Add two for EP0

/////////////////////////////////////////////////////////////////////
// Endpoint address mask
//  - Use to isolate endpoint address from endpoint direction in bEndpointAddress
#define ENDPOINT_ADDRESS_MASK       0x0f

/////////////////////////////////////////////////////////////////////
// bmAttribute bits in Configuration Descriptor
//  - USB 2.0 9.6.3 (bmAttributes in Table 9-10): Bit 7 is reserved, and always set to one
#define CONFIG_SELF_POWERED        6
#define CONFIG_REMOTE_WAKEUP       5    // Not to be confused with Device Remote Wakeup feature selector!

/////////////////////////////////////////////////////////////////////
// Vendor-specific type
//  - Vendor specific device, class, subclass and protocols are all 0xff
#define VENDOR_SPECIFIC                             0xff

/////////////////////////////////////////////////////////////////////
// USB Device requests (Setup packets)
//  - See USB 2.0: 9.3
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
typedef struct _USB_SETUP_PACKET
{   // USB setup packet (USB spec: 9.3)
    BYTE bmRequestType;
    BYTE bRequest;
    WORDBYTE wValue;
    WORDBYTE wIndex;
    WORDBYTE wLength;
} USB_SETUP_PACKET, * PUSB_SETUP_PACKET;

/////////////////////////////////////////////////////////////////////
// Setup packet (referenced as an array of bytes)
#define _bmRequestType  0
#define _bRequest       1
#define _wValueLo       2
#define _wValueHi       3
#define _wIndexLo       4
#define _wIndexHi       5
#define _wLengthLo      6
#define _wLengthHi      7

/////////////////////////////////////////////////////////////////////
// USB descriptors
//  - Based on USB 2.0: 9.6
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
typedef struct _USB_DEVICE_DESCRIPTOR 
{   // USB Device Descriptor
    //  - See USB 2.0: 9.6.1
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bcdUSBLo;
    BYTE bcdUSBHi;
    BYTE bDeviceClass;
    BYTE bDeviceSubClass;
    BYTE bDeviceProtocol;
    BYTE bMaxPacketSize0;
    BYTE idVendorLo;
    BYTE idVendorHi;
    BYTE idProductLo;
    BYTE idProductHi;
    BYTE bcdDeviceLo;
    BYTE bcdDeviceHi;
    BYTE iManufacturer;
    BYTE iProduct;
    BYTE iSerialNumber;
    BYTE bNumConfigurations;
}   USB_DEVICE_DESCRIPTOR, *   PUSB_DEVICE_DESCRIPTOR;

/////////////////////////////////////////////////////////////////////
// A USB configuration is packed with these standard USB descriptors 
// (See USB 2.0: 9.6.3):
//  - One Configuration Descriptor
//  - One (or more) Interface Descriptors
//  - An interface may be packed with zero or more Endpoint Descriptors
//  - Non-standard descriptors may be interleaved with standard descriptors
// Structures and packing tip: Care must be taken to ensure that the compiler
// packs descriptors (which are defined as structures) to be "byte aligned":
//  - The entire configuration, with all its packed descriptors, is 
//    returned to the host as a single USB transfer. There can be no 
//    gaps beween descriptors due to the compiler's structure packing 
//    and alignment strategy
//  - Compilers supporting zero-length arrays in structures may apply
typedef struct _USB_CONFIGURATION_DESCRIPTOR 
{   // USB Configuration Descriptor
    //  - See USB 2.0: 9.6.3
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE wTotalLengthLo;
    BYTE wTotalLengthHi;
    BYTE bNumInterfaces;
    BYTE bConfigurationValue;
    BYTE iConfiguration;
    BYTE bmAttributes;
    BYTE bMaxPower;             // In 2ma increments
}   USB_CONFIGURATION_DESCRIPTOR, *   PUSB_CONFIGURATION_DESCRIPTOR;

/////////////////////////////////////////////////////////////////////
// A USB interface is packed with zero or more Endpoint Descriptors
//  - Structures and packing tip: See discussion for USB configurations
typedef struct _USB_INTERFACE_DESCRIPTOR 
{   // USB Interface Descriptor
    //  - See USB 2.0: 9.6.5
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bInterfaceNumber;
    BYTE bAlternateSetting;
    BYTE bNumEndpoints;
    BYTE bInterfaceClass;
    BYTE bInterfaceSubClass;
    BYTE bInterfaceProtocol;
    BYTE iInterface;
}   USB_INTERFACE_DESCRIPTOR, *   PUSB_INTERFACE_DESCRIPTOR;

/////////////////////////////////////////////////////////////////////
typedef struct _USB_ENDPOINT_DESCRIPTOR 
{   // USB Endpoint Descriptor
    //  - See USB 2.0: 9.6.6
    BYTE bLength;               // 0x00
    BYTE bDescriptorType;       // 0x01
    BYTE bEndpointAddress;      // 0x02 Direction in bit 7
    BYTE bmAttributes;          // 0x03 CTRL, ISOC, BULK, INTR
    BYTE wMaxPacketSizeLo;      // 0x04
    BYTE wMaxPacketSizeHi;      // 0x05
    BYTE bInterval;             // 0x06 Polling interval (Interrupt, Isoch)
}   USB_ENDPOINT_DESCRIPTOR, *   PUSB_ENDPOINT_DESCRIPTOR;

/////////////////////////////////////////////////////////////////////
typedef struct _USB_STRING_DESCRIPTOR 
{   // USB String Descriptor
    //  - See USB 2.0: 9.6.7
    BYTE bLength;
    BYTE bDescriptorType;
    // The string content follows as a list of two-byte UNICODE characters
    //  - UNICODE characters must follow this structure without gaps. See 
    //    "structures and packing tip" in discussion for USB configurations
}   USB_STRING_DESCRIPTOR, *   PUSB_STRING_DESCRIPTOR;

/////////////////////////////////////////////////////////////////////
// USB descriptors added based on USB 2.00 Specification
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR 
{   // USB Device_Qualifier Descriptor
    //  - See USB 2.0: 9.6.2
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bcdUSBLo;
    BYTE bcdUSBHi;
    BYTE bDeviceClass;
    BYTE bDeviceSubClass;
    BYTE bDeviceProtocol;
    BYTE bMaxPacketSize0;
    BYTE bNumConfigurations;
    BYTE bReserved;
}   USB_DEVICE_QUALIFIER_DESCRIPTOR, *   PUSB_DEVICE_QUALIFIER_DESCRIPTOR;

/////////////////////////////////////////////////////////////////////
typedef struct _USB_COMMON_DESCRIPTOR 
{   // Common header for all USB descriptors
    //  - Can be applied to parsing any USB descriptor
    //  - Can be applied to non-standard USB descriptors
    BYTE bLength;
    BYTE bDescriptorType;
} USB_COMMON_DESCRIPTOR, *PUSB_COMMON_DESCRIPTOR;

/////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
// Link to next USB descriptor
#define NEXT_USB_DESCRIPTOR(pDescr) ((PBYTE)(pDescr)+((pDescr)->bLength))

/////////////////////////////////////////////////////////////////////
// NetChip standards
//  - Vendor ID
//  - Product IDs
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
// BEFORE APPLYING VENDOR AND PRODUCT ID'S TO YOUR DEVICE:
//  - CONTACT NETCHIP IF YOU INTEND TO USE NETCHIP'S VID (0x0525)
//  - CONTACT USB-IF IF YOU DO NOT INTEND TO USE NETCHIP'S VID
// Applying unique VIDs and PIDs is crucial to the success of USB as a whole.
// Failing to abide by USB's and/or NetChip's VID and PID registration
// methods could cause terrible conflicts and consequences long after
// your device is released!
// 
// NetChip offers FREE PIDs that you can use with NetChip's VID (0x0525)
//  - To get your FREE PIDs, contact   support@netchip.com
//
// Vendor ID given to NetChip by the USB-IF is 0x0525:
#define VID_NETCHIP     0x0525      // READ STATEMENT (ABOVE) REGARDING VIDs and PIDs!!!

/////////////////////////////////////////////////////////////////////
// Some NetChip standard PIDs:

// Transfer devices (0x1000 to 0x10ff)
#define PID_TRANSFER            0x1000                  // Basic transfer device
#define PID_TRANSFER_ISOCH      PID_TRANSFER + 0x40     // Isochronous transfer device

// Loopback devices (0x1100 to 0x11ff)
#define PID_LOOPBACK        0x1100      // Basic loopback device

#define PID_MASS_STORAGE    0x1200
#define PID_PRINTER         0x1300
#define PID_CHAPTER9        0x1400
#define PID_TERMINAL        0x1500

/////////////////////////////////////////////////////////////////////
#endif // USBSTD_H

/////////////////////////////////////////////////////////////////////
//  End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -