📄 usb.h
字号:
#define uchar unsigned char
#define uint unsigned int
//STANDARD REQUEST CODES
#define GET_STATUS 0
#define CLEAR_FEATURE 1
#define SET_FEATURE 3
#define SET_ADDRESS 5
#define GET_DESCRIPTOR 6
#define SET_DESCRIPTOR 7
#define GET_CONFIGURATION 8
#define SET_CONFIGURATION 9
#define GET_INTERFACE 10
#define SET_INTERFACE 11
#define SYNCH_FRAME 12
//DESCRIPTOR TYPES
#define DEVICE 1
#define CONFIGURATION 2
#define STRING 3
#define INTERFACE 4
#define ENDPOINT 5
#define DEVICE_REMOTE_WAKEUP 1
#define ENDPOINT_HALT 0
//标准设备请求命令结构
typedef struct
{
uchar bmRequestType; //请求命令类型
uchar bRequest; //请求命令代码
uint wValue; //命令信息
uint wIndex; //索引信息
uint wLength; //传输数据大小
}
REQUEST, *pREQUEST;
//setup_packet缓冲区
#define MAX_CONTROL_DATA_SIZE 16
typedef struct
{
REQUEST DeviceRequest; //USB设备请求
uint wLength;
uint wCount;
uchar * pData;
uchar dataBuffer[MAX_CONTROL_DATA_SIZE];
}CONTROL_DATA_BUFF;
typedef struct
{
uchar bLength;
uchar bDescriptorType;
uint bcdUSB;
uchar bDeviceClass;
uchar bDeviceSubClass;
uchar bDevicePortocol;
uchar bMaxPacketSize0;
uint idVendor;
uint idProduct;
uint bcdDevice;
uchar iManufacturer;
uchar iProduct;
uchar iSerialNumber;
uchar bNumConfigurations;
}
DEVICE_DESCRIPTOR,*pDEVICE_DESCRIPTOR;
typedef struct
{
uchar bLength;
uchar bDescriptorType;
uint wTotalLength;
uchar bNumInterfaces;
uchar bConfigurationValue;
uchar iConfiguration;
uchar bmAttributes;
uchar MaxPower;
}
CONFIGURATION_DESCRIPTOR,*pCONFIGURATION_DESCRIPTOR;
typedef struct
{
uchar bLength;
uchar bDescriptorType;
uchar bInterfaceNumber;
uchar bAlternateSetting;
uchar bNumEndpoints;
uchar bInterfaceClass;
uchar bInterfaceSubClass;
uchar bInterfaceProtocol;
uchar iInterface;
}
INTERFACE_DESCRIPTOR,*pINTERFACE_DESCRIPTOR;
typedef struct
{
uchar bLength;
uchar bDescriptorType;
uchar bEndpointAddress;
uchar bmAttributes;
uint wMaxPacketSize;
uchar bInterval;
}
ENDPOINT_DESCRIPTOR,*pENDPOINT_DESCRIPTOR;
typedef union
{
struct
{
uchar timer : 1;
uchar bus_reset : 1; //总线复位标志
uchar suspend : 1; //挂起改变标志
uchar setup_packet : 1; //收到SETUP包
uchar remote_wakeup : 1; //远程唤醒标志(未使用)
uchar in_isr : 1; //USB中断服务标志
uchar control_state : 2; //控制端点处理标志
//0: IDLE 空闲状态
//1: TRANSMIT 数据发送状态
//2: RECEIVE 数据接收状态
uchar configuration : 1; //配置标志(0: 未配置; 1: 已经配置)
uchar command : 1; //未使用
uchar ep1_rxdone : 1; //端点 1 收到数据标志
uchar ep2_rxdone : 1; //端点 2 收到数据标志
uchar ep1buf_full : 1;
uchar ep2buf_full : 1; //端点 2 接收双缓冲区满标志
}bits;
uint sbyte;
}
USBFLAG;
typedef union
{
struct
{
uchar reset:1;
uchar ctrl_out:1;
uchar ctrl_in:1;
uchar endp0_out:1;
uchar endp1_in:1;
uchar main_out:1;
uchar main_in:1;
uchar bus_reset:1;
uchar hold:1;
uchar DMA_EOT:1;
uchar re:7;
}int_flag;
uint ctrl;
}D12_STATUS;
extern CONTROL_DATA_BUFF controldata;
extern USBFLAG flag;
D12_STATUS d12_status;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -