]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/app/usbcan/usb/usb_defs.h
Merge branch 'master' into can-usb1
[lincan.git] / embedded / app / usbcan / usb / usb_defs.h
1
2 #ifndef USB_DEFS_MODULE
3   #define USB_DEFS_MODULE
4
5   #include <usb/usb_spec.h>
6 //  #include <usb/pdiusb.h>
7   #include <usb/lpcusb.h>
8   #include <endian.h>
9   #include <cpu_def.h>
10
11   #include <endian.h>
12   #if __BYTE_ORDER == __BIG_ENDIAN
13     #include <byteswap.h>
14     #define SWAP(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
15   #else /*__LITTLE_ENDIAN*/
16     #define SWAP(x) (x)
17   #endif
18
19   #ifndef CODE
20     #define CODE
21   #endif
22
23   #ifdef USB_MAX_PACKET
24     #undef USB_MAX_PACKET
25   #endif
26   #define USB_MAX_PACKET 16
27
28 /*****************************************************/
29 /*** Static data structures for device descriptors ***/
30 /*****************************************************/
31 #ifndef USB_VENDOR_ID
32   #define USB_VENDOR_ID      0x1669  /* PiKRON.com registered number */
33 #endif
34 #ifndef USB_PRODUCT_ID
35   #define USB_PRODUCT_ID     0x1011  /* test code for ULAD21 */
36 #endif
37   #define USB_RELEASE_VER    0x0010
38
39 /*** Class codes for device description ***/
40   #define USB_CLASS_CODE      0xFF
41   #define USB_SUBCLASS_CODE   0x00
42   #define USB_PROTOCOL_CODE   0x00
43
44
45   #define NUM_ENDPOINTS  2
46   #define CONFIG_DESCRIPTOR_LENGTH sizeof( USB_CONFIGURATION_DESCRIPTOR) \
47                                      + sizeof( USB_INTERFACE_DESCRIPTOR) \
48                                      + ( NUM_ENDPOINTS * sizeof( USB_ENDPOINT_DESCRIPTOR))
49
50 /*** Device descriptor ***/
51   CODE const USB_DEVICE_DESCRIPTOR DeviceDescription = {
52     sizeof( USB_DEVICE_DESCRIPTOR),
53     USB_DESCRIPTOR_TYPE_DEVICE,
54     SWAP( 0x0100),
55     USB_CLASS_CODE,
56     USB_SUBCLASS_CODE,
57     USB_PROTOCOL_CODE,
58     USB_MAX_PACKET0,
59     SWAP( USB_VENDOR_ID),
60     SWAP( USB_PRODUCT_ID),
61     SWAP( USB_RELEASE_VER),
62     1, /* manufacturer string ID */
63     2, /* product string ID */
64     3, /* serial number string ID */
65     1
66   };
67
68 /*** All In Configuration 0 ***/
69   CODE const struct {
70     USB_CONFIGURATION_DESCRIPTOR configuration;
71     USB_INTERFACE_DESCRIPTOR interface;
72     USB_ENDPOINT_DESCRIPTOR endpoint_tx;
73     USB_ENDPOINT_DESCRIPTOR endpoint_rx;
74   } ConfigDescription = {
75     /*** Configuration descriptor ***/
76     {
77       sizeof( USB_CONFIGURATION_DESCRIPTOR),
78       USB_DESCRIPTOR_TYPE_CONFIGURATION,
79       SWAP( CONFIG_DESCRIPTOR_LENGTH),
80       1, /* cnt of interfaces */
81       1, /* this configuration ID */
82       4, /* config.name string ID*/
83       0x80, /* cfg, in spec is, taha bit 7 must be set to one -> 0xe0 , orig 0x60*/
84       0x32    /* device power current from host 100mA */
85     },
86     /*** Interface Descriptor ***/
87     {
88       sizeof( USB_INTERFACE_DESCRIPTOR),
89       USB_DESCRIPTOR_TYPE_INTERFACE,
90       0,    /* index of this interface for SetInterface request */
91       0,    /* ID alternate interface */
92       NUM_ENDPOINTS,
93       USB_CLASS_CODE,
94       USB_SUBCLASS_CODE,
95       USB_PROTOCOL_CODE,
96       5
97     },
98     /*** Endpoint 1 - Tx,Bulk ***/
99     {
100       sizeof( USB_ENDPOINT_DESCRIPTOR),
101       USB_DESCRIPTOR_TYPE_ENDPOINT,
102       0x01,
103       USB_ENDPOINT_TYPE_BULK,
104       SWAP( USB_MAX_PACKET),
105       0
106     },
107     /*** Endpoint 1 - Rx,Bulk ***/
108     {
109       sizeof( USB_ENDPOINT_DESCRIPTOR),
110       USB_DESCRIPTOR_TYPE_ENDPOINT,
111       0x81,
112       USB_ENDPOINT_TYPE_BULK,
113       SWAP( USB_MAX_PACKET),
114       0
115     }
116   };
117   /*** Strings - in unicode ***/
118   CODE const char Str0Desc[] = {  /* supported languages of strings */
119     4, 0x03,  /* 2+2*N , N is count of supported languages */
120     0x09,0x04 /* english 0x0409 */
121   };
122
123   CODE const char Str1Desc[] = {  /* 1 = manufacturer */
124     44,0x03,
125     'K',0,
126     'r',0,
127     'i',0,
128     'z',0,
129     ',',0,
130     'B',0,
131     'a',0,
132     'r',0,
133     't',0,
134     'o',0,
135     's',0,
136     'i',0,
137     'n',0,
138     's',0,
139     'k',0,
140     'i',0,
141     ',',0,
142     'P',0,
143     'i',0,
144     's',0,
145     'a',0
146   };
147
148   CODE const char Str2Desc[] = {  /* 2 = product */
149     42, 0x03,
150     'C',0,
151     'A',0,
152     'N',0,
153     ' ',0,
154     't',0,
155     'o',0,
156     ' ',0,
157     'U',0,
158     'S',0,
159     'B',0,
160     ' ',0,
161     'c',0,
162     'o',0,
163     'n',0,
164     'v',0,
165     'e',0,
166     'r',0,
167     't',0,
168     'o',0,
169     'r',0
170   };
171
172
173   CODE const char Str3Desc[] = {  /* 3 = version */
174     26, 0x03,
175     '1',0,
176     '.',0,
177     '1',0,
178     ' ',0,
179     '0',0,
180     '8',0,
181     '-',0,
182     '1',0,
183     '1',0,
184     '-',0,
185     '2',0,
186     '3',0
187   };
188   CODE const char Str4Desc[] = {  /* 4 = configuration */
189     34, 0x03,
190     'C',0,
191     'o',0,
192     'n',0,
193     'f',0,
194     'i',0,
195     'g',0,
196     'u',0,
197     'r',0,
198     'a',0,
199     't',0,
200     'i',0,
201     'o',0,
202     'n',0,
203     ' ',0,
204     '#',0,
205     '1',0
206   };
207   CODE const char Str5Desc[] = {  /* 5 = interface */
208     38,0x03,
209     'I',0,
210     'n',0,
211     't',0,
212     'e',0,
213     'r',0,
214     'f',0,
215     'a',0,
216     'c',0,
217     'e',0,
218     ' ',0,
219     '#',0,
220     '0',0,
221     ' ',0,
222     '-',0,
223     ' ',0,
224     'C',0,
225     'A',0,
226     'N',0
227   };
228
229   CODE const char Str6Desc[] = {  /* EP1 OUT descriptor */
230     48,0x03,
231     'E',0,
232     'P',0,
233     '1',0,
234     'O',0,
235     'U',0,
236     'T',0,
237     '-',0,
238     's',0,
239     'e',0,
240     'n',0,
241     'd',0,
242     ' ',0,
243     'C',0,
244     'A',0,
245     'N',0,
246     ' ',0,
247     'm',0,
248     'e',0,
249     's',0,
250     's',0,
251     'a',0,
252     'g',0,
253     'e',0
254   };
255
256   CODE const char Str7Desc[] = {  /* EP1 IN descriptor */
257     52,0x03,
258     'E',0,
259     'P',0,
260     '1',0,
261     'I',0,
262     'N',0,
263     '-',0,
264     'r',0,
265     'e',0,
266     'c',0,
267     'e',0,
268     'i',0,
269     'v',0,
270     'e',0,
271     ' ',0,
272     'C',0,
273     'A',0,
274     'N',0,
275     ' ',0,
276     'm',0,
277     'e',0,
278     's',0,
279     's',0,
280     'a',0,
281     'g',0,
282     'e',0
283   };
284
285   /* all strings in pointers array */
286   CODE const PUSB_STRING_DESCRIPTOR StringDescriptors[] = {
287     (PUSB_STRING_DESCRIPTOR) Str0Desc,
288     (PUSB_STRING_DESCRIPTOR) Str1Desc,
289     (PUSB_STRING_DESCRIPTOR) Str2Desc,
290     (PUSB_STRING_DESCRIPTOR) Str3Desc,
291     (PUSB_STRING_DESCRIPTOR) Str4Desc,
292     (PUSB_STRING_DESCRIPTOR) Str5Desc,
293     (PUSB_STRING_DESCRIPTOR) Str6Desc,
294     (PUSB_STRING_DESCRIPTOR) Str7Desc,
295   };
296
297   #define CNT_STRINGS (sizeof(StringDescriptors)/sizeof(StringDescriptors[0]))
298
299   CODE const USB_DEVICE_CONFIGURATION_ENTRY usb_devdes_configurations[] = {
300     {
301       .pConfigDescription = &ConfigDescription.configuration,
302       .iConfigTotalLength = CONFIG_DESCRIPTOR_LENGTH
303     }
304   };
305
306   CODE const USB_INTERFACE_DESCRIPTOR *usb_devdes_interfaces[] = {
307     &ConfigDescription.interface
308   };
309
310   CODE const USB_DEVICE_DESCRIPTORS_TABLE usb_devdes_table = {
311     .pDeviceDescription = &DeviceDescription,
312     .pConfigurations = usb_devdes_configurations,
313     .pInterfaceDescriptors = usb_devdes_interfaces,
314     .pStrings = StringDescriptors,
315     .iNumStrings = CNT_STRINGS,
316     .bNumEndpoints = NUM_ENDPOINTS,
317     .bNumConfigurations = 1,
318     .bNumInterfaces = 1
319   };
320
321 #endif /* USB_DEFS_MODULE */