]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - sw/app/rocon/usb/usb_defs.h
Prepare build-able skeleton for RoCoN application.
[fpga/lx-cpu1/lx-rocon.git] / sw / app / rocon / 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 /*****************************************************/
24 /*** Static data structures for device descriptors ***/
25 /*****************************************************/
26 #ifndef USB_VENDOR_ID
27   #define USB_VENDOR_ID      0xDEAD  /* vymyslene cislo ( snad ho nikdo nema ... ;-) */
28 #endif
29 #ifndef USB_PRODUCT_ID
30   #define USB_PRODUCT_ID     0x2263  /* test code for ULAD21 */
31 #endif
32   #define USB_RELEASE_VER    0x0100
33
34 /*** Class codes for device description ***/
35   #define USB_CLASS_CODE      0xFF
36   #define USB_SUBCLASS_CODE   0x00
37   #define USB_PROTOCOL_CODE   0x00
38
39 #ifndef NUM_ENDPOINTS
40   #define NUM_ENDPOINTS  0
41 #endif
42   #define CONFIG_DESCRIPTOR_LENGTH sizeof( USB_CONFIGURATION_DESCRIPTOR) \
43                                      + sizeof( USB_INTERFACE_DESCRIPTOR) \
44                                      + ( NUM_ENDPOINTS * sizeof( USB_ENDPOINT_DESCRIPTOR))
45
46 /*** Device descriptor ***/
47   CODE const USB_DEVICE_DESCRIPTOR DeviceDescription = {
48     sizeof( USB_DEVICE_DESCRIPTOR),
49     USB_DESCRIPTOR_TYPE_DEVICE,
50     SWAP( 0x0100),
51     USB_CLASS_CODE,
52     USB_SUBCLASS_CODE,
53     USB_PROTOCOL_CODE,
54     USB_MAX_PACKET0,
55     SWAP( USB_VENDOR_ID),
56     SWAP( USB_PRODUCT_ID),
57     SWAP( USB_RELEASE_VER),
58     1, /* manufacturer string ID */
59     2, /* product string ID */
60     3, /* serial number string ID */
61     1
62   };
63
64 /*** All In Configuration 0 ***/
65 #ifndef CONFIG_APP_ULAD31_WITH_DIPSW
66   CODE const
67 #endif /*CONFIG_APP_ULAD31_WITH_DIPSW*/
68    struct {
69     USB_CONFIGURATION_DESCRIPTOR configuration;
70     USB_INTERFACE_DESCRIPTOR interface;
71     USB_ENDPOINT_DESCRIPTOR endpoint_tx;
72     USB_ENDPOINT_DESCRIPTOR endpoint_rx;
73   } ConfigDescription = {
74     /*** Configuration descriptor ***/
75     {
76       sizeof( USB_CONFIGURATION_DESCRIPTOR),
77       USB_DESCRIPTOR_TYPE_CONFIGURATION,
78       SWAP( CONFIG_DESCRIPTOR_LENGTH),
79       1, /* cnt of interfaces */
80       1, /* this configuration ID */
81       4, /* config.name string ID*/
82       0x80, /* cfg, in spec is, taha bit 7 must be set to one -> 0xe0 , orig 0x60*/
83       250    /* device power current from host 500mA / 2 */
84     },
85     /*** Interface Descriptor ***/
86     {
87       sizeof( USB_INTERFACE_DESCRIPTOR),
88       USB_DESCRIPTOR_TYPE_INTERFACE,
89       0,    /* index of this interface for SetInterface request */
90       0,    /* ID alternate interface */
91       NUM_ENDPOINTS,
92       USB_CLASS_CODE,
93       USB_SUBCLASS_CODE,
94       USB_PROTOCOL_CODE,
95       5
96     },
97     /*** Endpoint 1 - Tx,Bulk ***/
98     {
99       sizeof( USB_ENDPOINT_DESCRIPTOR),
100       USB_DESCRIPTOR_TYPE_ENDPOINT,
101       0x01,
102       USB_ENDPOINT_TYPE_BULK,
103       SWAP( USB_MAX_PACKET),
104       0
105     },
106     /*** Endpoint 1 - Rx,Bulk ***/
107     {
108       sizeof( USB_ENDPOINT_DESCRIPTOR),
109       USB_DESCRIPTOR_TYPE_ENDPOINT,
110       0x81,
111       USB_ENDPOINT_TYPE_BULK,
112       SWAP( USB_MAX_PACKET),
113       0
114     }
115   };
116   /*** Strings - in unicode ***/
117   CODE const char Str0Desc[] = {  /* supported languages of strings */
118     4, 0x03,  /* 2+2*N , N is count of supported languages */
119     0x09,0x04 /* english 0x0409 */
120   };
121
122   CODE const char Str1Desc[] = {  /* 1 = manufacturer */
123     24,0x03,
124     'P',0,
125     'i',0,
126     'K',0,
127     'R',0,
128     'O',0,
129     'N',0,
130     ' ',0,
131     'L',0,
132     't',0,
133     'd',0,
134     '.',0,
135   };
136
137   CODE const char Str2Desc[] = {  /* 2 = product */
138     12, 0x03,
139     'R',0,
140     'O',0,
141     'C',0,
142     'O',0,
143     'N',0,
144    };
145
146   #define usb_devdes_serial_number Str3Desc
147   /* Serial number is stored in data area to be set at device start-up */
148   char Str3Desc[(1+8)*2] = {  /* 3 = serial number */
149     18, 0x03,
150     'X',0,
151     'X',0,
152     'X',0,
153     'X',0,
154     'X',0,
155     'X',0,
156     'X',0,
157     'X',0,
158   };
159
160   CODE const char Str4Desc[] = {  /* 4 = configuration */
161     34, 0x03,
162     'C',0,
163     'o',0,
164     'n',0,
165     'f',0,
166     'i',0,
167     'g',0,
168     'u',0,
169     'r',0,
170     'a',0,
171     't',0,
172     'i',0,
173     'o',0,
174     'n',0,
175     ' ',0,
176     '#',0,
177     '1',0
178   };
179   CODE const char Str5Desc[] = {  /* 5 = interface */
180     26,0x03,
181     'I',0,
182     'n',0,
183     't',0,
184     'e',0,
185     'r',0,
186     'f',0,
187     'a',0,
188     'c',0,
189     'e',0,
190     ' ',0,
191     '#',0,
192     '0',0
193   };
194
195   CODE const char Str6Desc[] = {  /* EP1 OUT descriptor */
196     14,0x03,
197     'E',0,
198     'P',0,
199     '1',0,
200     'O',0,
201     'U',0,
202     'T',0
203   };
204
205   CODE const char Str7Desc[] = {  /* EP2 IN descriptor */
206     12,0x03,
207     'E',0,
208     'P',0,
209     '1',0,
210     'I',0,
211     'N',0,
212   };
213
214   /* all strings in pointers array */
215   CODE const PUSB_STRING_DESCRIPTOR StringDescriptors[] = {
216     (PUSB_STRING_DESCRIPTOR) Str0Desc,
217     (PUSB_STRING_DESCRIPTOR) Str1Desc,
218     (PUSB_STRING_DESCRIPTOR) Str2Desc,
219     (PUSB_STRING_DESCRIPTOR) Str3Desc,
220     (PUSB_STRING_DESCRIPTOR) Str4Desc,
221     (PUSB_STRING_DESCRIPTOR) Str5Desc,
222     (PUSB_STRING_DESCRIPTOR) Str6Desc,
223     (PUSB_STRING_DESCRIPTOR) Str7Desc
224   };
225
226   #define CNT_STRINGS (sizeof(StringDescriptors)/sizeof(StringDescriptors[0]))
227
228   CODE const USB_DEVICE_CONFIGURATION_ENTRY usb_devdes_configurations[] = {
229     {
230       .pConfigDescription = &ConfigDescription.configuration,
231       .iConfigTotalLength = CONFIG_DESCRIPTOR_LENGTH
232     }
233   };
234
235   CODE const USB_INTERFACE_DESCRIPTOR *usb_devdes_interfaces[] = {
236     &ConfigDescription.interface
237   };
238
239   CODE const USB_DEVICE_DESCRIPTORS_TABLE usb_devdes_table = {
240     .pDeviceDescription = &DeviceDescription,
241     .pConfigurations = usb_devdes_configurations,
242     .pInterfaceDescriptors = usb_devdes_interfaces,
243     .pStrings = StringDescriptors,
244     .iNumStrings = CNT_STRINGS,
245     .bNumEndpoints = NUM_ENDPOINTS,
246     .bNumConfigurations = 1,
247     .bNumInterfaces = 1
248   };
249
250 #endif /* USB_DEFS_MODULE */