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

📄 usb100._h

📁 基于D12的USB固件驱动
💻 _H
字号:
#ifndef    _USB100_H_
#define    _USB100_H_

#define    MAXIMUM_USB_STRING_LENGTH  255

/*values for the bits returned by the USB GET_STATUS command*/
#define  USB_GETSTATUS_SELF_POWERED              0x01
#define  USB_GETSTATUS_REMOTE_WAKEUP_ENABLED     0x02

#define  USB_DEVICE_DESCRIPTOR_TYPE              0x01
#define  USB_CONFIGURATION_DESCRIPTOR_TYPE       0x02
#define  USB_STRING_DESCRIPTOR_TYPE              0x03
#define  USB_INTERFACE_DESCRIPTOR_TYPE           0x04
#define  USB_ENDPOINT_DESCRIPTOR_TYPE            0x05
#define  USB_POWER_DESCRIPTOR_TYPE               0x06

#define  USB_DESCRIPTOR_MAKE_TYPE_AND_INDEX(d,i)  ((unsigned short)((unsigned short)d<<8|i))

/*values for bmAttributes field of an endpoint descriptor*/
#define  USB_ENDPOINT_TYPE_MASK                  0x03

#define  USB_ENDPOINT_TYPE_CONTROL               0x00
#define  USB_ENDPOINT_TYPE_ISOCHARONOUS          0x01
#define  USB_ENDPOINT_TYPE_BULK                  0x02
#define  USB_ENDPOINT_TYPE_INTERRUPT             0x03


/*definitions for bits in the bmAttributes field of a configuration descriptor.*/
#define  USB_CONFIG_POWERED_MASK                 0xc0

#define  USB_CONFIG_BUS_POWERED                  0x80
#define  USB_CONFIG_SELF_POWERED                 0x40
#define  USB_CONFIG_REMOTE_POWERED               0x20


/*Endpoint direction bit,stored in address*/
#define  USB_ENDPOINT_DIRECTION_MASK              0x80

/*test direction bit in the bEndpointAddress field of an endpoint descriptior*/
#define  USB_ENDPOINT_DIRECTION_OUT(addr)       (!((addr)&USB_ENDPOINT_DIRECTION_MASK))
#define  USB_ENDPOINT_DIRECTION_IN(addr)        (((addr)&USB_ENDPOINT_DIRECTION_MASK))
       

/*USB defined request codes see chapter9 of the usb 1.0 specificationfor more information.*/

/*These are the correct values based on the USB 1.0 specification*/
#define USB_REQUEST_GET_STATUS                   0x00
#define USB_REQUEST_CLEAR_FEATURE                0x01
#define USB_REQUEST_SET_FEATURE                  0x03
#define USB_REQUEST_SET_ADDRESS                  0x05
#define USB_REQUEST_GET_DESCRIPTOR               0x06
#define USB_REQUEST_SET_DESCRIPTOR               0x07
#define USB_REQUEST_GET_CONFIGURATION            0x08
#define USB_REQUEST_SET_CONFIGURATION            0x09
#define USB_REQUEST_GET_INTERFACE                0x0A
#define USB_REQUEST_SET_INTERFACE                0x0B
#define USB_REQUEST_SYNC_FRAME                   0x0C

/*defined USB device classes*/

#define USB_DEVICE_CLASS_RESERVED               0x00
#define USB_DEVICE_CLASS_AUDIO                  0x01
#define USB_DEVICE_CLASS_COMMUNICATION          0x02
#define USB_DEVICE_CLASS_HUMAN_INTERFACE        0x03
#define USB_DEVICE_CLASS_MONITOR                0x04
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE     0x05
#define USB_DEVICE_CLASS_POWER                  0x06
#define USB_DEVICE_CLASS_PRINTER                0x07
#define USB_DEVICE_CLASS_STORAGE                0x08
#define USB_DEVICE_CLASS_HUB                    0x09
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC        0xFF


/*USB defined Feature selectors*/

#define  USB_FEATURE_ENDPOINT_STALL              0x0000
#define  USB_FEATURE_REMOTE_WAKEUP               0x0001
#define  USB_FEATURE_POWER_D0                    0x0002
#define  USB_FEATURE_POWER_D1                    0x0003
#define  USB_FEATURE_POWER_D2                    0x0004
#define  USB_FEATURE_POWER_D3                    0x0005

