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

📄 usb_descriptor.c

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

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include "USB_Type.h"
#include "USB_Configuration.h"
#include "USB_Descriptor.h"

//-----------------------------------------------------------------------------
// Macro for two byte field
//-----------------------------------------------------------------------------

#if defined BIG_ENDIAN
#define LE(x)	((((x)&0x00FF)<<8)|(((x)&0xFF00)>>8))	// convert to little endian
#else
#define LE(x)	(x)										// no conversion
#endif

//-----------------------------------------------------------------------------
// Descriptor Declarations
//-----------------------------------------------------------------------------

//
// Device descriptor
//
Tdevice_descriptor code DeviceDesc =
{
	sizeof(Tdevice_descriptor),				// bLength
	DSC_TYPE_DEVICE,						// bDescriptorType
	LE( VER_USB ),							// bcdUSB
	0x02,									// bDeviceClass (Communication Class)	0x00,									// bDeviceSubClass
	0x00,									// bDeviceProtocol
	EP0_PACKET_SIZE,						// bMaxPacketSize0
	LE( VID ),								// idVendor
	LE( PID ),								// idProduct
	LE( DEV_REV ),							// bcdDevice
	0x01,									// iManufacturer
	0x02,									// iProduct
	0x03,									// iSerialNumber
	0x01,									// bNumConfigurations
}; //end of DeviceDesc

//
// Configuration descriptor
//
Tconfiguration_desc_set code ConfigDescSet =
{
  {										// Configuration descriptor
	sizeof(Tconfiguration_descriptor),		// bLength
	DSC_TYPE_CONFIG,						// bDescriptorType
	LE( sizeof(Tconfiguration_desc_set) ),	// bTotalLength
	DSC_NUM_INTERFACE,						// bNumInterfaces
	0x01,									// bConfigurationValue
	0x00,									// iConfiguration
	  DSC_CNFG_ATR_BASE						// bmAttributes
	| DSC_CNFG_ATR_BUS_POWERED,
	DSC_CNFG_MAXPOWER( 100 ),				// bMaxPower (mA)
											// <= 100mA: Low power
											// <= 500mA: High power
  },

  {										// Interface 0 - CDC Communication Class
	sizeof(Tinterface_descriptor),			// bLength
	DSC_TYPE_INTERFACE,						// bDescriptorType
	DSC_INTERFACE_CDC_comm,					// bInterfaceNumber
	0x00,									// bAlternateSetting
	0x01,									// bNumEndpoints
	0x02,									// bInterfaceClass (Communication Class)
	0x02,									// bInterfaceSubClass (Abstract Control Model)
	0x01,									// bInterfaceProcotol (V.25ter, Common AT commands)
	0x00,									// iInterface
  },
  {										// Header Functional Descriptor
	sizeof(Theader_func_descriptor),		// bLength
	DSC_TYPE_CS_INTERFACE,					// bDescriptorType (CS_INTERFACE)
	DSC_SUBTYPE_CS_CDC_HEADER_FUNC,			// bDescriptorSubtype (Header Functional)
	LE(0x0110),								// bcdCDC (CDC spec release number, 1.1)
  },
  {										// Call Management Functional Descriptor
	sizeof(Tcall_man_func_descriptor),		// bLength
	DSC_TYPE_CS_INTERFACE,					// bDescriptorType (CS_INTERFACE)
	DSC_SUBTYPE_CS_CDC_CALL_MAN,			// bDescriptorSubtype (Call Management)
	0x01,									// bmCapabilities (only over Communication Class IF / handles itself)
	DSC_INTERFACE_CDC_data,					// bDataInterface (Interface number of Data Class interface)
  },
  {										// Abstract Control Management Functional Descriptor
	sizeof(Tabst_control_mana_descriptor),	// bLength
	DSC_TYPE_CS_INTERFACE,					// bDescriptorType (CS_INTERFACE)
	DSC_SUBTYPE_CS_CDC_ABST_CNTRL,			// bDescriptorSubtype (Abstract Control Management)
	0x06,									// bmCapabilities (Supports Send_Break, Set_Line_Coding, Set_Control_Line_State,
											//					Get_Line_Coding, and the notification Serial_State)
  },
  {										// Union Functional Descriptor
	sizeof(Tunion_func_descriptor),			// bLength
	DSC_TYPE_CS_INTERFACE,					// bDescriptorType (CS_INTERFACE)
	DSC_SUBTYPE_CS_CDC_UNION_FUNC,			// bDescriptorSubtype (Union Functional)
	DSC_INTERFACE_CDC_comm,					// bMasterInterface (Interface number master interface in the union)
	DSC_INTERFACE_CDC_data,					// bSlaveInterface0 (Interface number slave interface in the union)
  },
  {										// Endpoint1
	sizeof(Tendpoint_descriptor),			// bLength
	DSC_TYPE_ENDPOINT,						// bDescriptorType
	EP1_IN,									// bEndpointAddress
	DSC_EP_INTERRUPT,						// bmAttributes
	LE( EP1_IN_PACKET_SIZE ),				// MaxPacketSize
	1										// bInterval
  },

  {										// Interface 1 - CDC Data Interface Class
	sizeof(Tinterface_descriptor),			// bLength
	DSC_TYPE_INTERFACE, 					// bDescriptorType
	DSC_INTERFACE_CDC_data,					// bInterfaceNumber
	0x00,									// bAlternateSetting
	0x02,									// bNumEndpoints
	0x0A,									// bInterfaceClass (Data Interface Class)
	0x00,									// bInterfaceSubClass
	0x00,									// bInterfaceProcotol (No class specific protocol required)
	0x00									// iInterface
  },
  {										// Endpoint IN 2 descriptor
	sizeof(Tendpoint_descriptor),			// bLength
	DSC_TYPE_ENDPOINT,						// bDescriptorType
	EP2_IN,									// bEndpointAddress
	DSC_EP_BULK,							// bmAttributes
	LE( EP2_IN_PACKET_SIZE ),				// MaxPacketSize
	0										// bInterval
  },
  {										// Endpoint OUT 2 descriptor
	sizeof(Tendpoint_descriptor),			// bLength
	DSC_TYPE_ENDPOINT,						// bDescriptorType
	EP2_OUT,								// bEndpointAddress
	DSC_EP_BULK,							// bmAttributes
	LE( EP2_OUT_PACKET_SIZE ),				// MaxPacketSize
	0										// bInterval
  },

}; //end of Configuration

