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

📄 usb_descriptor.h

📁 基于C8051单片机的USB Device driver
💻 H
字号:
/*
This file includes the descripter of a USB Device,according to
USB protocal 2.0 chapter 9 USB Device Framework.
Notation:
 b for BYTE(unsigned char)
 u for UINT(unsigned int)
 p for Pointer
 w for WORD(two bytes,organized as a union {unsigned int i; unsigned char c[2];})
 g for Global variable
 rb for A bit mask for bits in a USB register
 rbIn for A bit mask for bits in an IN Status USB register
 rbOut for A bit mask for bits in an OUT Status USB register
 bm for Bit-mapped BYTE
 std_ for Array offset for a standard device descriptor field
 cfg_ for Array offset for a configuration descriptor field
 if_ for Array offset for an interface descripter field
 ep_ for Array offset for an endpoint descripter field
*/

#ifndef _USB_DESCRIPTER_H_
#define _USB_DESCRIPTER_H_

#ifndef _BYTE_DEF_
#define _BYTE_DEF_
typedef unsigned char BYTE;
#endif /* _BYTE_DEF_ */

#ifndef _UINT_DEF_
#define _UINT_DEF_
typedef unsigned int UINT;
#endif /* _UINT_DEF_ */

#ifndef _WORD_DEF_
#define _WORD_DEF_
typedef union {unsigned int i; unsigned char c[2];} WORD;
#define LSB 1                   // All words sent to and received from the host are
#define MSB 0                   // little endian, this is switched by software when
                                // neccessary.  These sections of code have been marked
                                // with "Compiler Specific" as above for easier modification
#endif /* _WORD_DEF_ */

typedef struct DEVICE_STATUS
{
   BYTE bDevState;              // Device states
   BYTE bRemoteWakeupStatus;    // Device remote wakeup enabled/disabled
   BYTE bSelfPoweredStatus;     // Device self- or bus-powered
} DEVICE_STATUS;

typedef struct EP_STATUS
{
   UINT uNumBytes;            // Number of bytes available to transmit
   BYTE bEpState;               // Endpoint state
   BYTE *pData;                  // Pointer to data to transmit
} EP_STATUS;

//------------------------------------------
// Standard Device Descriptor Type Defintion
//------------------------------------------
typedef code struct
{
   BYTE bLength;                // Size of this Descriptor in Bytes
   BYTE bDescriptorType;        // Descriptor Type (=1)
   WORD bcdUSB;                 // USB Spec Release Number in BCD
   BYTE bDeviceClass;           // Device Class Code
   BYTE bDeviceSubClass;        // Device Subclass Code
   BYTE bDeviceProtocol;        // Device Protocol Code
   BYTE bMaxPacketSize0;        // Maximum Packet Size for EP0
   WORD idVendor;               // Vendor ID
   WORD idProduct;              // Product ID
   WORD bcdDevice;              // Device Release Number in BCD
   BYTE iManufacturer;          // Index of String Desc for Manufacturer
   BYTE iProduct;               // Index of String Desc for Product
   BYTE iSerialNumber;          // Index of String Desc for SerNo
   BYTE bNumConfigurations;     // Number of possible Configurations
} DEVICE_DESCRIPTOR;            // End of Device Descriptor Type

//--------------------------------------------------
// Standard Configuration Descriptor Type Definition
//--------------------------------------------------
typedef code struct
{
   BYTE bLength;                // Size of this Descriptor in Bytes
   BYTE bDescriptorType;        // Descriptor Type (=2)
   WORD wTotalLength;           // Total Length of Data for this Conf
   BYTE bNumInterfaces;         // No of Interfaces supported by this Conf
   BYTE bConfigurationValue;    // Designator Value for *this* Configuration
   BYTE iConfiguration;         // Index of String Desc for this Conf
   BYTE bmAttributes;           // Configuration Characteristics (see below)
   BYTE bMaxPower;              // Max. Power Consumption in this Conf (*2mA)
} CONFIGURATION_DESCRIPTOR;     // End of Configuration Descriptor Type

