GD32F1x0: USB/GD32_USB_Device_Library/Class/cdc_msc_wrapper/src/usbd_msc_cdc_wrapper.c Source File

GD32F1x0

usbd_msc_cdc_wrapper.c
Go to the documentation of this file.
1 
10 /* Includes ------------------------------------------------------------------*/
11 #include "usbd_msc_cdc_wrapper.h"
12 
13 /* Private variables ---------------------------------------------------------*/
14 static uint8_t USBD_MSC_CDC_Init (void *pudev, uint8_t ConfigIndex);
15 static uint8_t USBD_MSC_CDC_DeInit (void *pudev, uint8_t ConfigIndex);
16 static uint8_t USBD_MSC_CDC_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req);
17 static uint8_t USBD_MSC_CDC_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req);
18 static uint8_t USBD_MSC_CDC_GetInterface (void *pudev, USB_DEVICE_REQ *req);
19 static uint8_t USBD_MSC_CDC_SetInterface (void *pudev, USB_DEVICE_REQ *req);
20 static uint8_t USBD_MSC_CDC_EP0_RxReady (void *pudev);
21 static uint8_t USBD_MSC_CDC_DataIn (void *pudev, uint8_t EpID);
22 static uint8_t USBD_MSC_CDC_DataOut (void *pudev, uint8_t EpID);
23 static uint8_t USBD_MSC_CDC_SOF (void *pudev);
24 static uint8_t* USBD_MSC_CDC_GetCfgDesc (uint8_t USBSpeed, uint16_t *len);
25 static uint8_t USBD_MSC_CDC_ClearFeature (void *pudev, USB_DEVICE_REQ *req);
26 
27 /* HID_CDC_CORE_Private_Variables */
28 USBD_Class_cb_TypeDef USBD_MSC_CDC_cb =
29 {
30  USBD_MSC_CDC_Init,
31  USBD_MSC_CDC_DeInit,
32  USBD_MSC_CDC_GetClassDescriptor,
33  USBD_MSC_CDC_ClassReqHandle,
34  USBD_MSC_CDC_GetInterface,
35  USBD_MSC_CDC_SetInterface,
36  NULL, /* EP0_TxSent */
37  USBD_MSC_CDC_EP0_RxReady,
38  USBD_MSC_CDC_DataIn,
39  USBD_MSC_CDC_DataOut,
40  USBD_MSC_CDC_SOF,
41  USBD_MSC_CDC_GetCfgDesc,
42  USBD_MSC_CDC_ClearFeature
43 };
44 
45 /* USB CDC_MSC device Configuration Descriptor */
46 const uint8_t USBD_MSC_CDC_CfgDesc[USB_MSC_CDC_CONFIG_DESC_SIZE] =
47 {
48  0x09, /* bLength: Configuration Descriptor size */
49  USB_DESCTYPE_CONFIGURATION, /* bDescriptorType: Configuration */
50  USB_MSC_CDC_CONFIG_DESC_SIZE,/* wTotalLength: configuration descriptor set total length */
51  0x00,
52  0x03, /* bNumInterfaces: 3 interfaces (2 for CDC, 1 for MSC) */
53  0x01, /* bConfigurationValue: Configuration value */
54  0x00, /* iConfiguration: Index of string descriptor describing the configuration */
55  0xE0, /* bmAttributes: bus powered and Support Remote Wake-up */
56  0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */
57 
58  /* IAD */
59  0x08,/* bLength */
60  0x0B,/* bDescriptorType */
61  0x00,/* bFirstInterface */
62  0x01,/* bInterfaceCount */
63  0x08,/* bFunctionClass */
64  0x06,/* bFunctionSubClass */
65  0x50,/* bFunctionProtocol */
66  0x00,/* iFunction (Index of string descriptor describing this function) */
67 
68  /******************** Mass Storage interface ********************/
69  0x09, /* bLength: Interface Descriptor size */
70  0x04, /* bDescriptorType: interface descriptor type */
71  MSC_INTERFACE, /* bInterfaceNumber: Number of Interface */
72  0x00, /* bAlternateSetting: Alternate setting */
73  0x02, /* bNumEndpoints: use 2 endpoints for Tx and Rx */
74  0x08, /* bInterfaceClass: MSC Class */
75  0x06, /* bInterfaceSubClass: SCSI transparent */
76  0x50, /* nInterfaceProtocol: Bulk-only transport */
77  0x01, /* iInterface: index of interface string descriptor */
78 
79  /******************** Mass Storage Endpoints ********************/
80  0x07, /* bLength: Endpoint descriptor length = 7 */
81  0x05, /* bDescriptorType: Endpoint descriptor type */
82  MSC_IN_EP, /* bEndpointAddress: Endpoint address (IN, address 2) */
83  0x02, /* bmAttributes:Bulk endpoint type */
84  LOWBYTE(MSC_DATA_PACKET_SIZE), /* wMaxPacketSize: 64 bytes max */
85  HIGHBYTE(MSC_DATA_PACKET_SIZE),
86  0x00, /* bInterval: polling interval is ignored */
87 
88  0x07, /* bLength: Endpoint descriptor length = 7 */
89  0x05, /* bDescriptorType: Endpoint descriptor type */
90  MSC_OUT_EP,/* bEndpointAddress: Endpoint address (OUT, address 2) */
91  0x02, /* bmAttributes: endpoint attribute(bulk endpoint) */
92  LOWBYTE(MSC_DATA_PACKET_SIZE), /* wMaxPacketSize: 64 bytes max */
93  HIGHBYTE(MSC_DATA_PACKET_SIZE),
94  0x00, /* bInterval: polling interval is ignored */
95 
96  /******** IAD should be positioned just before the CDC interfaces ******
97  IAD to associate the two CDC interfaces */
98  0x08, /* bLength */
99  0x0B, /* bDescriptorType */
100  0x01, /* bFirstInterface */
101  0x02, /* bInterfaceCount */
102  0x02, /* bFunctionClass */
103  0x02, /* bFunctionSubClass */
104  0x01, /* bFunctionProtocol */
105  0x00, /* iFunction (Index of string descriptor describing this function) */
106 
107  /*************************** CDC interfaces *******************************/
108 
109  /*Interface Descriptor */
110  0x09, /* bLength: Interface Descriptor size */
111  USB_DESCTYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
112  CDC_COM_INTERFACE, /* bInterfaceNumber: Number of Interface */
113  0x00, /* bAlternateSetting: Alternate setting */
114  0x01, /* bNumEndpoints: One endpoints used */
115  0x02, /* bInterfaceClass: Communication Interface Class */
116  0x02, /* bInterfaceSubClass: Abstract Control Model */
117  0x01, /* bInterfaceProtocol: Common AT commands */
118  0x01, /* iInterface: index of interface string descriptor */
119 
120  /*Header Functional Descriptor*/
121  0x05, /* bLength: Endpoint Descriptor size */
122  0x24, /* bDescriptorType: CS_INTERFACE */
123  0x00, /* bDescriptorSubtype: Header Func Desc */
124  0x10, /* bcdCDC: spec release number */
125  0x01,
126 
127  /*Call Management Functional Descriptor*/
128  0x05, /* bFunctionLength */
129  0x24, /* bDescriptorType: CS_INTERFACE */
130  0x01, /* bDescriptorSubtype: Call Management Func Desc */
131  0x00, /* bmCapabilities: D0 is reset, D1 is ignored */
132  0x02, /* bDataInterface: 2 interface used for call management */
133 
134  /*ACM Functional Descriptor*/
135  0x04, /* bFunctionLength */
136  0x24, /* bDescriptorType: CS_INTERFACE */
137  0x02, /* bDescriptorSubtype: Abstract Control Management desc */
138  0x02, /* bmCapabilities: D1 */
139 
140  /*Union Functional Descriptor*/
141  0x05, /* bFunctionLength */
142  0x24, /* bDescriptorType: CS_INTERFACE */
143  0x06, /* bDescriptorSubtype: Union func desc */
144  0x01, /* bMasterInterface: Communication class interface */
145  0x02, /* bSlaveInterface0: Data Class Interface */
146 
147  /*Endpoint 2 Descriptor*/
148  0x07, /* bLength: Endpoint Descriptor size */
149  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: Endpoint */
150  CDC_CMD_EP, /* bEndpointAddress: endpoint address(EP2_IN) */
151  0x03, /* bmAttributes: Interrupt */
152  LOWBYTE(USB_CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: 8 bytes max */
153  HIGHBYTE(USB_CDC_CMD_PACKET_SIZE),
154  0xFF, /* bInterval: polling interval(255ms) */
155 
156  /*Data class interface descriptor*/
157  0x09, /* bLength: Endpoint Descriptor size */
158  USB_DESCTYPE_INTERFACE, /* bDescriptorType: */
159  0x02, /* bInterfaceNumber: Number of Interface */
160  0x00, /* bAlternateSetting: Alternate setting */
161  0x02, /* bNumEndpoints: 2 endpoints used */
162  0x0A, /* bInterfaceClass: CDC class */
163  0x00, /* bInterfaceSubClass: no set*/
164  0x00, /* bInterfaceProtocol: no set */
165  0x00, /* iInterface: no set */
166 
167  /*Endpoint OUT Descriptor*/
168  0x07, /* bLength: Endpoint Descriptor size */
169  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
170  CDC_DATA_OUT_EP, /* bEndpointAddress: endpoint address */
171  0x02, /* bmAttributes: Bulk */
172  0x40, /* wMaxPacketSize: 64 bytes max */
173  0x00,
174  0x00, /* bInterval: ignore for Bulk transfer */
175 
176  /*Endpoint IN Descriptor*/
177  0x07, /* bLength: Endpoint Descriptor size */
178  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
179  CDC_DATA_IN_EP, /* bEndpointAddress: endpoint address */
180  0x02, /* bmAttributes: Bulk */
181  0x40, /* wMaxPacketSize: 64 bytes max */
182  0x00,
183  0x00, /* bInterval: ignore for Bulk transfer */
184 };
185 
186 /* Private function prototypes -----------------------------------------------*/
187 extern USBD_Class_cb_TypeDef USBD_MSC_cb;
188 extern USBD_Class_cb_TypeDef USBD_CDC_cb;
189 
190 /* Private function ----------------------------------------------------------*/
191 
198 static uint8_t USBD_MSC_CDC_Init (void *pudev, uint8_t ConfigIndex)
199 {
200  /* HID initialization */
201  USBD_MSC_cb.Init(pudev, ConfigIndex);
202 
203  /* CDC initialization */
204  USBD_CDC_cb.Init(pudev, ConfigIndex);
205 
206  return USBD_OK;
207 }
208 
215 static uint8_t USBD_MSC_CDC_DeInit (void *pudev, uint8_t ConfigIndex)
216 {
217  /* MSC De-initialization */
218  USBD_MSC_cb.DeInit(pudev, ConfigIndex);
219 
220  /* CDC De-initialization */
221  USBD_CDC_cb.DeInit(pudev, ConfigIndex);
222 
223  return USBD_OK;
224 }
225 
232 static uint8_t USBD_MSC_CDC_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req)
233 {
234  if (req->wIndex == MSC_INTERFACE)
235  {
236  return USBD_MSC_cb.GetClassDescriptor(pudev, req);
237  }
238  else
239  {
240  return USBD_CDC_cb.GetClassDescriptor(pudev, req);
241  }
242 }
243 
244 
251 static uint8_t USBD_MSC_CDC_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req)
252 {
253  if (req->wIndex == MSC_INTERFACE)
254  {
255  return USBD_MSC_cb.ClassReqHandle(pudev, req);
256  }
257  else
258  {
259  return USBD_CDC_cb.ClassReqHandle(pudev, req);
260  }
261 }
262 
269 static uint8_t USBD_MSC_CDC_GetInterface (void *pudev, USB_DEVICE_REQ *req)
270 {
271  if (req->wIndex == MSC_INTERFACE)
272  {
273  return USBD_MSC_cb.GetInterface(pudev, req);
274  }
275  else
276  {
277  return USBD_CDC_cb.GetInterface(pudev, req);
278  }
279 }
280 
287 static uint8_t USBD_MSC_CDC_SetInterface (void *pudev, USB_DEVICE_REQ *req)
288 {
289  if (req->wIndex == MSC_INTERFACE)
290  {
291  return USBD_MSC_cb.SetInterface(pudev, req);
292  }
293  else
294  {
295  return USBD_CDC_cb.SetInterface(pudev, req);
296  }
297 }
298 
305 static uint8_t* USBD_MSC_CDC_GetCfgDesc (uint8_t USBSpeed, uint16_t *len)
306 {
307  *len = sizeof (USBD_MSC_CDC_CfgDesc);
308 
309  return (uint8_t*)USBD_MSC_CDC_CfgDesc;
310 }
311 
318 static uint8_t USBD_MSC_CDC_DataIn (void *pudev, uint8_t EpID)
319 {
320  /*DataIN can be for CDC or HID */
321  if (EpID == (CDC_DATA_IN_EP & ~0x80))
322  {
323  return USBD_CDC_cb.DataIn(pudev, EpID);
324  }
325  else
326  {
327  return USBD_MSC_cb.DataIn(pudev, EpID);
328  }
329 }
330 
337 uint8_t USBD_MSC_CDC_DataOut(void *pudev , uint8_t EpID)
338 {
339  /*DataOut can be for CDC or HID */
340  if (EpID == (CDC_DATA_OUT_EP & ~0x80))
341  {
342  return USBD_CDC_cb.DataOut(pudev, EpID);
343  }
344  else
345  {
346  return USBD_MSC_cb.DataOut(pudev, EpID);
347  }
348 }
349 
355 uint8_t USBD_MSC_CDC_SOF (void *pudev)
356 {
357  /*SOF processing needed for CDC */
358  return USBD_CDC_cb.SOF(pudev);
359 }
360 
366 static uint8_t USBD_MSC_CDC_EP0_RxReady (void *pudev)
367 {
368  /* RxReady processing needed for CDC */
369  USBD_CDC_cb.EP0_RxReady(pudev);
370 
371  return USBD_OK;
372 }
373 
374 static uint8_t USBD_MSC_CDC_ClearFeature (void *pudev, USB_DEVICE_REQ *req)
375 {
376  USBD_MSC_cb.ClearFeature(pudev, req);
377 
378  return USBD_OK;
379 }
380 
381 /************************ (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
#define CDC_CMD_EP
USB device class callback type define.
Definition: usb_core.h:153
header file for the usbd_hid_cdc_wrapper.c file.
USB standard device request struct.
Definition: usb_core.h:122
Generated by   doxygen 1.8.10