2 #ifndef USB_DEFS_MODULE
3 #define USB_DEFS_MODULE
5 #include <usb/usb_spec.h>
6 #include <usb/usb_cdc.h>
7 #include <usb/lpcusb.h>
12 #if __BYTE_ORDER == __BIG_ENDIAN
14 #define SWAP(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
15 #else /*__LITTLE_ENDIAN*/
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
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
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
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))
51 /*** Device descriptor ***/
52 CODE const USB_DEVICE_DESCRIPTOR DeviceDescription =
54 sizeof(USB_DEVICE_DESCRIPTOR),
55 USB_DESCRIPTOR_TYPE_DEVICE,
63 SWAP(USB_RELEASE_VER),
64 1, /* manufacturer string ID */
65 2, /* product string ID */
66 3, /* serial number string ID */
70 /*** All In Configuration 0 ***/
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 =
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 */
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,
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) */
116 /*** CDC CALL MANAGEMENT Descriptor ***/
117 sizeof(USBCDC_CALLMGMT_FCN_DESCRIPTOR),
118 USBCDC_COM_FCN_TYPE_CS_INTERFACE,
119 USBCDC_COM_FCN_SUBTYPE_CALLMGMT,
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,
131 /*** CDC UNION Descriptor ***/
132 sizeof(USBCDC_UNION_FCN_DESCRIPTOR),
133 USBCDC_COM_FCN_TYPE_CS_INTERFACE,
134 USBCDC_COM_FCN_SUBTYPE_UNION,
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) */
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) */
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) */
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) */
179 /*** Strings - in unicode ***/
180 CODE const char Str0Desc[] = /* supported languages of strings */
182 4, 0x03, /* 2+2*N , N is count of supported languages */
183 0x09, 0x04 /* english 0x0409 */
186 CODE const char Str1Desc[] = /* 1 = manufacturer */
202 CODE const char Str2Desc[] = /* 2 = product */
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 */
227 CODE const char Str4Desc[] = /* 4 = configuration */
247 CODE const char Str5Desc[] = /* 5 = interface */
264 /* all strings in pointers array */
265 CODE const PUSB_STRING_DESCRIPTOR StringDescriptors[] =
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
275 #define CNT_STRINGS (sizeof(StringDescriptors)/sizeof(StringDescriptors[0]))
277 CODE const USB_DEVICE_CONFIGURATION_ENTRY usb_devdes_configurations[] =
280 .pConfigDescription = &ConfigDescription.configuration,
281 .iConfigTotalLength = sizeof(ConfigDescription)
285 CODE const USB_INTERFACE_DESCRIPTOR *usb_devdes_interfaces[] =
287 &ConfigDescription.iface_comm,
288 &ConfigDescription.iface_data
291 CODE const USB_DEVICE_DESCRIPTORS_TABLE usb_devdes_table =
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,
303 #endif /* USB_DEFS_MODULE */