GD32F1x0: USB/GD32_USB_Device_Library/Class/cdc_printer_wrapper/src/usbd_printer_cdc_wrapper.c Source File

GD32F1x0

usbd_printer_cdc_wrapper.c
Go to the documentation of this file.
1 
10 /* Includes ------------------------------------------------------------------*/
12 
13 /* Private variables ---------------------------------------------------------*/
14 static uint8_t USBD_PRINTER_CDC_Init (void *pudev, uint8_t ConfigIndex);
15 static uint8_t USBD_PRINTER_CDC_DeInit (void *pudev, uint8_t ConfigIndex);
16 static uint8_t USBD_PRINTER_CDC_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req);
17 static uint8_t USBD_PRINTER_CDC_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req);
18 static uint8_t USBD_PRINTER_CDC_GetInterface (void *pudev, USB_DEVICE_REQ *req);
19 static uint8_t USBD_PRINTER_CDC_SetInterface (void *pudev, USB_DEVICE_REQ *req);
20 static uint8_t USBD_PRINTER_CDC_EP0_RxReady (void *pudev);
21 static uint8_t USBD_PRINTER_CDC_DataIn (void *pudev, uint8_t EpID);
22 static uint8_t USBD_PRINTER_CDC_DataOut (void *pudev, uint8_t EpID);
23 static uint8_t USBD_PRINTER_CDC_SOF (void *pudev);
24 static uint8_t* USBD_PRINTER_CDC_GetCfgDesc (uint8_t USBSpeed, uint16_t *len);
25 
26 /* HID_CDC_CORE_Private_Variables */
27 USBD_Class_cb_TypeDef USBD_PRINTER_CDC_cb =
28 {
29  USBD_PRINTER_CDC_Init,
30  USBD_PRINTER_CDC_DeInit,
31  USBD_PRINTER_CDC_GetClassDescriptor,
32  USBD_PRINTER_CDC_ClassReqHandle,
33  USBD_PRINTER_CDC_GetInterface,
34  USBD_PRINTER_CDC_SetInterface,
35  NULL, /* EP0_TxSent */
36  USBD_PRINTER_CDC_EP0_RxReady,
37  USBD_PRINTER_CDC_DataIn,
38  USBD_PRINTER_CDC_DataOut,
39  USBD_PRINTER_CDC_SOF,
40  USBD_PRINTER_CDC_GetCfgDesc,
41  NULL
42 };
43 
44 /* USB CDC_PRINTER device Configuration Descriptor */
45 const uint8_t USBD_PRINTER_CDC_CfgDesc[USB_PRINTER_CDC_CONFIG_DESC_SIZE] =
46 {
47  0x09, /* bLength: Configuration Descriptor size */
48  USB_DESCTYPE_CONFIGURATION, /* bDescriptorType: Configuration */
49  USB_PRINTER_CDC_CONFIG_DESC_SIZE,/* wTotalLength: configuration descriptor set total length */
50  0x00,
51  0x03, /* bNumInterfaces: 3 interfaces (2 for CDC, 1 for PRINTER) */
52  0x01, /* bConfigurationValue: Configuration value */
53  0x00, /* iConfiguration: Index of string descriptor describing the configuration */
54  0xE0, /* bmAttributes: bus powered and Support Remote Wake-up */
55  0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */
56 
57  /************** interface descriptor ****************/
58  0x09, /* bLength: interface descriptor size */
59  USB_DESCTYPE_INTERFACE,/* bDescriptorType: interface descriptor type */
60  PRINTER_INTERFACE, /* bInterfaceNumber: number of interface */
61  0x00, /* bAlternateSetting: alternate setting */
62  0x02, /* bNumEndpoints: use 2 endpoints for Tx/Rx */
63  0x07, /* bInterfaceClass: Printing class */
64  0x01, /* bInterfaceSubClass: 01 = Printers */
65  0x02, /* nInterfaceProtocol: 02 = Bi-directional interface */
66  0x00, /* iInterface: index of interface string descriptor */
67 
68  /******************** Printer IN endpoint descriptor ********************/
69  0x07, /* bLength: Endpoint Descriptor size */
70  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
71  PRINTER_IN_EP, /* bEndpointAddress: endpoint address (EP1_IN) */
72  0x02, /* bmAttributes: endpoint attribute(bulk endpoint) */
73  PRINTER_IN_PACKET, /* wMaxPacketSize: 64 bytes max */
74  0x00,
75  0x00, /* bInterval: polling interval */
76 
77  /******************** Printer OUT endpoint descriptor ********************/
78  0x07, /* bLength: Endpoint Descriptor size */
79  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
80  PRINTER_OUT_EP, /* bEndpointAddress: endpoint address (EP1_OUT) */
81  0x02, /* bmAttributes: endpoint attribute(bulk endpoint) */
82  PRINTER_OUT_PACKET, /* wMaxPacketSize: 64 bytes max */
83  0x00,
84  0x00, /* bInterval: polling interval */
85 
86  /******** IAD should be positioned just before the CDC interfaces ******
87  IAD to associate the two CDC interfaces */
88  0x08, /* bLength */
89  0x0B, /* bDescriptorType */
90  0x01, /* bFirstInterface */
91  0x02, /* bInterfaceCount */
92  0x02, /* bFunctionClass */
93  0x02, /* bFunctionSubClass */
94  0x01, /* bFunctionProtocol */
95  0x00, /* iFunction (Index of string descriptor describing this function) */
96 
97  /*************************** CDC interfaces *******************************/
98 
99  /*Interface Descriptor */
100  0x09, /* bLength: Interface Descriptor size */
101  USB_DESCTYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
102  CDC_COM_INTERFACE, /* bInterfaceNumber: Number of Interface */
103  0x00, /* bAlternateSetting: Alternate setting */
104  0x01, /* bNumEndpoints: One endpoints used */
105  0x02, /* bInterfaceClass: Communication Interface Class */
106  0x02, /* bInterfaceSubClass: Abstract Control Model */
107  0x01, /* bInterfaceProtocol: Common AT commands */
108  0x01, /* iInterface: index of interface string descriptor */
109 
110  /*Header Functional Descriptor*/
111  0x05, /* bLength: Endpoint Descriptor size */
112  0x24, /* bDescriptorType: CS_INTERFACE */
113  0x00, /* bDescriptorSubtype: Header Func Desc */
114  0x10, /* bcdCDC: spec release number */
115  0x01,
116 
117  /*Call Management Functional Descriptor*/
118  0x05, /* bFunctionLength */
119  0x24, /* bDescriptorType: CS_INTERFACE */
120  0x01, /* bDescriptorSubtype: Call Management Func Desc */
121  0x00, /* bmCapabilities: D0 is reset, D1 is ignored */
122  0x02, /* bDataInterface: 2 interface used for call management */
123 
124  /*ACM Functional Descriptor*/
125  0x04, /* bFunctionLength */
126  0x24, /* bDescriptorType: CS_INTERFACE */
127  0x02, /* bDescriptorSubtype: Abstract Control Management desc */
128  0x02, /* bmCapabilities: D1 */
129 
130  /*Union Functional Descriptor*/
131  0x05, /* bFunctionLength */
132  0x24, /* bDescriptorType: CS_INTERFACE */
133  0x06, /* bDescriptorSubtype: Union func desc */
134  0x01, /* bMasterInterface: Communication class interface */
135  0x02, /* bSlaveInterface0: Data Class Interface */
136 
137  /*Endpoint 2 Descriptor*/
138  0x07, /* bLength: Endpoint Descriptor size */
139  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: Endpoint */
140  CDC_CMD_EP, /* bEndpointAddress: endpoint address(EP2_IN) */
141  0x03, /* bmAttributes: Interrupt */
142  LOWBYTE(USB_CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: 8 bytes max */
143  HIGHBYTE(USB_CDC_CMD_PACKET_SIZE),
144  0xFF, /* bInterval: polling interval(255ms) */
145 
146  /*Data class interface descriptor*/
147  0x09, /* bLength: Endpoint Descriptor size */
148  USB_DESCTYPE_INTERFACE, /* bDescriptorType: */
149  0x02, /* bInterfaceNumber: Number of Interface */
150  0x00, /* bAlternateSetting: Alternate setting */
151  0x02, /* bNumEndpoints: 2 endpoints used */
152  0x0A, /* bInterfaceClass: CDC class */
153  0x00, /* bInterfaceSubClass: no set*/
154  0x00, /* bInterfaceProtocol: no set */
155  0x00, /* iInterface: no set */
156 
157  /*Endpoint OUT Descriptor*/
158  0x07, /* bLength: Endpoint Descriptor size */
159  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
160  CDC_DATA_OUT_EP, /* bEndpointAddress: endpoint address */
161  0x02, /* bmAttributes: Bulk */
162  0x40, /* wMaxPacketSize: 64 bytes max */
163  0x00,
164  0x00, /* bInterval: ignore for Bulk transfer */
165 
166  /*Endpoint IN Descriptor*/
167  0x07, /* bLength: Endpoint Descriptor size */
168  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
169  CDC_DATA_IN_EP, /* bEndpointAddress: endpoint address */
170  0x02, /* bmAttributes: Bulk */
171  0x40, /* wMaxPacketSize: 64 bytes max */
172  0x00,
173  0x00, /* bInterval: ignore for Bulk transfer */
174 };
175 
176 /* Private function prototypes -----------------------------------------------*/
177 extern USBD_Class_cb_TypeDef USBD_PRINTER_cb;
178 extern USBD_Class_cb_TypeDef USBD_CDC_cb;
179 
180 /* Private function ----------------------------------------------------------*/
181 
188 static uint8_t USBD_PRINTER_CDC_Init (void *pudev, uint8_t ConfigIndex)
189 {
190  /* HID initialization */
191  USBD_PRINTER_cb.Init(pudev, ConfigIndex);
192 
193  /* CDC initialization */
194  USBD_CDC_cb.Init(pudev, ConfigIndex);
195 
196  return USBD_OK;
197 }
198 
205 static uint8_t USBD_PRINTER_CDC_DeInit (void *pudev, uint8_t ConfigIndex)
206 {
207  /* PRINTER De-initialization */
208  USBD_PRINTER_cb.DeInit(pudev, ConfigIndex);
209 
210  /* CDC De-initialization */
211  USBD_CDC_cb.DeInit(pudev, ConfigIndex);
212 
213  return USBD_OK;
214 }
215 
222 static uint8_t USBD_PRINTER_CDC_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req)
223 {
224  if (req->wIndex == PRINTER_INTERFACE)
225  {
226  return USBD_PRINTER_cb.GetClassDescriptor(pudev, req);
227  }
228  else
229  {
230  return USBD_CDC_cb.GetClassDescriptor(pudev, req);
231  }
232 }
233 
234 
241 static uint8_t USBD_PRINTER_CDC_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req)
242 {
243  if (req->wIndex == PRINTER_INTERFACE)
244  {
245  return USBD_PRINTER_cb.ClassReqHandle(pudev, req);
246  }
247  else
248  {
249  return USBD_CDC_cb.ClassReqHandle(pudev, req);
250  }
251 }
252 
259 static uint8_t USBD_PRINTER_CDC_GetInterface (void *pudev, USB_DEVICE_REQ *req)
260 {
261  if (req->wIndex == PRINTER_INTERFACE)
262  {
263  return USBD_PRINTER_cb.GetInterface(pudev, req);
264  }
265  else
266  {
267  return USBD_CDC_cb.GetInterface(pudev, req);
268  }
269 }
270 
277 static uint8_t USBD_PRINTER_CDC_SetInterface (void *pudev, USB_DEVICE_REQ *req)
278 {
279  if (req->wIndex == PRINTER_INTERFACE)
280  {
281  return USBD_PRINTER_cb.SetInterface(pudev, req);
282  }
283  else
284  {
285  return USBD_CDC_cb.SetInterface(pudev, req);
286  }
287 }
288 
295 static uint8_t* USBD_PRINTER_CDC_GetCfgDesc (uint8_t USBSpeed, uint16_t *len)
296 {
297  *len = sizeof (USBD_PRINTER_CDC_CfgDesc);
298 
299  return (uint8_t*)USBD_PRINTER_CDC_CfgDesc;
300 }
301 
308 static uint8_t USBD_PRINTER_CDC_DataIn (void *pudev, uint8_t EpID)
309 {
310  /*DataIN can be for CDC or HID */
311  if (EpID == (CDC_DATA_IN_EP & ~0x80))
312  {
313  return USBD_CDC_cb.DataIn(pudev, EpID);
314  }
315  else
316  {
317  return USBD_PRINTER_cb.DataIn(pudev, EpID);
318  }
319 }
320 
327 uint8_t USBD_PRINTER_CDC_DataOut(void *pudev , uint8_t EpID)
328 {
329  /*DataOut can be for CDC or HID */
330  if (EpID == (CDC_DATA_OUT_EP & ~0x80))
331  {
332  return USBD_CDC_cb.DataOut(pudev, EpID);
333  }
334  else
335  {
336  return USBD_PRINTER_cb.DataOut(pudev, EpID);
337  }
338 }
339 
345 uint8_t USBD_PRINTER_CDC_SOF (void *pudev)
346 {
347  /*SOF processing needed for CDC */
348  return USBD_CDC_cb.SOF(pudev);
349 }
350 
356 static uint8_t USBD_PRINTER_CDC_EP0_RxReady (void *pudev)
357 {
358  /* RxReady processing needed for CDC */
359  USBD_CDC_cb.EP0_RxReady(pudev);
360 
361  return USBD_OK;
362 }
363 
364 /************************ (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_printer_cdc_wrapper.c file.
USB standard device request struct.
Definition: usb_core.h:122
Generated by   doxygen 1.8.10