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

📄 usb_descriptor.h

📁 USB CDC using C8051F320/340, virtual COM port thru usb connection
💻 H
字号:
//-----------------------------------------------------------------------------
// USB_Descriptor.h
//-----------------------------------------------------------------------------

#ifndef USB_DESCRIPTORS_H
#define USB_DESCRIPTORS_H

//-----------------------------------------------------------------------------
// Definition of descriptors
//-----------------------------------------------------------------------------

//------------------------------------------
// Standard Descriptors
//------------------------------------------
//------------------------------------------
// Device Descriptor
//------------------------------------------
typedef struct {
	BYTE bLength;						// Size of this Descriptor in Bytes
	BYTE bDescriptorType;				// Descriptor Type (=1)
	UINT bcdUSB;						// USB Spec Release Number in BCD
	BYTE bDeviceClass;					// Device Class Code
	BYTE bDeviceSubClass;				// Device Subclass Code
	BYTE bDeviceProtocol;				// Device Protocol Code
	BYTE bMaxPacketSize0;				// Maximum Packet Size for EP0
	UINT idVendor;						// Vendor ID
	UINT idProduct;						// Product ID
	UINT bcdDevice;						// Device Release Number in BCD
	BYTE iManufacturer;					// Index of String Desc for Manufacturer
	BYTE iProduct;						// Index of String Desc for Product
	BYTE iSerialNumber;					// Index of String Desc for SerNo
	BYTE bNumConfigurations;			// Number of possible Configurations
} Tdevice_descriptor;

//--------------------------------------------------
// Configuration Descriptor
//--------------------------------------------------
typedef struct {
	BYTE bLength;						// Size of this Descriptor in Bytes
	BYTE bDescriptorType;				// Descriptor Type (=2)
	UINT wTotalLength;					// Total Length of Data for this Conf
	BYTE bNumInterfaces;				// number of Interfaces supported by Conf
	BYTE bConfigurationValue;			// Designator Value for *this* Conf
	BYTE iConfiguration;				// Index of String Desc for this Conf
	BYTE bmAttributes;					// Configuration Characteristics
	BYTE bMaxPower;						// Max. Power Consumption in Conf (*2mA)
} Tconfiguration_descriptor;

//----------------------------------------------
// Interface Descriptor
//----------------------------------------------
typedef struct {
	BYTE bLength;						// Size of this Descriptor in Bytes
	BYTE bDescriptorType;				// Descriptor Type (=4)
	BYTE bInterfaceNumber;				// Number of *this* Interface (0..)
	BYTE bAlternateSetting;				// Alternative for this Interface
	BYTE bNumEndpoints;					// No of EPs used by this IF (excl. EP0)
	BYTE bInterfaceClass;				// Interface Class Code
	BYTE bInterfaceSubClass;			// Interface Subclass Code
	BYTE bInterfaceProtocol;			// Interface Protocol Code
	BYTE iInterface;					// Index of String Desc for Interface
} Tinterface_descriptor;

//---------------------------------------------
// Endpoint Descriptor
//---------------------------------------------
typedef struct {
	BYTE bLength;						// Size of this Descriptor in Bytes
	BYTE bDescriptorType;				// Descriptor Type (=5)
	BYTE bEndpointAddress;				// Endpoint Address (Number + Direction)
	BYTE bmAttributes;					// Endpoint Attributes (Transfer Type)
	UINT wMaxPacketSize;				// Max. Endpoint Packet Size
	BYTE bInterval;						// Polling Interval (Interrupt) ms
} Tendpoint_descriptor;

//---------------------------------------------
// Interface Association Descriptor
//---------------------------------------------
typedef struct {
	BYTE bLength;						// Size of this Descriptor in Bytes
	BYTE bDescriptorType;				// Descriptor Type (=11)
	BYTE bFirstInterface;				// Interface number of the first one associated with this function
	BYTE bInterfaceCount;				// Numver of contiguous interface associated with this function
	BYTE bFunctionClass;				// The class triad of this interface,
	BYTE bFunctionSubClass;				//   usually same as the triad of the first interface
	BYTE bFunctionProcotol;
	BYTE iInterface;					// Index of String Desc for this function
} Tinterface_association_descriptor;

//---------------------------------------------
// Class specific descriptors for CDC
//---------------------------------------------
//---------------------------------------------
// Header Functional Descriptor
//---------------------------------------------
typedef struct {
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bDescriptorSubtype;
    UINT bcdCDC;
} Theader_func_descriptor;

//---------------------------------------------
// Call Management Functional Descriptor
//---------------------------------------------
typedef struct {
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bDescriptorSubtype;
    BYTE bmCapabilities;
    BYTE bDataInterface;
} Tcall_man_func_descriptor;

