]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-dad.git/blob - sw/app/lx_dad/usb/usb_defs.h
eecc8de88ac5bc8b0e81e2bcea0a37b13b11c41e
[fpga/lx-cpu1/lx-dad.git] / sw / app / lx_dad / 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     0x1027  /* Number reserved for LX_DAD 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
40 #define CONFIG_DESCRIPTOR_LENGTH \
41   sizeof(USB_CONFIGURATION_DESCRIPTOR) \
42    + sizeof(USB_INTERFACE_DESCRIPTOR) \
43    + sizeof(USBCDC_HEADER_FCN_DESCRIPTOR) \
44    + sizeof(USBCDC_CALLMGMT_FCN_DESCRIPTOR) \
45    + sizeof(USBCDC_ACM_FCN_DESCRIPTOR) \
46    + sizeof(USBCDC_UNION_FCN_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 {
53   sizeof(USB_DEVICE_DESCRIPTOR),
54   USB_DESCRIPTOR_TYPE_DEVICE,
55   SWAP(0x0120),
56   USB_CLASS_CODE,
57   USB_SUBCLASS_CODE,
58   USB_PROTOCOL_CODE,
59   USB_MAX_PACKET0,
60   SWAP(USB_VENDOR_ID),
61   SWAP(USB_PRODUCT_ID),
62   SWAP(USB_RELEASE_VER),
63   1, /* manufacturer string ID */
64   2, /* product string ID */
65   3, /* serial number string ID */
66   1  /* bNumConfigs */
67 };
68
69 /*** All In Configuration 0 ***/
70 CODE const struct
71 {
72   USB_CONFIGURATION_DESCRIPTOR configuration;
73   USB_INTERFACE_DESCRIPTOR        iface_comm;
74   USBCDC_HEADER_FCN_DESCRIPTOR    cdcheader;
75   USBCDC_CALLMGMT_FCN_DESCRIPTOR  cdccallmgt;
76   USBCDC_ACM_FCN_DESCRIPTOR       cdcacm;
77   USBCDC_UNION_FCN_DESCRIPTOR     cdcunion;
78   USB_ENDPOINT_DESCRIPTOR         ep_notification;
79   USB_INTERFACE_DESCRIPTOR        iface_data;
80   USB_ENDPOINT_DESCRIPTOR         ep_rxd;
81   USB_ENDPOINT_DESCRIPTOR         ep_txd;
82 } PACKED ConfigDescription =
83 {
84   {
85     /*** Configuration descriptor ***/
86     sizeof(USB_CONFIGURATION_DESCRIPTOR),
87     USB_DESCRIPTOR_TYPE_CONFIGURATION,
88     SWAP(CONFIG_DESCRIPTOR_LENGTH),
89     2, /* cnt of interfaces */
90     1, /* this configuration ID */
91     4, /* config.name string ID */
92     USB_CONFIG_BUS_POWERED, /* CbmAttributes (bus powered) */
93     250    /* device power current from host 500mA / 2 */
94   },
95   {
96     /*** Interface Descriptor ***/
97     sizeof(USB_INTERFACE_DESCRIPTOR),
98     USB_DESCRIPTOR_TYPE_INTERFACE,
99     0,    /* index of this interface for SetInterface request */
100     0,    /* ID alternate interface */
101     1,    /* number of endpoints in interface */
102     USB_DEVICE_CLASS_COMMUNICATIONS,
103     USBCDC_COM_IFACE_SUBCLS_ACM,
104     0,    /* protocol */
105     5
106   },
107   {
108     /*** CDC Header Descriptor ***/
109     sizeof(USBCDC_HEADER_FCN_DESCRIPTOR),
110     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
111     USBCDC_COM_FCN_SUBTYPE_HEADER,    /* bDescriptorSubtype */
112     SWAP(0x0120),                     /* bcdCDC (spec. release 1.2) */
113   },
114   {
115     /*** CDC CALL MANAGEMENT Descriptor ***/
116     sizeof(USBCDC_CALLMGMT_FCN_DESCRIPTOR),
117     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
118     USBCDC_COM_FCN_SUBTYPE_CALLMGMT,
119     0,
120     1,
121   },
122   {
123     /*** CDC ABSTRACT CONTROL MANAGEMENT Descriptor ***/
124     sizeof(USBCDC_ACM_FCN_DESCRIPTOR),
125     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
126     USBCDC_COM_FCN_SUBTYPE_ACMGMT,
127     USBCDC_ACM_FCN_CAP_SUPPORT_LINECTRL,
128   },
129   {
130     /*** CDC UNION Descriptor ***/
131     sizeof(USBCDC_UNION_FCN_DESCRIPTOR),
132     USBCDC_COM_FCN_TYPE_CS_INTERFACE,
133     USBCDC_COM_FCN_SUBTYPE_UNION,
134     0,
135     1,
136   },
137   {
138     /*** Endpoint 1 IN, type interrupt ***/
139     sizeof(USB_ENDPOINT_DESCRIPTOR),
140     USB_DESCRIPTOR_TYPE_ENDPOINT,
141     CDC0_EP_NOTIFY,                   /* bEndpointAddress */
142     USB_ENDPOINT_TYPE_INTERRUPT,
143     SWAP(USB_MAX_PACKET),
144     0x80,                             /* bInterval (polling interval: 50ms) */
145   },
146   {
147     /*** Interface Descriptor ***/
148     sizeof(USB_INTERFACE_DESCRIPTOR),
149     USB_DESCRIPTOR_TYPE_INTERFACE,
150     1,                                /* bInterfaceNumber */
151     0,                                /* bAlternateSetting */
152     2,                                /* number of EPs */
153     USB_DEVICE_CLASS_CDC_DATA,        /* bInterfaceClass */
154     0,                                /* bInterfaceSubclass */
155     0,                                /* bDeviceProtocol */
156     0,                                /* iInterface (string, 0=none) */
157   },
158   {
159     /*** Endpoint 2 OUT, type bulk ***/
160     sizeof(USB_ENDPOINT_DESCRIPTOR),
161     USB_DESCRIPTOR_TYPE_ENDPOINT,
162     CDC0_EP_RXD,                      /* bEndpointAddress */
163     USB_ENDPOINT_TYPE_BULK,
164     SWAP(USB_MAX_PACKET),
165     0,                                /* bInterval (polling interval: 50ms) */
166   },
167   {
168     /*** Endpoint 2 IN, type bulk ***/
169     sizeof(USB_ENDPOINT_DESCRIPTOR),
170     USB_DESCRIPTOR_TYPE_ENDPOINT,
171     CDC0_EP_TXD,                      /* bEndpointAddress */
172     USB_ENDPOINT_TYPE_BULK,
173     SWAP(USB_MAX_PACKET),
174     0,                                /* bInterval (polling interval: 50ms) */
175   }
176 };
177
178 /*** Strings - in unicode ***/
179 CODE const char Str0Desc[] =    /* supported languages of strings */
180 {
181   4, 0x03,  /* 2+2*N , N is count of supported languages */
182   0x09, 0x04 /* english 0x0409 */
183 };
184
185 CODE const char Str1Desc[] =    /* 1 = manufacturer */
186 {
187   24, 0x03,
188   'P', 0,
189   'i', 0,
190   'K', 0,
191   'R', 0,
192   'O', 0,
193   'N', 0,
194   ' ', 0,
195   'L', 0,
196   't', 0,
197   'd', 0,
198   '.', 0,
199 };
200
201 CODE const char Str2Desc[] =    /* 2 = product */
202 {
203   14, 0x03,
204   'L', 0,
205   'X', 0,
206   '_', 0,
207   'D', 0,
208   'A', 0,
209   'D', 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 */