1 |
7 |
pradd |
const unsigned int USB_VENDOR_ID = 0x1234;
|
2 |
|
|
const unsigned int USB_PRODUCT_ID = 0x0001;
|
3 |
|
|
const char USB_SELF_POWER = 0x80; // Self powered 0xC0, 0x80 bus powered
|
4 |
|
|
const char USB_MAX_POWER = 50; // Bus power required in units of 2 mA
|
5 |
|
|
const char HID_INPUT_REPORT_BYTES = 64;
|
6 |
|
|
const char HID_OUTPUT_REPORT_BYTES = 64;
|
7 |
|
|
const char USB_TRANSFER_TYPE = 0x03; //0x03 Interrupt
|
8 |
|
|
//const char USB_TRANSFER_TYPE = 0x02; //0x02 Bulk
|
9 |
|
|
//const char USB_TRANSFER_TYPE = 0x01; //0x01 Isochrone
|
10 |
|
|
//const char USB_TRANSFER_TYPE = 0x00; //0x00 Controle
|
11 |
|
|
const char EP_IN_INTERVAL = 1;
|
12 |
|
|
const char EP_OUT_INTERVAL = 1;
|
13 |
|
|
|
14 |
|
|
const char USB_INTERRUPT = 0;
|
15 |
|
|
const char USB_HID_EP = 1;
|
16 |
|
|
const char USB_HID_RPT_SIZE = 33;
|
17 |
|
|
|
18 |
|
|
/* Device Descriptor */
|
19 |
|
|
const struct {
|
20 |
|
|
char bLength; // bLength - Descriptor size in bytes (12h)
|
21 |
|
|
char bDescriptorType; // bDescriptorType - The constant DEVICE (01h)
|
22 |
|
|
unsigned int bcdUSB; // bcdUSB - USB specification release number (BCD)
|
23 |
|
|
char bDeviceClass; // bDeviceClass - Class Code
|
24 |
|
|
char bDeviceSubClass; // bDeviceSubClass - Subclass code
|
25 |
|
|
char bDeviceProtocol; // bDeviceProtocol - Protocol code
|
26 |
|
|
char bMaxPacketSize0; // bMaxPacketSize0 - Maximum packet size for endpoint 0
|
27 |
|
|
unsigned int idVendor; // idVendor - Vendor ID
|
28 |
|
|
unsigned int idProduct; // idProduct - Product ID
|
29 |
|
|
unsigned int bcdDevice; // bcdDevice - Device release number (BCD)
|
30 |
|
|
char iManufacturer; // iManufacturer - Index of string descriptor for the manufacturer
|
31 |
|
|
char iProduct; // iProduct - Index of string descriptor for the product.
|
32 |
|
|
char iSerialNumber; // iSerialNumber - Index of string descriptor for the serial number.
|
33 |
|
|
char bNumConfigurations; // bNumConfigurations - Number of possible configurations
|
34 |
|
|
} device_dsc = {
|
35 |
|
|
0x12, // bLength
|
36 |
|
|
0x01, // bDescriptorType
|
37 |
|
|
0x0200, // bcdUSB
|
38 |
|
|
0x00, // bDeviceClass
|
39 |
|
|
0x00, // bDeviceSubClass
|
40 |
|
|
0x00, // bDeviceProtocol
|
41 |
|
|
8, // bMaxPacketSize0
|
42 |
|
|
USB_VENDOR_ID, // idVendor
|
43 |
|
|
USB_PRODUCT_ID, // idProduct
|
44 |
|
|
0x0001, // bcdDevice
|
45 |
|
|
0x01, // iManufacturer
|
46 |
|
|
0x02, // iProduct
|
47 |
|
|
0x00, // iSerialNumber
|
48 |
|
|
0x01 // bNumConfigurations
|
49 |
|
|
};
|
50 |
|
|
|
51 |
|
|
/* Configuration 1 Descriptor */
|
52 |
|
|
const char configDescriptor1[]= {
|
53 |
|
|
// Configuration Descriptor
|
54 |
|
|
0x09, // bLength - Descriptor size in bytes
|
55 |
|
|
0x02, // bDescriptorType - The constant CONFIGURATION (02h)
|
56 |
|
|
0x29,0x00, // wTotalLength - The number of bytes in the configuration descriptor and all of its subordinate descriptors
|
57 |
|
|
1, // bNumInterfaces - Number of interfaces in the configuration
|
58 |
|
|
1, // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
|
59 |
|
|
0, // iConfiguration - Index of string descriptor for the configuration
|
60 |
|
|
USB_SELF_POWER, // bmAttributes - Self/bus power and remote wakeup settings
|
61 |
|
|
USB_MAX_POWER, // bMaxPower - Bus power required in units of 2 mA
|
62 |
|
|
|
63 |
|
|
// Interface Descriptor
|
64 |
|
|
0x09, // bLength - Descriptor size in bytes (09h)
|
65 |
|
|
0x04, // bDescriptorType - The constant Interface (04h)
|
66 |
|
|
0, // bInterfaceNumber - Number identifying this interface
|
67 |
|
|
0, // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
|
68 |
|
|
2, // bNumEndpoint - Number of endpoints supported not counting endpoint zero
|
69 |
|
|
0x03, // bInterfaceClass - Class code
|
70 |
|
|
0, // bInterfaceSubclass - Subclass code
|
71 |
|
|
0, // bInterfaceProtocol - Protocol code
|
72 |
|
|
0, // iInterface - Interface string index
|
73 |
|
|
|
74 |
|
|
// HID Class-Specific Descriptor
|
75 |
|
|
0x09, // bLength - Descriptor size in bytes.
|
76 |
|
|
0x21, // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
|
77 |
|
|
0x01,0x01, // bcdHID - HID specification release number (BCD).
|
78 |
|
|
0x00, // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h.
|
79 |
|
|
1, // bNumDescriptors - Number of subordinate report and physical descriptors.
|
80 |
|
|
0x22, // bDescriptorType - The type of a class-specific descriptor that follows
|
81 |
|
|
USB_HID_RPT_SIZE,0x00, // wDescriptorLength - Total length of the descriptor identified above.
|
82 |
|
|
|
83 |
|
|
// Endpoint Descriptor
|
84 |
|
|
0x07, // bLength - Descriptor size in bytes (07h)
|
85 |
|
|
0x05, // bDescriptorType - The constant Endpoint (05h)
|
86 |
|
|
USB_HID_EP | 0x80, // bEndpointAddress - Endpoint number and direction
|
87 |
|
|
USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information
|
88 |
|
|
0x40,0x00, // wMaxPacketSize - Maximum packet size supported
|
89 |
|
|
EP_IN_INTERVAL, // bInterval - Service interval or NAK rate
|
90 |
|
|
|
91 |
|
|
// Endpoint Descriptor
|
92 |
|
|
0x07, // bLength - Descriptor size in bytes (07h)
|
93 |
|
|
0x05, // bDescriptorType - The constant Endpoint (05h)
|
94 |
|
|
USB_HID_EP, // bEndpointAddress - Endpoint number and direction
|
95 |
|
|
USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information
|
96 |
|
|
0x40,0x00, // wMaxPacketSize - Maximum packet size supported
|
97 |
|
|
EP_OUT_INTERVAL // bInterval - Service interval or NAK rate
|
98 |
|
|
};
|
99 |
|
|
|
100 |
|
|
const struct {
|
101 |
|
|
char report[USB_HID_RPT_SIZE];
|
102 |
|
|
}hid_rpt_desc =
|
103 |
|
|
{
|
104 |
|
|
{0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1)
|
105 |
|
|
0x09, 0x01, // Usage (Vendor Usage 1)
|
106 |
|
|
0xA1, 0x01, // Collection (Application)
|
107 |
|
|
// Input report
|
108 |
|
|
0x19, 0x01, // Usage Minimum
|
109 |
|
|
0x29, 0x40, // Usage Maximum
|
110 |
|
|
0x15, 0x00, // Logical Minimum (data bytes in the report may have minimum value = 0x00)
|
111 |
|
|
0x26, 0xFF, 0x00, // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
|
112 |
|
|
0x75, 0x08, // Report Size: 8-bit field size
|
113 |
|
|
0x95, HID_INPUT_REPORT_BYTES,// Report Count
|
114 |
|
|
0x81, 0x02, // Input (Data, Array, Abs)
|
115 |
|
|
// Output report
|
116 |
|
|
0x19, 0x01, // Usage Minimum
|
117 |
|
|
0x29, 0x40, // Usage Maximum
|
118 |
|
|
0x75, 0x08, // Report Size: 8-bit field size
|
119 |
|
|
0x95, HID_OUTPUT_REPORT_BYTES,// Report Count
|
120 |
|
|
0x91, 0x02, // Output (Data, Array, Abs)
|
121 |
|
|
0xC0} // End Collection
|
122 |
|
|
};
|
123 |
|
|
|
124 |
|
|
//Language code string descriptor
|
125 |
|
|
const struct {
|
126 |
|
|
char bLength;
|
127 |
|
|
char bDscType;
|
128 |
|
|
unsigned int string[1];
|
129 |
|
|
} strd1 = {
|
130 |
|
|
4,
|
131 |
|
|
0x03,
|
132 |
|
|
{0x0409}
|
133 |
|
|
};
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
//Manufacturer string descriptor
|
137 |
|
|
const struct{
|
138 |
|
|
char bLength;
|
139 |
|
|
char bDscType;
|
140 |
|
|
unsigned int string[16];
|
141 |
|
|
}strd2={
|
142 |
|
|
34, //sizeof this descriptor string
|
143 |
|
|
0x03,
|
144 |
|
|
{'M','i','k','r','o','e','l','e','k','t','r','o','n','i','k','a'}
|
145 |
|
|
};
|
146 |
|
|
|
147 |
|
|
//Product string descriptor
|
148 |
|
|
const struct{
|
149 |
|
|
char bLength;
|
150 |
|
|
char bDscType;
|
151 |
|
|
unsigned int string[23];
|
152 |
|
|
}strd3={
|
153 |
|
|
32, //sizeof this descriptor string
|
154 |
|
|
0x03,
|
155 |
|
|
{'U','S','B',' ','H','I','D',' ','L','i','b','r','a','r','y'}
|
156 |
|
|
};
|
157 |
|
|
|
158 |
|
|
//Array of configuration descriptors
|
159 |
|
|
const char* USB_config_dsc_ptr[1];
|
160 |
|
|
|
161 |
|
|
//Array of string descriptors
|
162 |
|
|
const char* USB_string_dsc_ptr[3];
|
163 |
|
|
|
164 |
|
|
void USB_Init_Desc(){
|
165 |
|
|
USB_config_dsc_ptr[0] = &configDescriptor1;
|
166 |
|
|
USB_string_dsc_ptr[0] = (const char*)&strd1;
|
167 |
|
|
USB_string_dsc_ptr[1] = (const char*)&strd2;
|
168 |
|
|
USB_string_dsc_ptr[2] = (const char*)&strd3;
|
169 |
|
|
}
|