//----------------------------------------------
// Standard Interface Descriptor Type Definition
//----------------------------------------------
typedef code struct
{
   BYTE bLength;                // Size of this Descriptor in Bytes
   BYTE bDescriptorType;        // Descriptor Type (=4)
   BYTE bInterfaceNumber;       // Number of *this* Interface (0..)
   BYTE bAlternateSetting;      // Alternative for this Interface (if any)
   BYTE bNumEndpoints;          // No of EPs used by this IF (excl. EP0)
   BYTE bInterfaceClass;        // Interface Class Code
   BYTE bInterfaceSubClass;     // Interface Subclass Code
   BYTE bInterfaceProtocol;     // Interface Protocol Code
   BYTE iInterface;             // Index of String Desc for this Interface
} INTERFACE_DESCRIPTOR;         // End of Interface Descriptor Type

//---------------------------------------------
// Standard Endpoint Descriptor Type Definition
//---------------------------------------------
typedef code struct
{
   BYTE bLength;                // Size of this Descriptor in Bytes
   BYTE bDescriptorType;        // Descriptor Type (=5)
   BYTE bEndpointAddress;       // Endpoint Address (Number + Direction)
   BYTE bmAttributes;           // Endpoint Attributes (Transfer Type)
   WORD wMaxPacketSize;	        // Max. Endpoint Packet Size
   BYTE bInterval;              // Polling Interval (Interrupt) ms
} ENDPOINT_DESCRIPTOR;          // End of Endpoint Descriptor Type


//-----------------------------
// Setup Packet Type Definition
//-----------------------------
typedef struct
{
   BYTE bmRequestType;          // Request recipient, type, and direction
   BYTE bRequest;               // Specific standard request number
   WORD wValue;                 // varies according to request
   WORD wIndex;                 // varies according to request
   WORD wLength;                // Number of bytes to transfer
} SETUP_BUFFER;                 // End of Setup Packet Type

// Descriptor sizes
#define STD_DSC_SIZE 18                   // Device
#define CFG_DSC_SIZE 9                    // Configuration
#define IF_DSC_SIZE 9                     // Interface
#define EP_DSC_SIZE 7                     // Endpoint

// Descriptor indicies - these are used to access specific fields
// of a descriptor array.

// Standard Device Descriptor Array Indicies
#define std_bLength 0                     // Length of this descriptor
#define std_bDescriptorType 1             // Device desc type (const. 0x01)
#define std_bcdUSB 2                      // USB Specification used (BCD)
#define std_bDeviceClass 4                // Device Class
#define std_bDeviceSubClass 5             // Device SubClass
#define std_bDeviceProtocol 6             // Device Protocol
#define std_bMaxPacketSize0 7             // Maximum packet size for Endpoint0
#define std_idVendor 8                    // Vendor ID
#define std_idProduct 10                  // Product ID
#define std_bcdDevice 12                  // Device revision number
#define std_iManufacturer 14              // Manufacturer name string index
#define std_std_iProduct 15               // Product name string index
#define std_iSerialNumber 16              // Serial number string index
#define std_bNumConfigurations 17         // Number of supported configurations

// Configuration Descriptor Array Indicies
#define cfg_bLength 0                     // Length of this desc
#define cfg_bDescriptorType 1             // Config desc type (const. 0x02)
#define cfg_wTotalLength_lsb 2            // Total length, including
#define cfg_wTotalLength_msb 3            // interface & endpoints
#define cfg_bNumInterfaces 4              // Number of supported int's
#define cfg_bConfigurationValue 5         // Config index
#define cfg_iConfiguration 6              // Index for string desc
#define cfg_bmAttributes 7                // Power, wakeup options
#define cfg_MaxPower 8                    // Max bus power consumed

// Interface Descriptor Array Indicies
#define if_bLength 0                      // Length of this desc
#define if_bDescriptorType 1              // Interface desc type (const. ??  )
#define if_bInterfaceNumber 2             // This interface index
#define if_bAlternateSetting 3            // Alternate index
#define if_bNumEndpoints 4                // Endpoints used by this interface
#define if_bInterfaceClass 5              // Device class
#define if_bInterfaceSubClass 6           // Device subclass
#define if_bInterfaceProcotol 7           // Class-specific protocol
#define if_iInterface 8                   // Index for string desc

// Endpoint Descriptor Array Indicies
#define ep_bLength 0                      // Length of this desc
#define ep_bDescriptorType 1              // Endpoint desc type
#define ep_bEndpointAddress 2             // This endpoint address
#define ep_bmAttributes 3                 // Transfer type
#define ep_wMaxPacketSize 4               // Max FIFO size
#define ep_bInterval 6                    // Polling interval (int only)

#endif   /* USB_DESCRIPTOR_H */

⌨️ 快捷键说明

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