/*

typedef struct _USB_DEVICE_DESCRIPTOR{
   unsigned char  bLength;                    //12H
   unsigned char  bDescriptorType;            //01H
   unsigned short bcdUSB;                    //V1.1
   unsigned char  bDeviceClass;
   unsigned char  bDeviceSubClass;
   unsigned char  bDeviceProtocol;
   unsigned char  bMaxPacketSize0;            //8,16,32,64
   unsigned short idVendor;                    
   unsigned short idProduct;                   
   unsigned short bcdDevice;                    
   unsigned char  iManufacturer;
   unsigned char  iProduct;
   unsigned char  iSerialNumber;
   unsigned char  bNumconfigurations;
} USB_DEVICE_DESCRIPTOR,*PUSB_DEVICE_DESCRIPTOR;


typedef struct _USB_ENDPOINT_DESCRIPTOR{
   unsigned char  bLength;                    //07H
   unsigned char  bDescriptorType;            //05H
   unsigned char  bEndpointAddress;
   unsigned char  bmAttributes;
   unsigned short wMaxPacketSize;                    
   unsigned char  bInterval;
} USB_ENDPOINT_DESCRIPTOR,*PUSB_ENDPOINT_DESCRIPTOR;



typedef struct _USB_CONFIGURATION_DESCRIPTOR{
   unsigned char  bLength;                    //09H
   unsigned char  bDescriptorType;            //02H
   unsigned short wTotalLength;
   unsigned char  bNumInterface;
   unsigned char  bConfigurationValue;
   unsigned char  iConfiguration;
   unsigned char  bmAttributes;
   unsigned char  MaxPower;
} USB_CONFIGURATION_DESCRIPTOR,*PUSB_CONFIGURATION_DESCRIPTOR;

typedef struct _USB_INTERFACE_DESCRIPTOR{
   unsigned char bLength;                    //09H
   unsigned char bDescriptorType;            //04H
   unsigned char bInterfaceNumber;                 
   unsigned char bAlternateSetting;
   unsigned char bNumEndpoints;
   unsigned char bInterfaceClass;
   unsigned char bInterfaceSubClass;
   unsigned char bInterfaceProtocol;
   unsigned char iInterface;
} USB_INTERFACE_DESCRIPTOR,*PUSB_INTERFACE_DESCRIPTOR;


typedef struct _USB_STRING_DESCRIPTOR{
   unsigned char bLength;                    //03H
   unsigned char bDescriptorType;            //03H
   unsigned char bString;
} USB_STRING_DESCRIPTOR,*PUSB_STRING_DESCRIPTOR;


*/

/*USB power descriptor added to core specification*/

#define USB_SUPPORT_D0_COMMAND                   0x01
#define USB_SUPPORT_D1_COMMAND                   0x02
#define USB_SUPPORT_D2_COMMAND                   0x04
#define USB_SUPPORT_D3_COMMAND                   0x08

#define USB_SUPPORT_D1_WAKE                      0x10
#define USB_SUPPORT_D2_WAKE                      0x20


typedef struct _USB_POWER_DESCRIPTOR{
   unsigned char  bLength;                    
   unsigned char  bDescriptorType;           
   unsigned char  bCapabilitiesFlags;
   unsigned short EventNotification;                    
   unsigned short D1LatencyTime;
   unsigned short D2LatencyTime;
   unsigned short D3LatencyTime; 
   unsigned char  PowerUnit;         
   unsigned short D0PowerConsumption;                   
   unsigned short D1PowerConsumption;                   
   unsigned short D2PowerConsumption;                   
} USB_POWER_DESCRIPTOR,*PUSB_POWER_DESCRIPTOR;


typedef struct _USB_COMMON_DESCRIPTOR{
   unsigned char bLength;                    
   unsigned char bDescriptorType;           
} USB_COMMON_DESCRIPTOR,*PUSB_COMMON_DESCRIPTOR;


//Standard USB HUB definitions
//See Chapter 11
typedef struct _USB_HUB_DESCRIPTOR{
   unsigned char  bDescriptorLength;          //Length of this descriptor                    
   unsigned char  bDescriptorType;            //Hub configuration type
   unsigned char  bNumberOfPorts;             //Number of ports on this hub 
   unsigned short wHubCharacteristics;        //Hub Characteristics                  
   unsigned char  bPowerOnToPowerGood;        //Port power on till power good in 2ms
   unsigned char  bHubControlCurrent;         //Max current in mA
   unsigned char  bRemoveAndPowerMask[64];    //Room for 255 ports power control and removal bitmask
} USB_HUB_DESCRIPTOR,*PUSB_HUB_DESCRIPTOR;

/*###################################################################

                                masks 

  ###################################################################*/
#define USB_RECIPIENT                 (unsigned char)0x1F
#define USB_RECIPIENT_DEVICE          (unsigned char)0x00
#define USB_RECIPIENT_INTERFACE       (unsigned char)0x01
#define USB_RECIPIENT_ENDPOINT        (unsigned char)0x02
#define USB_REQUEST_TYPE_MASK         (unsigned char)0x60
#define USB_STANDARD_REQUEST          (unsigned char)0x00
#define USB_CLASS_REQUEST             (unsigned char)0x20
#define USB_VENDOR_REQUEST            (unsigned char)0x40

#define USB_REQUEST_MASK              (unsigned char)0x0F

#define DEVICE_ADDRESS_MASK           (unsigned char)0x7F

/*###################################################################

                          basic #defines 

  ###################################################################*/

#define MAX_ENDPOINTS     (unsigned char)0x03

#define EP0_TX_FIFO_SIZE    16
#define EP0_RX_FIFO_SIZE    16
#define EP0_PACKET_SIZE     16


#define EP1_TX_FIFO_SIZE    16
#define EP1_RX_FIFO_SIZE    16
#define EP1_PACKET_SIZE     16


#define EP2_TX_FIFO_SIZE    64
#define EP2_RX_FIFO_SIZE    64
#define EP2_PACKET_SIZE     64

#define USB_IDLE            0
#define USB_TRANSMIT        1
#define USB_RECEIVE         2

#define USB_CLASS_CODE_TEST_CLASS_DEVICE            0xDC
#define USB_SUBCLASS_CODE_TEST_CLASS_D12            0xA0
#define USB_PROTOCOL_CODE_TEST_CLASS_D12            0xB0


#endif   /*_USB100_H_*/








⌨️ 快捷键说明

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