Rev Author Line No. Line
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  
3331 kaklik 47 //#DEFINE USB_CONFIG_BUS_POWER FALSE
48 //#define USB_USE_FULL_SPEED FALSE
3325 kaklik 49  
3331 kaklik 50 #DEFINE USB_HID_DEVICE FALSE //Tells the CCS PIC USB firmware
51 //Enable to include HID handling code.
3325 kaklik 52  
3331 kaklik 53 //turn on EP0 for IN control transfers. (IN = PIC -> PC)
54 #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
55 #define USB_EP0_TX_SIZE 64 //max packet size of this endpoint
3325 kaklik 56  
3331 kaklik 57 #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
58 #define USB_EP0_RX_SIZE 64 //max packet size of this endpoint
3325 kaklik 59  
3331 kaklik 60 //#define USB_EP1_TX_ENABLE USB_ENABLE_CONTROL
61 //#define USB_EP1_TX_SIZE 8 //max packet size of this endpoint
3325 kaklik 62  
3331 kaklik 63 //#define USB_EP1_RX_ENABLE USB_ENABLE_CONTROL
64 //#define USB_EP1_RX_SIZE 8 //max packet size of this endpoint
3325 kaklik 65  
66  
67  
3331 kaklik 68 #include <usb.h>
3325 kaklik 69  
70 //////////////////////////////////////////////////////////////////
71 ///
72 /// start config descriptor
73 /// right now we only support one configuration descriptor.
74 /// the config, interface, class, and endpoint goes into this array.
75 ///
76 //////////////////////////////////////////////////////////////////
77  
3331 kaklik 78 #DEFINE USB_TOTAL_CONFIG_LEN 32 //config+interface+class+endpoint
3325 kaklik 79  
80 const char USB_CONFIG_DESC[] = {
81 //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
82 // config(s)
83 // interface(s)
84 // class(es)
85 // endpoint(s)
86  
87 //config_descriptor for config index 1
88 USB_DESC_CONFIG_LEN, //length of descriptor size ==1
89 USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==2
90 USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==3,4
91 1, //number of interfaces this device supports ==5
92 0x01, //identifier for this configuration. (IF we had more than one configurations) ==6
93 0x00, //index of string descriptor for this configuration ==7
94 #if USB_CONFIG_BUS_POWER
95 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
96 #else
97 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
98 #endif
99 USB_CONFIG_BUS_POWER/2, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==9
100  
101 //interface descriptor 1
102 USB_DESC_INTERFACE_LEN, //length of descriptor =10
103 USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =11
104 0x00, //number defining this interface (IF we had more than one interface) ==12
105 0x00, //alternate setting ==13
3331 kaklik 106 2, //number of endpoints, except 0 ==14
107 0xff, //class code, 03 = HID ==15
108 0xff, //subclass code //boot ==16
109 0xff, //protocol code ==17
3325 kaklik 110 0x00, //index of string descriptor for interface ==18
111  
112 //class descriptor 1 (HID)
3331 kaklik 113 /* USB_DESC_CLASS_LEN, //length of descriptor ==19
3325 kaklik 114 USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID) ==20
115 0x00,0x01, //hid class release number (1.0) (try 1.10) ==21,22
116 0x00, //localized country code (0 = none) ==23
117 0x01, //number of hid class descrptors that follow (1) ==24
118 0x22, //report descriptor type (0x22 == HID) ==25
3331 kaklik 119 0, 0x00, //length of report descriptor ==26,27
120 */
121 //endpoint descriptor
122 USB_DESC_ENDPOINT_LEN, //length of descriptor ==28
123 USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==29
124 0x80, //endpoint number and direction (0x80 = EP0 IN) ==30
125 USB_ENDPOINT_TYPE_CONTROL, //transfer type supported (0x03 is interrupt) ==31
126 USB_EP0_TX_SIZE,0x00, //maximum packet size supported ==32,33
127 10 //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==34
3325 kaklik 128  
129 //endpoint descriptor
130 USB_DESC_ENDPOINT_LEN, //length of descriptor ==28
131 USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==29
3331 kaklik 132 0x00, //endpoint number and direction (0x80 = EP0 IN) ==30
133 USB_ENDPOINT_TYPE_CONTROL, //transfer type supported (0x03 is interrupt) ==31
134 USB_EP0_RX_SIZE,0x00, //maximum packet size supported ==32,33
3325 kaklik 135 10 //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==34
136 };
137  
138  
139 //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
140 //since we can't make pointers to constants in certain pic16s, this is an offset table to find
141 // a specific descriptor in the above table.
142  
143 //NOTE: DO TO A LIMITATION OF THE CCS CODE, ALL HID INTERFACES MUST START AT 0 AND BE SEQUENTIAL
144 // FOR EXAMPLE, IF YOU HAVE 2 HID INTERFACES THEY MUST BE INTERFACE 0 AND INTERFACE 1
145 #define USB_NUM_HID_INTERFACES 1
146  
147 //the maximum number of interfaces seen on any config
148 //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
149 #define USB_MAX_NUM_INTERFACES 1
150  
151 //define how many interfaces there are per config. [0] is the first config, etc.
152 const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1};
153  
154 //define where to find class descriptors
155 //first dimension is the config number
156 //second dimension specifies which interface
157 //last dimension specifies which class in this interface to get, but most will only have 1 class per interface
158 //if a class descriptor is not valid, set the value to 0xFFFF
159 const int16 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][USB_NUM_HID_INTERFACES][1]=
160 {
161 //config 1
162 //interface 0
163 //class 1
164 18
165 };
166  
167  
168 #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
169 #error USB_TOTAL_CONFIG_LEN not defined correctly
170 #endif
171  
172  
173 //////////////////////////////////////////////////////////////////
174 ///
175 /// start device descriptors
176 ///
177 //////////////////////////////////////////////////////////////////
178  
179 const char USB_DEVICE_DESC[] = {
180 //starts of with device configuration. only one possible
181 USB_DESC_DEVICE_LEN, //the length of this report ==1
182 0x01, //the constant DEVICE (DEVICE 0x01) ==2
183 0x10,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4
3331 kaklik 184 0xff, //class code vendor specific
3325 kaklik 185 0x00, //subclass code ==6
186 0x00, //protocol code ==7
187 USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8
188 USB_CONFIG_VID & 0xFF, ((USB_CONFIG_VID >> 8) & 0xFF), //vendor id ==9, 10
189 USB_CONFIG_PID & 0xFF, ((USB_CONFIG_PID >> 8) & 0xFF), //product id, don't use 0xffff ==11, 12
190 USB_CONFIG_VERSION & 0xFF, ((USB_CONFIG_VERSION >> 8) & 0xFF), //device release number ==13,14
191 0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==15
192 0x02, //index of string descriptor of the product ==16
193 0x00, //index of string descriptor of serial number ==17
194 USB_NUM_CONFIGURATIONS //number of possible configurations ==18
195 };
196  
197 #if (sizeof(USB_DEVICE_DESC) != USB_DESC_DEVICE_LEN)
198 #error USB_DESC_DEVICE_LEN not defined correctly
199 #endif
200  
201  
202 //////////////////////////////////////////////////////////////////
203 ///
204 /// start string descriptors
205 /// String 0 is a special language string, and must be defined. People in U.S.A. can leave this alone.
206 ///
207 //////////////////////////////////////////////////////////////////
208  
209 //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.
210 const char USB_STRING_DESC_OFFSET[]={0,4,12};
211  
212 //number of strings you have, including string 0.
213 #define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET)
214  
215 // Here is where the "CCS" Manufacturer string and "CCS USB Mouse" are stored.
216 // Strings are saved as unicode.
217 char const USB_STRING_DESC[]={
218 //string 0
219 4, //length of string index
220 USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
221 0x09,0x04, //Microsoft Defined for US-English
222 //string 1
223 8, //length of string index
224 USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
225 'U',0,
226 'S',0,
227 'T',0,
228 //string 2
229 28, //length of string index
230 USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
231 'i',0,
232 '2',0,
233 'c',0,
234 '-',0,
235 'P',0,
236 'I',0,
237 'C',0,
238 '-',0,
239 'U',0,
240 'S',0,
241 'B',0,
242 ' ',0,
243 ' ',0
244 };