Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
usb_cdc_device_descriptors.c
1/*******************************************************************************
2 System Initialization File
3
4 Description:
5 This file contains source code necessary to initialize the MPLAB Harmony
6 module objects in the system.
7 *******************************************************************************/
8
9// DOM-IGNORE-BEGIN
10/*******************************************************************************
11Copyright (c) 2013-2015 released Microchip Technology Inc. All rights reserved.
12
13Microchip licenses to you the right to use, modify, copy and distribute
14Software only when embedded on a Microchip microcontroller or digital signal
15controller that is integrated into your product or third party product
16(pursuant to the sublicense terms in the accompanying license agreement).
17
18You should refer to the license agreement accompanying this Software for
19additional information regarding your rights and obligations.
20
21SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
22EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
23MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
24IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
25CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
26OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
27INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
28CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
29SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
30(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
31 *******************************************************************************/
32// DOM-IGNORE-END
33
34
35#include "driver/usb/usbfs/drv_usbfs.h"
36#include "usb/usb_device.h"
37#include "usb/usb_device_cdc.h"
38
39#include "system_config.h"
40
41uint8_t __attribute__((aligned(512))) endPointTable[DRV_USBFS_ENDPOINTS_NUMBER * 32];
42const DRV_USBFS_INIT drvUSBFSInit =
43{
44 /* Assign the endpoint table */
45 .endpointTable= endPointTable,
46
47 /* Interrupt Source for USB module */
48 .interruptSource = INT_SOURCE_USB_1,
49
50 /* System module initialization */
51 .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
52
53 /* Operation Mode */
54 .operationMode = DRV_USBFS_OPMODE_DEVICE,
55
56 .operationSpeed = USB_SPEED_FULL,
57
58 /* Stop in idle */
59 .stopInIdle = false,
60
61 /* Suspend in sleep */
62 .suspendInSleep = false,
63
64 /* Identifies peripheral (PLIB-level) ID */
65 .usbID = USB_ID_1,
66
67};
68
69/**************************************************
70 * USB Device Function Driver Init Data
71 **************************************************/
72const USB_DEVICE_CDC_INIT cdcInit0 =
73{
74 .queueSizeRead = 1,
75 .queueSizeWrite = 1,
76 .queueSizeSerialStateNotification = 1
77};
78/**************************************************
79 * USB Device Layer Function Driver Registration
80 * Table
81 **************************************************/
82const USB_DEVICE_FUNCTION_REGISTRATION_TABLE funcRegistrationTable[1] =
83{
84 /* Function 1 */
85 {
86 .configurationValue = 1, /* Configuration value */
87 .interfaceNumber = 0, /* First interfaceNumber of this function */
88 .speed = USB_SPEED_FULL, /* Function Speed */
89 .numberOfInterfaces = 2, /* Number of interfaces */
90 .funcDriverIndex = 0, /* Index of CDC Function Driver */
91 .driver = (void*)USB_DEVICE_CDC_FUNCTION_DRIVER, /* USB CDC function data exposed to device layer */
92 .funcDriverInit = (void*)&cdcInit0 /* Function driver init data */
93 },
94};
95
96/*******************************************
97 * USB Device Layer Descriptors
98 *******************************************/
99/*******************************************
100 * USB Device Descriptor
101 *******************************************/
102const USB_DEVICE_DESCRIPTOR deviceDescriptor =
103{
104 0x12, // Size of this descriptor in bytes
105 USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
106 0x0200, // USB Spec Release Number in BCD format
107 USB_CDC_CLASS_CODE, // Class Code
108 USB_CDC_SUBCLASS_CODE, // Subclass code
109 0x00, // Protocol code
110 USB_DEVICE_EP0_BUFFER_SIZE, // Max packet size for EP0, see system_config.h
111 0x04D8, // Vendor ID
112 0x000A, // Product ID
113 0x0100, // Device release number in BCD format
114 0x01, // Manufacturer string index
115 0x02, // Product string index
116 0x00, // Device serial number string index
117 0x01 // Number of possible configurations
118};
119
120
121/*******************************************
122 * USB Full Speed Configuration Descriptor
123 *******************************************/
124const uint8_t fullSpeedConfigurationDescriptor[]=
125{
126 /* Configuration Descriptor */
127
128 0x09, // Size of this descriptor in bytes
129 USB_DESCRIPTOR_CONFIGURATION, // Descriptor Type
130 67,0, //(67 Bytes)Size of the Config descriptor.e
131 2, // Number of interfaces in this cfg
132 0x01, // Index value of this configuration
133 0x00, // Configuration string index
134 USB_ATTRIBUTE_DEFAULT | USB_ATTRIBUTE_SELF_POWERED, // Attributes
135 50, // Max power consumption (2X mA)
136 /* Descriptor for Function 1 - CDC */
137
138 /* Interface Descriptor */
139
140 0x09, // Size of this descriptor in bytes
141 USB_DESCRIPTOR_INTERFACE, // Descriptor Type
142 0, // Interface Number
143 0x00, // Alternate Setting Number
144 0x01, // Number of endpoints in this interface
145 USB_CDC_COMMUNICATIONS_INTERFACE_CLASS_CODE, // Class code
146 USB_CDC_SUBCLASS_ABSTRACT_CONTROL_MODEL, // Subclass code
147 USB_CDC_PROTOCOL_AT_V250, // Protocol code
148 0x00, // Interface string index
149
150 /* CDC Class-Specific Descriptors */
151
152 sizeof(USB_CDC_HEADER_FUNCTIONAL_DESCRIPTOR), // Size of the descriptor
153 USB_CDC_DESC_CS_INTERFACE, // CS_INTERFACE
154 USB_CDC_FUNCTIONAL_HEADER, // Type of functional descriptor
155 0x20,0x01, // CDC spec version
156
157 sizeof(USB_CDC_ACM_FUNCTIONAL_DESCRIPTOR), // Size of the descriptor
158 USB_CDC_DESC_CS_INTERFACE, // CS_INTERFACE
159 USB_CDC_FUNCTIONAL_ABSTRACT_CONTROL_MANAGEMENT, // Type of functional descriptor
160 USB_CDC_ACM_SUPPORT_LINE_CODING_LINE_STATE_AND_NOTIFICATION,// bmCapabilities of ACM
161
162 sizeof(USB_CDC_UNION_FUNCTIONAL_DESCRIPTOR_HEADER) + 1, // Size of the descriptor
163 USB_CDC_DESC_CS_INTERFACE, // CS_INTERFACE
164 USB_CDC_FUNCTIONAL_UNION, // Type of functional descriptor
165 0, // com interface number
166 1,
167
168 sizeof(USB_CDC_CALL_MANAGEMENT_DESCRIPTOR), // Size of the descriptor
169 USB_CDC_DESC_CS_INTERFACE, // CS_INTERFACE
170 USB_CDC_FUNCTIONAL_CALL_MANAGEMENT, // Type of functional descriptor
171 0x00, // bmCapabilities of CallManagement
172 1, // Data interface number
173
174 /* Interrupt Endpoint (IN) Descriptor */
175
176 0x07, // Size of this descriptor
177 USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
178 1 | USB_EP_DIRECTION_IN, // EndpointAddress ( EP1 IN INTERRUPT)
179 USB_TRANSFER_TYPE_INTERRUPT, // Attributes type of EP (INTERRUPT)
180 0x10,0x00, // Max packet size of this EP
181 0x02, // Interval (in ms)
182
183 /* Interface Descriptor */
184
185 0x09, // Size of this descriptor in bytes
186 USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
187 1, // Interface Number
188 0x00, // Alternate Setting Number
189 0x02, // Number of endpoints in this interface
190 USB_CDC_DATA_INTERFACE_CLASS_CODE, // Class code
191 0x00, // Subclass code
192 USB_CDC_PROTOCOL_NO_CLASS_SPECIFIC, // Protocol code
193 0x00, // Interface string index
194
195 /* Bulk Endpoint (OUT) Descriptor */
196
197 0x07, // Size of this descriptor
198 USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
199 2 | USB_EP_DIRECTION_OUT, // EndpointAddress ( EP2 OUT )
200 USB_TRANSFER_TYPE_BULK, // Attributes type of EP (BULK)
201 0x40,0x00, // Max packet size of this EP
202 0x00, // Interval (in ms)
203
204 /* Bulk Endpoint (IN)Descriptor */
205
206 0x07, // Size of this descriptor
207 USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
208 2 | USB_EP_DIRECTION_IN, // EndpointAddress ( EP2 IN )
209 0x02, // Attributes type of EP (BULK)
210 0x40,0x00, // Max packet size of this EP
211 0x00, // Interval (in ms)
212
213
214};
215
216/*******************************************
217 * Array of Full speed config descriptors
218 *******************************************/
219USB_DEVICE_CONFIGURATION_DESCRIPTORS_TABLE fullSpeedConfigDescSet[1] =
220{
221 fullSpeedConfigurationDescriptor
222};
223
224
225/**************************************
226 * String descriptors.
227 *************************************/
228
229 /*******************************************
230 * Language code string descriptor
231 *******************************************/
232 const struct
233 {
234 uint8_t bLength;
235 uint8_t bDscType;
236 uint16_t string[1];
237 }
238 sd000 =
239 {
240 sizeof(sd000), // Size of this descriptor in bytes
241 USB_DESCRIPTOR_STRING, // STRING descriptor type
242 {0x0409} // Language ID
243 };
244/*******************************************
245 * Manufacturer string descriptor
246 *******************************************/
247 const struct
248 {
249 uint8_t bLength; // Size of this descriptor in bytes
250 uint8_t bDscType; // STRING descriptor type
251 uint16_t string[7]; // String
252 }
253 sd001 =
254 {
255 sizeof(sd001),
256 USB_DESCRIPTOR_STRING,
257 {'O', 'p', 'e', 'n', 'M', 'R', 'N'}
258 };
259
260/*******************************************
261 * Product string descriptor
262 *******************************************/
263 const struct
264 {
265 uint8_t bLength; // Size of this descriptor in bytes
266 uint8_t bDscType; // STRING descriptor type
267 uint16_t string[17]; // String
268 }
269 sd002 =
270 {
271 sizeof(sd002),
272 USB_DESCRIPTOR_STRING,
273 {'V', 'i', 'r', 't', 'u', 'a', 'l', ' ', 'C', 'O', 'M', ' ',
274 'P', 'o', 'r', 't'}
275 };
276
277/***************************************
278 * Array of string descriptors
279 ***************************************/
280USB_DEVICE_STRING_DESCRIPTORS_TABLE stringDescriptors[3]=
281{
282 (const uint8_t *const)&sd000,
283 (const uint8_t *const)&sd001,
284 (const uint8_t *const)&sd002
285};
286
287/*******************************************
288 * USB Device Layer Master Descriptor Table
289 *******************************************/
290const USB_DEVICE_MASTER_DESCRIPTOR usbMasterDescriptor =
291{
292 &deviceDescriptor, /* Full speed descriptor */
293 1, /* Total number of full speed configurations available */
294 fullSpeedConfigDescSet, /* Pointer to array of full speed configurations descriptors*/
295 NULL,
296 0,
297 NULL,
298 3, // Total number of string descriptors available.
299 stringDescriptors, // Pointer to array of string descriptors.
300 NULL,
301 NULL
302};
303
304
305/****************************************************
306 * USB Device Layer Initialization Data
307 ****************************************************/
308const USB_DEVICE_INIT usbDevInitData =
309{
310 /* System module initialization */
311 .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
312
313 /* Number of function drivers registered to this instance of the
314 USB device layer */
315 .registeredFuncCount = 1,
316
317 /* Function driver table registered to this instance of the USB device layer*/
318 .registeredFunctions = (USB_DEVICE_FUNCTION_REGISTRATION_TABLE*)funcRegistrationTable,
319
320 /* Pointer to USB Descriptor structure */
321 .usbMasterDescriptor = (USB_DEVICE_MASTER_DESCRIPTOR*)&usbMasterDescriptor,
322
323 /* USB Device Speed */
324 .deviceSpeed = USB_SPEED_FULL,
325
326 /* Index of the USB Driver to be used by this Device Layer Instance */
327 .driverIndex = DRV_USBFS_INDEX_0,
328
329 /* Pointer to the USB Driver Functions. */
330 .usbDriverInterface = DRV_USBFS_DEVICE_INTERFACE,
331
332};
const USB_DEVICE_INIT usbDevInitData
Initialization structure in flash.