//
// String descriptors
//

#define STR0LEN 4

static BYTE code String0Desc[STR0LEN] =
{
	STR0LEN, DSC_TYPE_STRING, 0x09, 0x04
}; //end of String0Desc

#define STR1LEN sizeof("SILICON LABORATORIES INC.")*2

static BYTE code String1Desc[STR1LEN] =
{
	STR1LEN, DSC_TYPE_STRING,
	'S', 0,
	'I', 0,
	'L', 0,
	'I', 0,
	'C', 0,
	'O', 0,
	'N', 0,
	' ', 0,
	'L', 0,
	'A', 0,
	'B', 0,
	'O', 0,
	'R', 0,
	'A', 0,
	'T', 0,
	'O', 0,
	'R', 0,
	'I', 0,
	'E', 0,
	'S', 0,
	' ', 0,
	'I', 0,
	'N', 0,
	'C', 0,
	'.', 0
}; //end of String1Desc

#define STR2LEN sizeof("C8051F320 Development Board")*2

static BYTE code String2Desc[STR2LEN] =
{
	STR2LEN, DSC_TYPE_STRING,
	'C', 0,
	'8', 0,
	'0', 0,
	'5', 0,
	'1', 0,
	'F', 0,
	'3', 0,
	'2', 0,
	'0', 0,
	' ', 0,
	'D', 0,
	'e', 0,
	'v', 0,
	'e', 0,
	'l', 0,
	'o', 0,
	'p', 0,
	'm', 0,
	'e', 0,
	'n', 0,
	't', 0,
	' ', 0,
	'B', 0,
	'o', 0,
	'a', 0,
	'r', 0,
	'd', 0
}; //end of String2Desc

// serial number string

#define STR3LEN sizeof("0001")*2

static BYTE code String3Desc[STR3LEN] =
{
	STR3LEN, DSC_TYPE_STRING,
	'0', 0,
	'0', 0,
	'0', 0,
	'1', 0
}; //end of String3Desc

BYTE code * code StringDescTable[] =
{
	String0Desc,
	String1Desc,
	String2Desc,
	String3Desc
};

BYTE code StringDescNum = sizeof( StringDescTable ) / sizeof( StringDescTable[0] );

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

⌨️ 快捷键说明

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