]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - sw/app/rocon/usb/usb_defs.h
RoCoN: USB CDC ACM use maximal packet length - 64 bytes.
[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/usb_cdc.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 #define USB_VENDOR_ID      0x1669  /* PIKRON company bought vendor ID */
27 #define USB_PRODUCT_ID     0x1023  /* Number reserved for RoCoN on LX_CPU1 */
28 #define USB_RELEASE_VER    0x0100
29
30 /*** Class codes for device description ***/
31 #define USB_CLASS_CODE      USB_DEVICE_CLASS_COMMUNICATIONS
32 #define USB_SUBCLASS_CODE   0x00
33 #define USB_PROTOCOL_CODE   0x00
34
35 #define NUM_ENDPOINTS       3
36 #define CDC0_EP_NOTIFY      0x81
37 #define CDC0_EP_RXD         0x02
38 #define CDC0_EP_TXD         0x82
39 #define CDC0_MAX_PACKET     64
40
41 #define CONFIG_DESCRIPTOR_LENGTH \
42   sizeof(USB_CONFIGURATION_DESCRIPTOR) \
43    + sizeof(USB_INTERFACE_DESCRIPTOR) \
44    + sizeof(USBCDC_HEADER_FCN_DESCRIPTOR) \
45    + sizeof(USBCDC_CALLMGMT_FCN_DESCRIPTOR) \
46    + sizeof(USBCDC_ACM_FCN_DESCRIPTOR) \
47    + sizeof(USBCDC_UNION_FCN_DESCRIPTOR) \
48    + sizeof(USB_INTERFACE_DESCRIPTOR) \
49    + (NUM_ENDPOINTS*sizeof(USB_ENDPOINT_DESCRIPTOR))
50
51 /*** Device descriptor ***/
52 CODE const USB_DEVICE_DESCRIPTOR DeviceDescription =
53 {
54   sizeof(USB_DEVICE_DESCRIPTOR),
55   USB_DESCRIPTOR_TYPE_DEVICE,
56   SWAP(0x0120),
57   USB_CLASS_CODE,
58   USB_SUBCLASS_CODE,
59   USB_PROTOCOL_CODE,
60   USB_MAX_PACKET0,
61   SWAP(USB_VENDOR_ID),
62   SWAP(USB_PRODUCT_ID),
63   SWAP(USB_RELEASE_VER),
64   1, /* manufacturer string ID */
65   2, /* product string ID */
66   3, /* serial number string ID */
67   1  /* bNumConfigs */
68 };
69
70 /*** All In Configuration 0 ***/
71 CODE const struct
72 {
73   USB_CONFIGURATION_DESCRIPTOR configuration;
74   USB_INTERFACE_DESCRIPTOR        iface_comm;
75   USBCDC_HEADER_FCN_DESCRIPTOR    cdcheader;
76   USBCDC_CALLMGMT_FCN_DESCRIPTOR  cdccallmgt;
77   USBCDC_ACM_FCN_DESCRIPTOR       cdcacm;
78   USBCDC_UNION_FCN_DESCRIPTOR     cdcunion;
79   USB_ENDPOINT_DESCRIPTOR         ep_notification;
80   USB_INTERFACE_DESCRIPTOR        iface_data;
81   USB_ENDPOINT_DESCRIPTOR         ep_rxd;
82   USB_ENDPOINT_DESCRIPTOR         ep_txd;
83 } PACKED ConfigDescription =
84 {
85   {
86     /*** Configuration descriptor ***/
87     sizeof(USB_CONFIGURATION_DESCRIPTOR),
88     USB_DESCRIPTOR_TYPE_CONFIGURATION,
89     SWAP(CONFIG_DESCRIPTOR_LENGTH),
90     2, /* cnt of interfaces */
91     1, /* this configuration ID */
92     4, /* config.name string ID */
93     USB_CONFIG_BUS_POWERED, /* CbmAttributes (bus powered) */
94     250    /* device power current from host 500mA / 2 */
95   },
96   {
97     /*** Interface Descriptor ***/
98     sizeof(USB_INTERFACE_DESCRIPTOR),
99     USB_DESCRIPTOR_TYPE_INTERFACE,
100     0,    /* index of this interface for SetInterface request */
101     0,    /* ID alternate interface */
102     1,    /* number of endpoints in interface */
103     USB_DEVICE_CLASS_COMMUNICATIONS,
104     USBCDC_COM_IFACE_SUBCLS_ACM,
105     0,    /* protocol */
106     5
107   },
108   {
109     /*** CDC Header Descriptor ***/
110     sizeof(USBCDC_HEADER_FCN_DESCRIPTOR),
111     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
112     USBCDC_COM_FCN_SUBTYPE_HEADER,    /* bDescriptorSubtype */
113     SWAP(0x0120),                     /* bcdCDC (spec. release 1.2) */
114   },
115   {
116     /*** CDC CALL MANAGEMENT Descriptor ***/
117     sizeof(USBCDC_CALLMGMT_FCN_DESCRIPTOR),
118     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
119     USBCDC_COM_FCN_SUBTYPE_CALLMGMT,
120     0,
121     1,
122   },
123   {
124     /*** CDC ABSTRACT CONTROL MANAGEMENT Descriptor ***/
125     sizeof(USBCDC_ACM_FCN_DESCRIPTOR),
126     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
127     USBCDC_COM_FCN_SUBTYPE_ACMGMT,
128     USBCDC_ACM_FCN_CAP_SUPPORT_LINECTRL,
129   },
130   {
131     /*** CDC UNION Descriptor ***/
132     sizeof(USBCDC_UNION_FCN_DESCRIPTOR),
133     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
134     USBCDC_COM_FCN_SUBTYPE_UNION,
135     0,
136     1,
137   },
138   {
139     /*** Endpoint 1 IN, type interrupt ***/
140     sizeof(USB_ENDPOINT_DESCRIPTOR),
141     USB_DESCRIPTOR_TYPE_ENDPOINT,
142     CDC0_EP_NOTIFY,                   /* bEndpointAddress */
143     USB_ENDPOINT_TYPE_INTERRUPT,
144     SWAP(USB_MAX_PACKET),
145     0x80,                             /* bInterval (polling interval: 50ms) */
146   },
147   {
148     /*** Interface Descriptor ***/
149     sizeof(USB_INTERFACE_DESCRIPTOR),
150     USB_DESCRIPTOR_TYPE_INTERFACE,
151     1,                                /* bInterfaceNumber */
152     0,                                /* bAlternateSetting */
153     2,                                /* number of EPs */
154     USB_DEVICE_CLASS_CDC_DATA,        /* bInterfaceClass */
155     0,                                /* bInterfaceSubclass */
156     0,                                /* bDeviceProtocol */
157     0,                                /* iInterface (string, 0=none) */
158   },
159   {
160     /*** Endpoint 2 OUT, type bulk ***/
161     sizeof(USB_ENDPOINT_DESCRIPTOR),
162     USB_DESCRIPTOR_TYPE_ENDPOINT,
163     CDC0_EP_RXD,                      /* bEndpointAddress */
164     USB_ENDPOINT_TYPE_BULK,
165     SWAP(CDC0_MAX_PACKET),
166     0,                                /* bInterval (polling interval: 50ms) */
167   },
168   {
169     /*** Endpoint 2 IN, type bulk ***/
170     sizeof(USB_ENDPOINT_DESCRIPTOR),
171     USB_DESCRIPTOR_TYPE_ENDPOINT,
172     CDC0_EP_TXD,                      /* bEndpointAddress */
173     USB_ENDPOINT_TYPE_BULK,
174     SWAP(CDC0_MAX_PACKET),
175     0,                                /* bInterval (polling interval: 50ms) */
176   }
177 };
178
179 /*** Strings - in unicode ***/
180 CODE const char Str0Desc[] =    /* supported languages of strings */
181 {
182   4, 0x03,  /* 2+2*N , N is count of supported languages */
183   0x09, 0x04 /* english 0x0409 */
184 };
185
186 CODE const char Str1Desc[] =    /* 1 = manufacturer */
187 {
188   24, 0x03,
189   'P', 0,
190   'i', 0,
191   'K', 0,
192   'R', 0,
193   'O', 0,
194   'N', 0,
195   ' ', 0,
196   'L', 0,
197   't', 0,
198   'd', 0,
199   '.', 0,
200 };
201
202 CODE const char Str2Desc[] =    /* 2 = product */
203 {
204   12, 0x03,
205   'R', 0,
206   'O', 0,
207   'C', 0,
208   'O', 0,
209   'N', 0,
210 };
211
212 #define usb_devdes_serial_number Str3Desc
213 /* Serial number is stored in data area to be set at device start-up */
214 char Str3Desc[(1 + 8) * 2] = /* 3 = serial number */
215 {
216   18, 0x03,
217   'X', 0,
218   'X', 0,
219   'X', 0,
220   'X', 0,
221   'X', 0,
222   'X', 0,
223   'X', 0,
224   'X', 0,
225 };
226
227 CODE const char Str4Desc[] =    /* 4 = configuration */
228 {
229   34, 0x03,
230   'C', 0,
231   'o', 0,
232   'n', 0,
233   'f', 0,
234   'i', 0,
235   'g', 0,
236   'u', 0,
237   'r', 0,
238   'a', 0,
239   't', 0,
240   'i', 0,
241   'o', 0,
242   'n', 0,
243   ' ', 0,
244   '#', 0,
245   '1', 0
246 };
247 CODE const char Str5Desc[] =    /* 5 = interface */
248 {
249   26, 0x03,
250   'I', 0,
251   'n', 0,
252   't', 0,
253   'e', 0,
254   'r', 0,
255   'f', 0,
256   'a', 0,
257   'c', 0,
258   'e', 0,
259   ' ', 0,
260   '#', 0,
261   '0', 0
262 };
263
264 /* all strings in pointers array */
265 CODE const PUSB_STRING_DESCRIPTOR StringDescriptors[] =
266 {
267   (PUSB_STRING_DESCRIPTOR) Str0Desc,
268   (PUSB_STRING_DESCRIPTOR) Str1Desc,
269   (PUSB_STRING_DESCRIPTOR) Str2Desc,
270   (PUSB_STRING_DESCRIPTOR) Str3Desc,
271   (PUSB_STRING_DESCRIPTOR) Str4Desc,
272   (PUSB_STRING_DESCRIPTOR) Str5Desc
273 };
274
275 #define CNT_STRINGS (sizeof(StringDescriptors)/sizeof(StringDescriptors[0]))
276
277 CODE const USB_DEVICE_CONFIGURATION_ENTRY usb_devdes_configurations[] =
278 {
279   {
280     .pConfigDescription = &ConfigDescription.configuration,
281     .iConfigTotalLength = sizeof(ConfigDescription)
282   }
283 };
284
285 CODE const USB_INTERFACE_DESCRIPTOR *usb_devdes_interfaces[] =
286 {
287   &ConfigDescription.iface_comm,
288   &ConfigDescription.iface_data
289 };
290
291 CODE const USB_DEVICE_DESCRIPTORS_TABLE usb_devdes_table =
292 {
293   .pDeviceDescription = &DeviceDescription,
294   .pConfigurations = usb_devdes_configurations,
295   .pInterfaceDescriptors = usb_devdes_interfaces,
296   .pStrings = StringDescriptors,
297   .iNumStrings = CNT_STRINGS,
298   .bNumEndpoints = NUM_ENDPOINTS,
299   .bNumConfigurations = 1,
300   .bNumInterfaces = 2
301 };
302
303 #endif /* USB_DEFS_MODULE */