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