📄 usb.h.svn-base
字号:
#ifndef __USB_H__
#define __USB_H__
/*Standard RequestType (Direction)*/
#define HOST_TO_DEVICE 0x00
#define DEVICE_TO_HOST 0x80
/*Standard RequestType (Type)*/
#define STANDARD_TYPE 0x00
#define CLASS_TYPE 0x20
#define VENDOR_TYPE 0x40
#define RESERVED_TYPE 0x60
/*Standard RequestType (Recipient)*/
#define DEVICE_RECIPIENT 0x00
#define INTERFACE_RECIPIENT 0x01
#define ENDPOINT_RECIPIENT 0x02
#define OTHER_RECIPIENT 0x03
/*Feature Selectors*/
#define DEVICE_REMOTE_WAKEUP 0x01
#define EP_STALL 0x00
/*Standard Request Codes*/
#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
/*Class-specific Request Codes*/
#define GET_DEVICE_ID 0x00
#define GET_PORT_STATUS 0x01
#define SOFT_RESET 0x02
/*Descriptor Types*/
#define DEVICE_TYPE 0x01
#define CONFIGURATION_TYPE 0x02
#define STRING_TYPE 0x03
#define INTERFACE_TYPE 0x04
#define ENDPOINT_TYPE 0x05
/*Configuration Descriptor: bmAttributes*/
#define CONF_ATTR_DEFAULT 0x80
#define CONF_ATTR_REMOTE_WAKEUP 0x20
#define CONF_ATTR_SELFPOWERED 0x40
/*Endpoint Descriptor*/
#define EP_MODE_IN 0x80
#define EP_MODE_OUT 0x00
#define EP_ATTR_CONTROL 0x00
#define EP_ATTR_ISOCHRONOUS 0x01
#define EP_ATTR_BULK 0x02
#define EP_ATTR_INTERRUPT 0x03
/*String Descriptor*/
#define LANGID_US_L 0x09
#define LANGID_US_H 0x04
/*USB Setup Package*/
struct USB_SETUP_DATA
{
unsigned char bmRequestType;
unsigned char bRequest;
unsigned char bValueL;
unsigned char bValueH;
unsigned char bIndexL;
unsigned char bIndexH;
unsigned char bLengthL;
unsigned char bLengthH;
} __attribute__((packed));
/*USB Device Descriptor*/
struct USB_DEVICE_DESCRIPTOR
{
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bcdUSBL;
unsigned char bcdUSBH;
unsigned char bDeviceClass;
unsigned char bDeviceSubClass;
unsigned char bDeviceProtocol;
unsigned char bMaxPacketSize0;
unsigned char idVendorL;
unsigned char idVendorH;
unsigned char idProductL;
unsigned char idProductH;
unsigned char bcdDeviceL;
unsigned char bcdDeviceH;
unsigned char iManufacturer;
unsigned char iProduct;
unsigned char iSerialNumber;
unsigned char bNumConfigurations;
} __attribute__((packed));
struct USB_CONFIGURATION_DESCRIPTOR
{
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char wTotalLengthL;
unsigned char wTotalLengthH;
unsigned char bNumInterfaces;
unsigned char bConfigurationValue;
unsigned char iConfiguration;
unsigned char bmAttributes;
unsigned char maxPower;
} __attribute__((packed));
struct USB_INTERFACE_DESCRIPTOR
{
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bInterfaceNumber;
unsigned char bAlternateSetting;
unsigned char bNumEndpoints;
unsigned char bInterfaceClass;
unsigned char bInterfaceSubClass;
unsigned char bInterfaceProtocol;
unsigned char iInterface;
} __attribute__((packed));
struct USB_ENDPOINT_DESCRIPTOR
{
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bEndpointAddress;
unsigned char bmAttributes;
unsigned char wMaxPacketSizeL;
unsigned char wMaxPacketSizeH;
unsigned char bInterval;
} __attribute__((packed));
struct USB_CONFIGURATION_SET
{
unsigned char bConfigurationValue;
} __attribute__((packed));
struct USB_GET_STATUS
{
unsigned char bDevice;
unsigned char bInterface;
unsigned char bEndpoint0;
unsigned char bEndpoint1;
unsigned char bEndpoint3;
} __attribute__((packed));
struct USB_INTERFACE_GET
{
unsigned char bAlternateSetting;
} __attribute__((packed));
#define EP0_PKT_SIZE 0x08
#define EP1_PKT_SIZE BULK_PKT_SIZE
#define EP3_PKT_SIZE BULK_PKT_SIZE
void init_descriptor(void);
#endif /*__USB_H__*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -