小弟是个新手,在学习单片机c语言中遇到这样的东西,实在不知道是什么意思:
typedef code struct
{ }结构名;
typedef code BYTE aa;
还有就是在函数的前面加一个code. typedef我到是能明白,但是code的用法却不清楚,不知道在这些地方code的作用是什么??希望大家能帮忙说一下,谢谢
你说的是这个结构的名称就是code,是吧。
其实我说的这个东西是的原来的代码是这样的:
typedef code struct {
configuration_descriptor hid_configuration_descriptor;
interface_descriptor hid_interface_descriptor;
class_descriptor hid_descriptor;
endpoint_descriptor hid_endpoint_in_descriptor;
endpoint_descriptor hid_endpoint_out_descriptor;
}
hid_configuration_descriptor;
是别人在开发USB时定义的一种结构,但是我实在是不知道code的作用,去掉后编译就不能通过。
还有我上面说的另外的两种情况中code的意思,我也不清楚。
恩,谢谢。这个东西本身是在头文件中的,我看这样吧,文件本身不大,我把它贴出来,你也能看的清楚点。
#ifndef _USB_DESC_H_
#define _USB_DESC_H_
#ifndef _BYTE_DEF_
#define _BYTE_DEF_
typedef unsigned char BYTE;
#endif
#ifndef _WORD_DEF_ // Compiler Specific, written for Little Endian
#define _WORD_DEF_
typedef union {unsigned int i; unsigned char c[2];} WORD
#define LSB 1 // All words sent to and received from the host are
#define MSB 0 // little endian, this is switched by software when
// neccessary. These sections of code have been marked
// with "Compiler Specific" as above for easier modification
#endif
typedef /*code*/ struct
{
BYTE bLength; // Size of this Descriptor in Bytes 以字节为基本单位
BYTE bDescriptorType; // Descriptor Type (=1)
WORD 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
WORD idVendor; // Vendor ID
WORD idProduct; // Product ID
WORD 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
} device_descriptor; // End of Device Descriptor Type
//--------------------------------------------------
// Standard Configuration Descriptor Type Definition
//--------------------------------------------------
typedef /*code*/ struct
{
BYTE bLength; // Size of this Descriptor in Bytes
BYTE bDescriptorType; // Descriptor Type (=2)
WORD wTotalLength; // Total Length of Data for this Conf
BYTE bNumInterfaces; // No of Interfaces supported by this Conf
BYTE bConfigurationValue; // Designator Value for *this* Configuration
BYTE iConfiguration; // Index of String Desc for this Conf
BYTE bmAttributes; // Configuration Characteristics (see below)
BYTE bMaxPower; // Max. Power Consumption in this Conf (*2mA)
} configuration_descriptor; // End of Configuration Descriptor Type
//----------------------------------------------
// Standard Interface Descriptor Type Definition
//----------------------------------------------
typedef /*code*/ 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 (if any)
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 this Interface
} interface_descriptor; // End of Interface Descriptor Type
//------------------------------------------
// Standard Class Descriptor Type Definition
//------------------------------------------
typedef /*code */struct //
{
BYTE bLength; // Size of this Descriptor in Bytes (=9)
BYTE bDescriptorType; // Descriptor Type (HID=0x21)
WORD bcdHID; // HID Class Specification release number (=1.00)
BYTE bCountryCode; // Localized country code
BYTE bNumDescriptors; // Number of class descriptors to follow
BYTE bReportDescriptorType; // Report descriptor type (HID=0x22)
WORD wItemLength; // Total length of report descriptor table
} class_descriptor; // End of Class Descriptor Type
//---------------------------------------------
// Standard Endpoint Descriptor Type Definition
//---------------------------------------------
typedef /*code*/ 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)
WORD wMaxPacketSize; // Max. Endpoint Packet Size
BYTE bInterval; // Polling Interval (Interrupt) ms
} endpoint_descriptor; // End of Endpoint Descriptor Type
//---------------------------------------------
// HID Configuration Descriptor Type Definition
//---------------------------------------------
// From "USB Device Class Definition for Human Interface Devices (HID)".
// Section 7.1:
// "When a Get_Descriptor(Configuration) request is issued,
// it returns the Configuration descriptor, all Interface descriptors,
// all Endpoint descriptors, and the HID descriptor for each interface."
typedef code struct {
configuration_descriptor hid_configuration_descriptor; //HID类设备定义
interface_descriptor hid_interface_descriptor;
class_descriptor hid_descriptor;
endpoint_descriptor hid_endpoint_in_descriptor;
endpoint_descriptor hid_endpoint_out_descriptor;
}
hid_configuration_descriptor;
#define HID_REPORT_DESCRIPTOR_SIZE 0x001B
#define HID_REPORT_DESCRIPTOR_SIZE_LE 0x1B00
typedef code BYTE hid_report_descriptor[HID_REPORT_DESCRIPTOR_SIZE];
//-----------------------------
// Setup Packet Type Definition
//-----------------------------
typedef struct
{
BYTE bmRequestType; // Request recipient, type, and direction
BYTE bRequest; // Specific standard request number
WORD wValue; // varies according to request
WORD wIndex; // varies according to request
WORD wLength; // Number of bytes to transfer
} setup_buffer; // End of Setup Packet Type
#endif
我确实也没有看到有code的定义。另外,在另外的头文件中有
code const BYTE String0Desc[STR0LEN] =
{
STR0LEN, 0x03, 0x09, 0x04
}; 这里的code又是什么意思?都被code给搞糊涂了。