//---------------------------------------------
// Abstract Control Management Functional Descriptor
//---------------------------------------------
typedef struct {
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bDescriptorSubtype;
    BYTE bmCapabilities;
} Tabst_control_mana_descriptor;

//---------------------------------------------
// Union Functional Descriptor
//---------------------------------------------
typedef struct {
	BYTE bLength;
	BYTE bDescriptorType;
	BYTE bDescriptorSubtype;
	BYTE bMasterInterface;
	BYTE bSlaveInterface0;
} Tunion_func_descriptor;


//---------------------------------------------
// Class specific descriptors for HID
//---------------------------------------------
//---------------------------------------------
// HID class Descriptor
//---------------------------------------------
typedef struct {
	BYTE bLength;
	BYTE bDescriptorType;
	UINT bcdHID;
	BYTE bCountryCode;
	BYTE bNumDescriptors;
	BYTE bReportDescriptorType;
	UINT wReportDescriptorLength;
} THID_class_descriptor;


//---------------------------------------------
// Configuration Descriptor Set
//---------------------------------------------
typedef struct {
	Tconfiguration_descriptor				m_config_desc;
		Tinterface_descriptor				m_interface_desc_CDC_comm;
			Theader_func_descriptor			m_header_func_desc;
			Tcall_man_func_descriptor		m_call_man_desc;
			Tabst_control_mana_descriptor	m_abst_control_desc;
			Tunion_func_descriptor			m_union_func_desc;
			Tendpoint_descriptor			m_endpoint_desc_CDC_INT_IN;
		Tinterface_descriptor				m_interface_desc_CDC_data;
			Tendpoint_descriptor			m_endpoint_desc_CDC_BULK_IN;
			Tendpoint_descriptor			m_endpoint_desc_CDC_BULK_OUT;
} Tconfiguration_desc_set;

//---------------------------------------------
// Constants for  Descriptors
//---------------------------------------------

// Descriptor type
#define DSC_TYPE_DEVICE					0x01
#define DSC_TYPE_CONFIG					0x02
#define DSC_TYPE_STRING					0x03
#define DSC_TYPE_INTERFACE				0x04
#define DSC_TYPE_ENDPOINT				0x05
#define DSC_TYPE_IAD					0x0B

// Configuration descriptor: bmAttributes
#define DSC_CNFG_ATR_BASE				0x80	// D7: base attribute, always 1
#define DSC_CNFG_ATR_SELF_POWERED		0x40	// D6: bus-powered: 0, self-powered: 1, both: 1
#define DSC_CNFG_ATR_BUS_POWERED		0x00
#define DSC_CNFG_ATR_REMOTEWAKEUP		0x20	// D5: remote-wakeup disabled: 0, enabled: 1

// Configuration descriptor: bMaxPower
#define DSC_CNFG_MAXPOWER( x )			(((x) + 1) / 2)		// 1 unit = 2mA

// Endpoint transfer type
#define DSC_EP_CONTROL					0x00
#define DSC_EP_ISOC						0x01
#define DSC_EP_BULK						0x02
#define DSC_EP_INTERRUPT				0x03

// Endopoint address
#define EP1_OUT							0x01
#define EP2_OUT							0x02
#define EP3_OUT							0x03
#define EP1_IN							0x81
#define EP2_IN							0x82
#define EP3_IN							0x83

// Descriptor type (Class specific)
#define DSC_TYPE_CS_INTERFACE			0x24

// Descriptor type (Class specific) - CDC
#define DSC_SUBTYPE_CS_CDC_HEADER_FUNC	0x00
#define DSC_SUBTYPE_CS_CDC_CALL_MAN		0x01
#define DSC_SUBTYPE_CS_CDC_ABST_CNTRL	0x02
#define DSC_SUBTYPE_CS_CDC_UNION_FUNC	0x06

// Descriptor type (Class specific) - HID
#define DSC_SUBTYPE_CS_HID_CLASS		0x21
#define DSC_SUBTYPE_CS_HID_REPORT		0x22
#define DSC_SUBTYPE_CS_HID_PHYSICAL		0x23

//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------

extern Tdevice_descriptor code DeviceDesc;
extern Tconfiguration_desc_set code ConfigDescSet;
extern BYTE code * code StringDescTable[];
extern BYTE code StringDescNum;

// for HID descriptors
#define HID_IN_REPORT_SIZE				EP3_IN_PACKET_SIZE
#define HID_OUT_REPORT_SIZE				EP3_OUT_PACKET_SIZE

extern BYTE code HID_report_desc0[];
extern BYTE code HID_report_desc0_size;

#endif	// USB_DESCRIPTORS_H

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

⌨️ 快捷键说明

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