3325 |
kaklik |
1 |
/////////////////////////////////////////////////////////////////////////// |
|
|
2 |
/// usbconfig.h //// |
|
|
3 |
//// //// |
|
|
4 |
//// An example set of device / configuration descriptors. //// |
|
|
5 |
//// This set works exclusively with ex_usb_mouse.c example. //// |
|
|
6 |
//// //// |
|
|
7 |
/////////////////////////////////////////////////////////////////////////// |
|
|
8 |
//// //// |
|
|
9 |
//// Version History: //// |
|
|
10 |
//// //// |
|
|
11 |
//// March 5th, 2009: //// |
|
|
12 |
//// Cleanup for Wizard. //// |
|
|
13 |
//// PIC24 Initial release. //// |
|
|
14 |
//// //// |
|
|
15 |
//// June 20th, 2005: //// |
|
|
16 |
//// Initial 18Fxx5x release //// |
|
|
17 |
//// //// |
|
|
18 |
//// March 21st, 2005: //// |
|
|
19 |
//// EP 0x81 now uses USB_EP1_TX_SIZE to define max packet size, to //// |
|
|
20 |
//// make it easier for dynamically changed code. //// |
|
|
21 |
//// EP 0x81 will now use 1ms polling interval if using a full speed //// |
|
|
22 |
//// device. //// |
|
|
23 |
//// //// |
|
|
24 |
//// June 24th, 2002: Cleanup //// |
|
|
25 |
//// //// |
|
|
26 |
/////////////////////////////////////////////////////////////////////////// |
|
|
27 |
//// (C) Copyright 1996,2005 Custom Computer Services //// |
|
|
28 |
//// This source code may only be used by licensed users of the CCS //// |
|
|
29 |
//// C compiler. This source code may only be distributed to other //// |
|
|
30 |
//// licensed users of the CCS C compiler. No other use, //// |
|
|
31 |
//// reproduction or distribution is permitted without written //// |
|
|
32 |
//// permission. Derivative programs created using this software //// |
|
|
33 |
//// in object code form are not restricted in any way. //// |
|
|
34 |
/////////////////////////////////////////////////////////////////////////// |
|
|
35 |
|
|
|
36 |
#IFNDEF __USB_DESCRIPTORS__ |
|
|
37 |
#DEFINE __USB_DESCRIPTORS__ |
|
|
38 |
|
|
|
39 |
///////// config options, although it's best to leave alone for this demo ///// |
|
|
40 |
#define USB_CONFIG_PID 0xc631 |
|
|
41 |
#define USB_CONFIG_VID 0x0403 |
|
|
42 |
#define USB_CONFIG_BUS_POWER 100 //100mA (range is 0..500) |
|
|
43 |
#define USB_CONFIG_VERSION 0x0205 //01.00 //range is 00.00 to 99.99 |
|
|
44 |
//////// end config /////////////////////////////////////////////////////////// |
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
#DEFINE USB_HID_DEVICE TRUE //Tells the CCS PIC USB firmware |
|
|
49 |
//to include HID handling code. |
|
|
50 |
|
|
|
51 |
//turn on EP1 for IN interrupt transfers. (IN = PIC -> PC) |
|
|
52 |
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT |
|
|
53 |
|
|
|
54 |
#define USB_EP1_TX_SIZE 8 //max packet size of this endpoint |
|
|
55 |
|
|
|
56 |
#include <usb.h> |
|
|
57 |
|
|
|
58 |
////////////////////////////////////////////////////////////////// |
|
|
59 |
/// |
|
|
60 |
/// HID Report. Tells HID driver how to handle and deal with |
|
|
61 |
/// received data. HID Reports can be extremely complex, |
|
|
62 |
/// see HID specifcation for help on writing your own. |
|
|
63 |
/// |
|
|
64 |
/// This examples configures HID driver to take received data |
|
|
65 |
/// as mouse x, y and button data. |
|
|
66 |
/// |
|
|
67 |
////////////////////////////////////////////////////////////////// |
|
|
68 |
|
|
|
69 |
const char USB_CLASS_SPECIFIC_DESC[] = |
|
|
70 |
{ |
|
|
71 |
0x05, 0x01, // usage page (generic desktop Choose the usage page "mouse" is on |
|
|
72 |
0x09, 0x02, // usage (mouse) Device is a mouse |
|
|
73 |
0xA1, 0x01, // collection (application) This collection encompasses the report format |
|
|
74 |
0x09, 0x01, // usage (pointer) Choose the key code usage page |
|
|
75 |
0xA1, 0x00, // collection (physical) Physical collection |
|
|
76 |
0x05, 0x09, // usage page (buttons) Choose the button usage page |
|
|
77 |
0x19, 0x01, // usage minimum (1) There are three buttons |
|
|
78 |
0x29, 0x03, // usage maximum (3) |
|
|
79 |
0x15, 0x00, // logical minimum (0) Each button is represented by one bit |
|
|
80 |
0x25, 0x01, // logical maximum (1) |
|
|
81 |
0x95, 0x03, // report count (3) Three reports, one bit each |
|
|
82 |
0x75, 0x01, // report size (1) |
|
|
83 |
0x81, 0x02, // input (data, variable, absolute) Defined bits above are data bits |
|
|
84 |
0x95, 0x01, // report count (1) One report, five bits in length |
|
|
85 |
0x75, 0x05, // report size (5) |
|
|
86 |
0x81, 0x01, // input (constant) Bit stuff to fill byte |
|
|
87 |
0x05, 0x01, // usage page (generic desktop) Choose the usage pare X and Y are on |
|
|
88 |
0x09, 0x30, // usage (X) X direction of pointer |
|
|
89 |
0x09, 0x31, // usage (Y) Y direction of pointer |
|
|
90 |
0x09, 0x38 // usage (wheel) |
|
|
91 |
0x15, 0x81, // logical minimum (-127) Range of report data is -127 to 127 |
|
|
92 |
0x25, 0x7F, // logical maximum (127) |
|
|
93 |
0x75, 0x08, // report size (8) Two reports, eight bits each |
|
|
94 |
0x95, 0x03, // report count (3) |
|
|
95 |
0x81, 0x06, // input (data, variable, absolute) Defined bits above are data bits |
|
|
96 |
0xC0, // end collection End physical collection |
|
|
97 |
0xC0 // end collection End application collection |
|
|
98 |
}; |
|
|
99 |
|
|
|
100 |
//if a class has an extra descriptor not part of the config descriptor, |
|
|
101 |
// this lookup table defines where to look for it in the const |
|
|
102 |
// USB_CLASS_SPECIFIC_DESC[] array. |
|
|
103 |
//first element is the config number (if your device has more than one config) |
|
|
104 |
//second element is which interface number |
|
|
105 |
//set element to 0xFFFF if this config/interface combo doesn't exist |
|
|
106 |
const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP[USB_NUM_CONFIGURATIONS][1] = |
|
|
107 |
{ |
|
|
108 |
//config 1 |
|
|
109 |
//interface 0 |
|
|
110 |
|
|
|
111 |
}; |
|
|
112 |
|
|
|
113 |
//if a class has an extra descriptor not part of the config descriptor, |
|
|
114 |
// this lookup table defines the size of that descriptor. |
|
|
115 |
//first element is the config number (if your device has more than one config) |
|
|
116 |
//second element is which interface number |
|
|
117 |
//set element to 0xFFFF if this config/interface combo doesn't exist |
|
|
118 |
const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[USB_NUM_CONFIGURATIONS][1] = |
|
|
119 |
{ |
|
|
120 |
//config 1 |
|
|
121 |
//interface 0 |
|
|
122 |
sizeof(USB_CLASS_SPECIFIC_DESC) |
|
|
123 |
}; |
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
////////////////////////////////////////////////////////////////// |
|
|
128 |
/// |
|
|
129 |
/// start config descriptor |
|
|
130 |
/// right now we only support one configuration descriptor. |
|
|
131 |
/// the config, interface, class, and endpoint goes into this array. |
|
|
132 |
/// |
|
|
133 |
////////////////////////////////////////////////////////////////// |
|
|
134 |
|
|
|
135 |
#DEFINE USB_TOTAL_CONFIG_LEN 34 //config+interface+class+endpoint |
|
|
136 |
|
|
|
137 |
const char USB_CONFIG_DESC[] = { |
|
|
138 |
//IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE: |
|
|
139 |
// config(s) |
|
|
140 |
// interface(s) |
|
|
141 |
// class(es) |
|
|
142 |
// endpoint(s) |
|
|
143 |
|
|
|
144 |
//config_descriptor for config index 1 |
|
|
145 |
USB_DESC_CONFIG_LEN, //length of descriptor size ==1 |
|
|
146 |
USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==2 |
|
|
147 |
USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==3,4 |
|
|
148 |
1, //number of interfaces this device supports ==5 |
|
|
149 |
0x01, //identifier for this configuration. (IF we had more than one configurations) ==6 |
|
|
150 |
0x00, //index of string descriptor for this configuration ==7 |
|
|
151 |
#if USB_CONFIG_BUS_POWER |
|
|
152 |
0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==8 |
|
|
153 |
#else |
|
|
154 |
0x80, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==8 |
|
|
155 |
#endif |
|
|
156 |
USB_CONFIG_BUS_POWER/2, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==9 |
|
|
157 |
|
|
|
158 |
//interface descriptor 1 |
|
|
159 |
USB_DESC_INTERFACE_LEN, //length of descriptor =10 |
|
|
160 |
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =11 |
|
|
161 |
0x00, //number defining this interface (IF we had more than one interface) ==12 |
|
|
162 |
0x00, //alternate setting ==13 |
|
|
163 |
1, //number of endpoints, except 0 ==14 |
|
|
164 |
0x03, //class code, 03 = HID ==15 |
|
|
165 |
0x01, //subclass code //boot ==16 |
|
|
166 |
0x02, //protocol code ==17 |
|
|
167 |
0x00, //index of string descriptor for interface ==18 |
|
|
168 |
|
|
|
169 |
//class descriptor 1 (HID) |
|
|
170 |
USB_DESC_CLASS_LEN, //length of descriptor ==19 |
|
|
171 |
USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID) ==20 |
|
|
172 |
0x00,0x01, //hid class release number (1.0) (try 1.10) ==21,22 |
|
|
173 |
0x00, //localized country code (0 = none) ==23 |
|
|
174 |
0x01, //number of hid class descrptors that follow (1) ==24 |
|
|
175 |
0x22, //report descriptor type (0x22 == HID) ==25 |
|
|
176 |
USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][0], 0x00, //length of report descriptor ==26,27 |
|
|
177 |
|
|
|
178 |
//endpoint descriptor |
|
|
179 |
USB_DESC_ENDPOINT_LEN, //length of descriptor ==28 |
|
|
180 |
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==29 |
|
|
181 |
0x81, //endpoint number and direction (0x81 = EP1 IN) ==30 |
|
|
182 |
USB_ENDPOINT_TYPE_INTERRUPT, //transfer type supported (0x03 is interrupt) ==31 |
|
|
183 |
USB_EP1_TX_SIZE,0x00, //maximum packet size supported ==32,33 |
|
|
184 |
10 //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==34 |
|
|
185 |
}; |
|
|
186 |
|
|
|
187 |
|
|
|
188 |
//****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ******** |
|
|
189 |
//since we can't make pointers to constants in certain pic16s, this is an offset table to find |
|
|
190 |
// a specific descriptor in the above table. |
|
|
191 |
|
|
|
192 |
//NOTE: DO TO A LIMITATION OF THE CCS CODE, ALL HID INTERFACES MUST START AT 0 AND BE SEQUENTIAL |
|
|
193 |
// FOR EXAMPLE, IF YOU HAVE 2 HID INTERFACES THEY MUST BE INTERFACE 0 AND INTERFACE 1 |
|
|
194 |
#define USB_NUM_HID_INTERFACES 1 |
|
|
195 |
|
|
|
196 |
//the maximum number of interfaces seen on any config |
|
|
197 |
//for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2 |
|
|
198 |
#define USB_MAX_NUM_INTERFACES 1 |
|
|
199 |
|
|
|
200 |
//define how many interfaces there are per config. [0] is the first config, etc. |
|
|
201 |
const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1}; |
|
|
202 |
|
|
|
203 |
//define where to find class descriptors |
|
|
204 |
//first dimension is the config number |
|
|
205 |
//second dimension specifies which interface |
|
|
206 |
//last dimension specifies which class in this interface to get, but most will only have 1 class per interface |
|
|
207 |
//if a class descriptor is not valid, set the value to 0xFFFF |
|
|
208 |
const int16 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][USB_NUM_HID_INTERFACES][1]= |
|
|
209 |
{ |
|
|
210 |
//config 1 |
|
|
211 |
//interface 0 |
|
|
212 |
//class 1 |
|
|
213 |
18 |
|
|
214 |
}; |
|
|
215 |
|
|
|
216 |
|
|
|
217 |
#if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN) |
|
|
218 |
#error USB_TOTAL_CONFIG_LEN not defined correctly |
|
|
219 |
#endif |
|
|
220 |
|
|
|
221 |
|
|
|
222 |
////////////////////////////////////////////////////////////////// |
|
|
223 |
/// |
|
|
224 |
/// start device descriptors |
|
|
225 |
/// |
|
|
226 |
////////////////////////////////////////////////////////////////// |
|
|
227 |
|
|
|
228 |
const char USB_DEVICE_DESC[] = { |
|
|
229 |
//starts of with device configuration. only one possible |
|
|
230 |
USB_DESC_DEVICE_LEN, //the length of this report ==1 |
|
|
231 |
0x01, //the constant DEVICE (DEVICE 0x01) ==2 |
|
|
232 |
0x10,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4 |
|
|
233 |
0xff, //class code ==5 |
|
|
234 |
0x00, //subclass code ==6 |
|
|
235 |
0x00, //protocol code ==7 |
|
|
236 |
USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8 |
|
|
237 |
USB_CONFIG_VID & 0xFF, ((USB_CONFIG_VID >> 8) & 0xFF), //vendor id ==9, 10 |
|
|
238 |
USB_CONFIG_PID & 0xFF, ((USB_CONFIG_PID >> 8) & 0xFF), //product id, don't use 0xffff ==11, 12 |
|
|
239 |
USB_CONFIG_VERSION & 0xFF, ((USB_CONFIG_VERSION >> 8) & 0xFF), //device release number ==13,14 |
|
|
240 |
0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==15 |
|
|
241 |
0x02, //index of string descriptor of the product ==16 |
|
|
242 |
0x00, //index of string descriptor of serial number ==17 |
|
|
243 |
USB_NUM_CONFIGURATIONS //number of possible configurations ==18 |
|
|
244 |
}; |
|
|
245 |
|
|
|
246 |
#if (sizeof(USB_DEVICE_DESC) != USB_DESC_DEVICE_LEN) |
|
|
247 |
#error USB_DESC_DEVICE_LEN not defined correctly |
|
|
248 |
#endif |
|
|
249 |
|
|
|
250 |
|
|
|
251 |
////////////////////////////////////////////////////////////////// |
|
|
252 |
/// |
|
|
253 |
/// start string descriptors |
|
|
254 |
/// String 0 is a special language string, and must be defined. People in U.S.A. can leave this alone. |
|
|
255 |
/// |
|
|
256 |
////////////////////////////////////////////////////////////////// |
|
|
257 |
|
|
|
258 |
//the offset of the starting location of each string. offset[0] is the start of string 0, offset[1] is the start of string 1, etc. |
|
|
259 |
const char USB_STRING_DESC_OFFSET[]={0,4,12}; |
|
|
260 |
|
|
|
261 |
//number of strings you have, including string 0. |
|
|
262 |
#define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET) |
|
|
263 |
|
|
|
264 |
// Here is where the "CCS" Manufacturer string and "CCS USB Mouse" are stored. |
|
|
265 |
// Strings are saved as unicode. |
|
|
266 |
char const USB_STRING_DESC[]={ |
|
|
267 |
//string 0 |
|
|
268 |
4, //length of string index |
|
|
269 |
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) |
|
|
270 |
0x09,0x04, //Microsoft Defined for US-English |
|
|
271 |
//string 1 |
|
|
272 |
8, //length of string index |
|
|
273 |
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) |
|
|
274 |
'U',0, |
|
|
275 |
'S',0, |
|
|
276 |
'T',0, |
|
|
277 |
//string 2 |
|
|
278 |
28, //length of string index |
|
|
279 |
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) |
|
|
280 |
'i',0, |
|
|
281 |
'2',0, |
|
|
282 |
'c',0, |
|
|
283 |
'-',0, |
|
|
284 |
'P',0, |
|
|
285 |
'I',0, |
|
|
286 |
'C',0, |
|
|
287 |
'-',0, |
|
|
288 |
'U',0, |
|
|
289 |
'S',0, |
|
|
290 |
'B',0, |
|
|
291 |
' ',0, |
|
|
292 |
' ',0 |
|
|
293 |
}; |