Rev 3325 Rev 3331
Line 42... Line 42...
42 #define USB_CONFIG_BUS_POWER 100 //100mA (range is 0..500) 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 43 #define USB_CONFIG_VERSION 0x0205 //01.00 //range is 00.00 to 99.99
44 //////// end config /////////////////////////////////////////////////////////// 44 //////// end config ///////////////////////////////////////////////////////////
45   45  
46   46  
-   47 //#DEFINE USB_CONFIG_BUS_POWER FALSE
-   48 //#define USB_USE_FULL_SPEED FALSE
47   49  
48 #DEFINE USB_HID_DEVICE TRUE //Tells the CCS PIC USB firmware 50 #DEFINE USB_HID_DEVICE FALSE //Tells the CCS PIC USB firmware
49 //to include HID handling code. 51 //Enable to include HID handling code.
50   52  
51 //turn on EP1 for IN interrupt transfers. (IN = PIC -> PC) 53 //turn on EP0 for IN control transfers. (IN = PIC -> PC)
52 #define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT 54 #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
-   55 #define USB_EP0_TX_SIZE 64 //max packet size of this endpoint
53   56  
-   57 #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
54 #define USB_EP1_TX_SIZE 8 //max packet size of this endpoint 58 #define USB_EP0_RX_SIZE 64 //max packet size of this endpoint
55   59  
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[] = 60 //#define USB_EP1_TX_ENABLE USB_ENABLE_CONTROL
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 61 //#define USB_EP1_TX_SIZE 8 //max packet size of this endpoint
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   62  
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. 63 //#define USB_EP1_RX_ENABLE USB_ENABLE_CONTROL
103 //first element is the config number (if your device has more than one config) 64 //#define USB_EP1_RX_SIZE 8 //max packet size of this endpoint
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 0 -  
111 }; -  
112   65  
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   66  
125   67  
-   68 #include <usb.h>
126   69  
127 ////////////////////////////////////////////////////////////////// 70 //////////////////////////////////////////////////////////////////
128 /// 71 ///
129 /// start config descriptor 72 /// start config descriptor
130 /// right now we only support one configuration descriptor. 73 /// right now we only support one configuration descriptor.
131 /// the config, interface, class, and endpoint goes into this array. 74 /// the config, interface, class, and endpoint goes into this array.
132 /// 75 ///
133 ////////////////////////////////////////////////////////////////// 76 //////////////////////////////////////////////////////////////////
134   77  
135 #DEFINE USB_TOTAL_CONFIG_LEN 34 //config+interface+class+endpoint 78 #DEFINE USB_TOTAL_CONFIG_LEN 32 //config+interface+class+endpoint
136   79  
137 const char USB_CONFIG_DESC[] = { 80 const char USB_CONFIG_DESC[] = {
138 //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE: 81 //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
139 // config(s) 82 // config(s)
140 // interface(s) 83 // interface(s)
Line 158... Line 101...
158 //interface descriptor 1 101 //interface descriptor 1
159 USB_DESC_INTERFACE_LEN, //length of descriptor =10 102 USB_DESC_INTERFACE_LEN, //length of descriptor =10
160 USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =11 103 USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =11
161 0x00, //number defining this interface (IF we had more than one interface) ==12 104 0x00, //number defining this interface (IF we had more than one interface) ==12
162 0x00, //alternate setting ==13 105 0x00, //alternate setting ==13
163 1, //number of endpoints, except 0 ==14 106 2, //number of endpoints, except 0 ==14
164 0x03, //class code, 03 = HID ==15 107 0xff, //class code, 03 = HID ==15
165 0x01, //subclass code //boot ==16 108 0xff, //subclass code //boot ==16
166 0x02, //protocol code ==17 109 0xff, //protocol code ==17
167 0x00, //index of string descriptor for interface ==18 110 0x00, //index of string descriptor for interface ==18
168   111  
169 //class descriptor 1 (HID) 112 //class descriptor 1 (HID)
170 USB_DESC_CLASS_LEN, //length of descriptor ==19 113 /* USB_DESC_CLASS_LEN, //length of descriptor ==19
171 USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID) ==20 114 USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID) ==20
172 0x00,0x01, //hid class release number (1.0) (try 1.10) ==21,22 115 0x00,0x01, //hid class release number (1.0) (try 1.10) ==21,22
173 0x00, //localized country code (0 = none) ==23 116 0x00, //localized country code (0 = none) ==23
174 0x01, //number of hid class descrptors that follow (1) ==24 117 0x01, //number of hid class descrptors that follow (1) ==24
175 0x22, //report descriptor type (0x22 == HID) ==25 118 0x22, //report descriptor type (0x22 == HID) ==25
176 USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][0], 0x00, //length of report descriptor ==26,27 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
177   128  
178 //endpoint descriptor 129 //endpoint descriptor
179 USB_DESC_ENDPOINT_LEN, //length of descriptor ==28 130 USB_DESC_ENDPOINT_LEN, //length of descriptor ==28
180 USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==29 131 USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==29
181 0x81, //endpoint number and direction (0x81 = EP1 IN) ==30 132 0x00, //endpoint number and direction (0x80 = EP0 IN) ==30
182 USB_ENDPOINT_TYPE_INTERRUPT, //transfer type supported (0x03 is interrupt) ==31 133 USB_ENDPOINT_TYPE_CONTROL, //transfer type supported (0x03 is interrupt) ==31
183 USB_EP1_TX_SIZE,0x00, //maximum packet size supported ==32,33 134 USB_EP0_RX_SIZE,0x00, //maximum packet size supported ==32,33
184 10 //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==34 135 10 //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==34
185 }; 136 };
186   137  
187   138  
188 //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ******** 139 //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
Line 228... Line 179...
228 const char USB_DEVICE_DESC[] = { 179 const char USB_DEVICE_DESC[] = {
229 //starts of with device configuration. only one possible 180 //starts of with device configuration. only one possible
230 USB_DESC_DEVICE_LEN, //the length of this report ==1 181 USB_DESC_DEVICE_LEN, //the length of this report ==1
231 0x01, //the constant DEVICE (DEVICE 0x01) ==2 182 0x01, //the constant DEVICE (DEVICE 0x01) ==2
232 0x10,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4 183 0x10,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4
233 0xff, //class code ==5 184 0xff, //class code vendor specific
234 0x00, //subclass code ==6 185 0x00, //subclass code ==6
235 0x00, //protocol code ==7 186 0x00, //protocol code ==7
236 USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8 187 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 188 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 189 USB_CONFIG_PID & 0xFF, ((USB_CONFIG_PID >> 8) & 0xFF), //product id, don't use 0xffff ==11, 12