📄 msusb.h
字号:
#ifndef __MSUSB_H_
#define __MSUSB_H_
/*
* Standard requests
*/
#define USB_REQ_GET_STATUS 0x00
#define USB_REQ_CLEAR_FEATURE 0x01
#define USB_REQ_SET_FEATURE 0x03
#define USB_REQ_SET_ADDRESS 0x05
#define USB_REQ_GET_DESCRIPTOR 0x06
#define USB_REQ_SET_DESCRIPTOR 0x07
#define USB_REQ_GET_CONFIGURATION 0x08
#define USB_REQ_SET_CONFIGURATION 0x09
#define USB_REQ_GET_INTERFACE 0x0A
#define USB_REQ_SET_INTERFACE 0x0B
#define USB_REQ_SYNCH_FRAME 0x0C
/*
* USB Packet IDs (PIDs)
*/
#define USB_PID_OUT 0xe1
#define USB_PID_ACK 0xd2
#define USB_PID_IN 0x69
#define USB_PID_STALL 0x1e
#define USB_ENDPOINT_DIR_MASK 0x80
#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
#define USB_ENDPOINT_XFER_BULK 2
#define USB_ENDPOINT_XFER_INT 3
#define USB_ST_NOERROR 0
#define USB_ST_NORESPONSE 0xfc
#define USB_ST_STALL 0xec
#define USB_DIR_OUT 0
#define USB_DIR_IN 0x80
#define USB_TYPE_MASK (0x03 << 5)
#define USB_TYPE_STANDARD (0x00 << 5)
#define USB_TYPE_CLASS (0x01 << 5)
#define USB_TYPE_VENDOR (0x02 << 5)
#define USB_TYPE_RESERVED (0x03 << 5)
#define USB_RECIP_MASK 0x1f
#define USB_RECIP_DEVICE 0x00
#define USB_RECIP_INTERFACE 0x01
#define USB_RECIP_ENDPOINT 0x02
#define USB_RECIP_OTHER 0x03
#define EP0C_SET_ADDRESS 1 /* 1st enum cmd is to set dev address */
#define EP0C_GET_MAX_EP0 2 /* fetch functions max EP0, 1st enum req */
#define EP0C_GET_STD_DEV_DESC 3 /* 2nd enum req, get std descriptor */
#define EP0C_GET_CONFIG 4 /* read config descriptor only */
#define EP0C_GET_FULL_CONFIG 5 /* read entire config descriptor */
#define EP0C_SET_CONFIG 6 /* set config 0 prior to probe */
#define EP0C_SET_FEATURE 7 /* set a feature, like OTG */
#define EP0C_CLEAR_FEATURE 8 /* set a feature, like OTG */
#define USB_DT_DEVICE 0x01
#define USB_DT_CONFIG 0x02
#define USB_DT_STRING 0x03
#define USB_DT_INTERFACE 0x04
#define USB_DT_ENDPOINT 0x05
#define USB_DT_DEVICE_QUALIFIER 0x06
#define USB_DT_OTHER_SPEED 0X07
#define USB_DT_INTERFACE_POWER 0x08
#define USB_DT_OTG 0x09
#define USB_DT_DEVICE_SIZE 18
#define USB_DT_DEVICE_QUALIFIER_SIZE 10
#define USB_DT_CONFIG_SIZE 9
#define USB_DT_INTERFACE_SIZE 9
#define USB_DT_ENDPOINT_SIZE 7
#define USB_DT_OTG_SIZE 3
#define USB_OTG_SRP 0x01 /* bit 0 of bmAttributes */
#define USB_OTG_HNP 0x02 /* bit 1 of bmAttributes */
#define MAX_BITS_BYTE (8)
#define MAX_BITS_SHORT (16)
#define MAX_BITS_3BYTE (24)
#define MAX_BITS_INT (32)
#define POSITION_VALUE_8 (0x100)
#define POSITION_VALUE_16 (__u32)(0x10000)
#define POSITION_VALUE_24 (__u32)(0x1000000)
#define BIT_MASK(n) ( ~(~(0L)<<n) )
#define ENDPOINT_HALT 0x00
#define MSD_BOT_CSW_LENGTH 0x0D
#define MSD_BOT_CBW_LENGTH 0x1F
#define MSD_BOT_CBW_CB_LENGTH 0x10
#define usb_pipein(pipe) (((pipe) >> PIPEDEF_DIR) & 1)
#define usb_pipeendpoint(pipe) (((pipe) >> PIPEDEF_EP) & 0xf)
#define usb_pipetype(pipe) (((pipe) >> PIPEDEF_ATTR) & 3)
#define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
#define usb_sndctrlpipe(endpoint) ((PIPE_CONTROL << PIPEDEF_ATTR) | \
(PIPE_OUT << PIPEDEF_DIR) | (((endpoint) << PIPEDEF_EP) &0xf))
#define usb_rcvctrlpipe(endpoint) ((PIPE_CONTROL << PIPEDEF_ATTR) | \
(PIPE_IN << PIPEDEF_DIR) | (((endpoint) << PIPEDEF_EP) &0xf))
#define usb_sndbulkpipe(endpoint) ((PIPE_BULK << PIPEDEF_ATTR) | \
(PIPE_OUT << PIPEDEF_DIR) | (((endpoint) << PIPEDEF_EP) &0xf))
#define usb_rcvbulkpipe(endpoint) ((PIPE_BULK << PIPEDEF_ATTR) | \
(PIPE_IN << PIPEDEF_DIR) | (((endpoint) << PIPEDEF_EP) &0xf))
/* All standard descriptors have these 2 fields in common */
typedef struct {
__s8 bLength;
__s8 bDescriptorType;
} usb_descriptor_header;
/* All standard descriptors have these 2 fields in common */
struct devrequest{
__u8 bmRequestType;
__u8 bRequest;
__u16 wValue;
__u16 wIndex;
__u16 wLength;
};
/* Device descriptor */
struct usb_device_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u16 bcdUSB;
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
__u8 bMaxPacketSize0;
__u16 idVendor;
__u16 idProduct;
__u16 bcdDevice;
__u8 iManufacturer;
__u8 iProduct;
__u8 iSerialNumber;
__u8 bNumConfigurations;
};
/* Endpoint descriptor */
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u8 bEndpointAddress;
__u8 bmAttributes;
__u16 wMaxPacketSize;
__u8 bInterval;
__u8 bRefresh;
__u8 bSynchAddress;
__u8 *extra; /* Extra descriptors */
__s32 extralen;
} usb_endpoint_descriptor;
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u8 bEndpointAddress;
__u8 bmAttributes;
__u16 wMaxPacketSize;
__u8 bInterval;
} usb_function_endpoint_descriptor;
/* Interface descriptor */
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u8 bInterfaceNumber;
__u8 bAlternateSetting;
__u8 bNumEndpoints;
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
__u8 iInterface;
usb_endpoint_descriptor *endpoint;
__u8 *extra; /* Extra descriptors */
__s32 extralen;
} usb_interface_descriptor;
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u8 bInterfaceNumber;
__u8 bAlternateSetting;
__u8 bNumEndpoints;
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
__u8 iInterface;
} usb_function_interface_descriptor;
typedef struct {
usb_interface_descriptor *altsetting;
__s32 act_altsetting; /* active alternate setting */
__s32 num_altsetting; /* number of alternate settings */
__s32 max_altsetting; /* total memory allocated */
struct usb_driver *driver; /* driver */
void *private_data;
} usb_interface;
/* Configuration descriptor information.. */
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u16 wTotalLength;
__u8 bNumInterfaces;
__u8 bConfigurationValue;
__u8 iConfiguration;
__u8 bmAttributes;
__u8 MaxPower;
usb_interface *interface;
__u8 *extra; /* Extra descriptors */
__s32 extralen;
} usb_config_descriptor;
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u16 wTotalLength;
__u8 bNumInterfaces;
__u8 bConfigurationValue;
__u8 iConfiguration;
__u8 bmAttributes;
__u8 bMaxPower;
} usb_function_config_descriptor;
/* String descriptor */
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u16 wData[1];
} usb_string_descriptor;
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u8 bmAttributes; /* bit 0=SRP; bit 1=HNP */
} usb_otg_descriptor;
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u16 bcdHID;
__u8 bCountryCode;
__u8 bNumDescriptors;
__u8 bClassDescriptorType;
__u16 wDescriptorLength;
} usb_hid_descriptor;
typedef struct {
__u8 bDescriptorType;
__u16 wDescriptorLength;
} hid_optional_descriptor;
typedef struct {
__u8 bLength;
__u8 bDescriptorType;
__u16 bcdUSB;
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
__u8 bMaxPacketSize0;
__u8 bNumConfigurations;
__u8 bRESERVED;
} usb_qualifier_descriptor;
struct usb_device{
__u8 core;
struct usb_device_descriptor descriptor;/* Descriptor */
usb_config_descriptor *config; /* All of the configs */
usb_config_descriptor *actconfig;/* the active configuration */
__s8 **rawdescriptors; /* Raw descriptors for each config */
};
void otgInitMassBuffer(void);
void OTGUSBInitial(__u32 xdataaddr,__u8 Device_Mode_Type);
void usbChange_USB_State(__u8 toUSB);
void usbSWOP_Setup(struct devrequest *sP);
void usbSWOP_Device_Descriptor(void *vP);
void usbSWOP_Endpoint_Descriptor(void *vP);
void usbSWOP_Config_Descriptor(void *vP);
void USB_Send_Stall (__u8 ep);
__u8 usbIsUSBConfiged(void);
extern __u8 usbCBW[];
extern __u8 usbCSW[];
extern __u8 usbMass_Data_Buffer[];
extern __u32 *usbMass_Data_Buffer_Addr ;
extern __u32 *usbCSW_Addr;
extern __u32 *usbCBW_Addr;
extern __u32 *usbCBWCB_Addr;
#endif /* __MSUSB_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -