📄 dc_struct.c.h
字号:
//#include "function.h"
//----------------------------------------------
#ifndef _DC_STRUCT_H
#define _DC_STRUCT_H
// Standard Chapter 9 definition
//----------------------------------------------
// 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_CONFIG 0x08
#define SET_CONFIG 0x09
#define GET_INTERFACE 0x0a
#define SET_INTERFACE 0x0b
#define SYNCH_FRAME 0x0c
// Descriptor Types
#define DEVICE 0x01
#define CONFIGURATION 0x02
#define STRING 0x03
#define INTERFACE 0x04
#define ENDPOINT 0x05
#define DEVICE_DES_LEN 18
#define CONFIG_DES_LEN 9
#define INTERFACE_DES_LEN 9
#define ENDPOINT_DES_LEN 7
#define CTRLEP 0
#define ISOEP 1
#define BULKEP 2
#define INTEP 3
#define USB_IDLE 0
#define USB_TRANSMIT 1
#define USB_RECEIVE 2
#define EP0MaxSize 64
#define TOTALLENGTH 9+9+8*7
#define SWAP(data) (data%256)|(data/256)<<8
#define MAX_CONTROLDATA_SIZE 64
#define EP0_PACKETSIZE 64
// Request
typedef struct device_request
{
unsigned char bmRequestType;
unsigned char bRequest;
unsigned short wValue;
unsigned short wIndex;
unsigned short wLength;
} USB_Device_Request;
/*
* Standard USB Descriptor Definitions
* Sec 9.6, page 261
*/
typedef struct std_dev_desc { /* Sec9.6.1, Table 9-8, p262 */
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short bcdUSB;
unsigned char bDeviceClass;
unsigned char bDeviceSubClass;
unsigned char bDeviceProtocol;
unsigned char bMaxPacketSize0;
unsigned short idVendor;
unsigned short idProduct;
unsigned short bcdDevice;
unsigned char iManufacturer;
unsigned char iProduct;
unsigned char iSerialNumber;
unsigned char bNumConfigurations;
}
std_dev_descriptor;
typedef struct dev_qual_desc { /* Sec 9.6.2, Table 9-9, p264 */
/* This is for Hi-speed */
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short bcdUSB;
unsigned char bDeviceClass;
unsigned char bDeviceSubClass;
unsigned char bDeviceProtocol;
unsigned char bMaxPacketSize0;
unsigned char bNumConfigurations;
}
dev_qualifier_descriptor;
typedef struct std_conf_desc { /* Sec9.6.3, Table 9-10, p265 */
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short wTotalLength;
// unsigned long wTotalLength; //??when defined unsigned short,the actual size is 8 word,instead of 9 word
unsigned char bNumInterfaces;
unsigned char bConfigurationValue;
unsigned char iConfiguration;
unsigned char bmAttributes;
unsigned char bMaxPower;
}
std_config_descriptor;
typedef struct std_if_desc { /* Sec9.6.5, Table 9-12, p268 */
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;
}
std_interface_descriptor;
typedef struct std_ep_desc { /* Sec9.6.6, Table 9-13, p269 */
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bEndpointAddress;
unsigned char bmAttributes;
unsigned short wMaxPacketSize;
unsigned char bInterval;
}
std_endpoint_descriptor;
typedef struct std_str_desc { /* Sec9.6.7, Table 9-15, p273 */
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short bString; // bString[ (254) >> 1 ];
}
std_string_descriptor;
std_dev_descriptor StdDevDesc1362={
DEVICE_DES_LEN, // bLength
DEVICE, // bDescriptorType
0, 2, // bcdUSB (USB Spec 2.0)
0, // bDeviceClass (0xFF = Vendor Specific)
0, // bDeviceSubClass
0, // bDeviceProtocol
64,// EP0MaxSize, // bMaxPacketSize0
#if 0
0x23, 0x01, // idVendor
0x67, 0x45, // idProduct define by myself
else
//#endif
//#if FINAL_TI_NUMBERS_TO_USE
0x0, 0x0, // idVendor TI USB PRODUCT CODES 0451, BBBB
0x0, 0x0, // idProduct
#endif
// 0x1C, 0x00, // idProduct
// 0x00, 0x1C,
0, 0, // bcdDevice
0, // iManufacturer - index of Manf String Descriptor
0, // iProduct - index of Product String Descriptor
0, // iSerialNumber - Index of Serial Number String
1
};
std_config_descriptor StdConfigDesc1362={
9, //bLength
CONFIGURATION, //bDescriptor Type
// TOTALELENGTH%256,
// TOTALELENGTH/256, //total data length include config,interface,endpoint
SWAP(TOTALLENGTH),
1, //bNumberInterfaces
0, //bConfiguration Value
0, //iConfiguration
0x40, //self powered.and not support remote wakeup.
//here need be in accrodance with DcHardwareConfig register
32 //MaxPower--100mA.????how to decide this value?here may need modify
};
std_interface_descriptor StdInterfaceDesc1362={
7, //bLength
INTERFACE, //bDescriptor Type
1, //bInterface Number
0, //bAlternate Setting
8, //bNumEndpoint--EP1-EP8
0, //bInterface Class
0, //bInterfaceSubClass
0, //bInterface Protocol
0 //iInterface
};
/*----------------------------------------*
EP1:out,sigle buffer,isochronous,1023 buffer size.
EP2:in, sigle buffer,isochronous,1023 bytes buffer size.
EP3:out,sigle buffer, interrupt, 16 bytes buffer size
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -