GD32F1x0: USB/GD32_USB_Device_Library/Class/printer/src/usbd_printer_core.c Source File

GD32F1x0

usbd_printer_core.c
Go to the documentation of this file.
1 
11 /* Includes ------------------------------------------------------------------ */
12 #include "usbd_printer_core.h"
13 
29 static uint8_t USBD_PRINTER_Init (void *pudev, uint8_t ConfigIndex);
30 static uint8_t USBD_PRINTER_DeInit (void *pudev, uint8_t ConfigIndex);
31 static uint8_t USBD_PRINTER_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req);
32 static uint8_t USBD_PRINTER_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req);
33 static uint8_t USBD_PRINTER_GetInterface (void *pudev, USB_DEVICE_REQ *req);
34 static uint8_t USBD_PRINTER_SetInterface (void *pudev, USB_DEVICE_REQ *req);
35 static uint8_t USBD_PRINTER_DataIn (void *pudev, uint8_t EpID);
36 static uint8_t USBD_PRINTER_DataOut (void *pudev, uint8_t EpID);
37 static uint8_t* USBD_PRINTER_GetCfgDesc (uint8_t USBSpeed, uint16_t *len);
38 
42 static uint32_t USBD_PRINTER_AltSet = 0;
43 
44 /* Printer port status: paper not empty/selected/no error */
45 static uint8_t PortStatus = 0x18;
46 
54 USBD_Class_cb_TypeDef USBD_PRINTER_cb =
55 {
56  USBD_PRINTER_Init,
57  USBD_PRINTER_DeInit,
58  USBD_PRINTER_GetClassDescriptor,
59  USBD_PRINTER_ClassReqHandle,
60  USBD_PRINTER_GetInterface,
61  USBD_PRINTER_SetInterface,
62  NULL, /* EP0_TxSent */
63  NULL, /* EP0_RxReady */
64  USBD_PRINTER_DataIn,
65  USBD_PRINTER_DataOut,
66  NULL, /* SOF */
67  USBD_PRINTER_GetCfgDesc,
68 };
69 
70 /* USB Printing device configuration descriptor set */
71 const uint8_t USBD_PRINTER_CfgDesc[USB_PRINTER_CONFIG_DESC_SIZE] =
72 {
73  0x09, /* bLength: configuration descriptor size */
74  USB_DESCTYPE_CONFIGURATION, /* bDescriptorType: configuration descriptor type */
75  USB_PRINTER_CONFIG_DESC_SIZE, /* wTotalLength: configuration descriptor set total length */
76  0x00,
77  0x01, /* bNumInterfaces: 1 interface */
78  0x01, /* bConfigurationValue: configuration value */
79  0x00, /* iConfiguration: index of string descriptor describing the configuration */
80  0xA0, /* bmAttributes: device attributes (bus powered and support remote wakeup) */
81  0x32, /* bMaxPower 100 mA: this current is used for detecting Vbus */
82 
83  /************** interface descriptor ****************/
84  0x09, /* bLength: interface descriptor size */
85  USB_DESCTYPE_INTERFACE,/* bDescriptorType: interface descriptor type */
86  0x00, /* bInterfaceNumber: number of interface */
87  0x00, /* bAlternateSetting: alternate setting */
88  0x02, /* bNumEndpoints: use 2 endpoints for Tx/Rx */
89  0x07, /* bInterfaceClass: Printing class */
90  0x01, /* bInterfaceSubClass: 01 = Printers */
91  0x02, /* nInterfaceProtocol: 02 = Bi-directional interface */
92  0x00, /* iInterface: index of interface string descriptor */
93 
94  /******************** Printer IN endpoint descriptor ********************/
95  0x07, /* bLength: Endpoint Descriptor size */
96  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
97  PRINTER_IN_EP, /* bEndpointAddress: endpoint address (EP1_IN) */
98  0x02, /* bmAttributes: endpoint attribute(bulk endpoint) */
99  PRINTER_IN_PACKET, /* wMaxPacketSize: 64 bytes max */
100  0x00,
101  0x00, /* bInterval: polling interval */
102 
103  /******************** Printer OUT endpoint descriptor ********************/
104  0x07, /* bLength: Endpoint Descriptor size */
105  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
106  PRINTER_OUT_EP, /* bEndpointAddress: endpoint address (EP1_OUT) */
107  0x02, /* bmAttributes: endpoint attribute(bulk endpoint) */
108  PRINTER_OUT_PACKET, /* wMaxPacketSize: 64 bytes max */
109  0x00,
110  0x00, /* bInterval: polling interval */
111 };
112 
127 static uint8_t USBD_PRINTER_Init (void *pudev, uint8_t ConfigIndex)
128 {
129  USB_EP_BufConfig(pudev, PRINTER_IN_EP, USB_SNG_BUFTYPE, PRINTER_TX_ADDRESS);
130  USB_EP_BufConfig(pudev, PRINTER_OUT_EP, USB_SNG_BUFTYPE, PRINTER_RX_ADDRESS);
131 
132  /* Initialize Tx endpoint */
133  USB_EP_Init(pudev,
134  PRINTER_IN_EP,
135  USB_EPTYPE_BULK,
136  PRINTER_IN_PACKET);
137 
138  /* Initialize Rx endpoint */
139  USB_EP_Init(pudev,
140  PRINTER_OUT_EP,
141  USB_EPTYPE_BULK,
142  PRINTER_OUT_PACKET);
143 
144  return USBD_OK;
145 }
146 
153 static uint8_t USBD_PRINTER_DeInit (void *pudev, uint8_t ConfigIndex)
154 {
155  /* Deinitialize HID endpoints */
156  USB_EP_DeInit (pudev, PRINTER_IN_EP);
157  USB_EP_DeInit (pudev, PRINTER_OUT_EP);
158 
159  return USBD_OK;
160 }
161 
168 static uint8_t USBD_PRINTER_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req)
169 {
170  switch (req->bRequest)
171  {
172  case GET_DEVICE_ID:
173  /* Added by user */
174  break;
175 
176  case GET_PORT_STATUS:
177  USB_CtlTx (pudev, (uint8_t *)&PortStatus, 1);
178  break;
179 
180  case SOFT_RESET:
181  /* Added by user */
182  break;
183 
184  default:
185  USBD_EnumError (pudev, req);
186  return USBD_FAIL;
187  }
188 
189  return USBD_OK;
190 }
191 
198 static uint8_t USBD_PRINTER_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req)
199 {
200  return USBD_OK;
201 }
202 
209 static uint8_t USBD_PRINTER_GetInterface (void *pudev, USB_DEVICE_REQ *req)
210 {
211  USB_CtlTx (pudev, (uint8_t *)&USBD_PRINTER_AltSet, 1);
212 
213  return USBD_OK;
214 }
215 
222 static uint8_t USBD_PRINTER_SetInterface (void *pudev, USB_DEVICE_REQ *req)
223 {
224  USBD_PRINTER_AltSet = (uint8_t)(req->wValue);
225 
226  return USBD_OK;
227 }
228 
235 static uint8_t USBD_PRINTER_DataIn (void *pudev, uint8_t EpID)
236 {
237  /* Added by user */
238 
239  return USBD_OK;
240 }
241 
248 static uint8_t USBD_PRINTER_DataOut (void *pudev, uint8_t EpID)
249 {
250  /* Added by user */
251 
252  return USBD_OK;
253 }
254 
261 static uint8_t* USBD_PRINTER_GetCfgDesc (uint8_t USBSpeed, uint16_t *len)
262 {
263  *len = sizeof (USBD_PRINTER_CfgDesc);
264 
265  return (uint8_t *)USBD_PRINTER_CfgDesc;
266 }
267 
288 /************************ (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
USB printer (USB printing device) header file.
USB device class callback type define.
Definition: usb_core.h:153
void USB_EP_DeInit(USB_CORE_HANDLE *pudev, uint8_t EpAddr)
Configure the endpoint when it is disabled.
Definition: usb_core.c:275
void USB_EP_Init(USB_CORE_HANDLE *pudev, uint8_t EpAddr, uint8_t EpType, uint16_t EpMps)
Endpoint initialization.
Definition: usb_core.c:169
uint8_t USB_CtlTx(USB_CORE_HANDLE *pudev, uint8_t *pbuf, uint16_t Len)
Transmit data on the control pipe.
Definition: usb_core.c:543
#define USB_SNG_BUFTYPE
USB endpoint kind.
Definition: usb_core.h:52
void USB_EP_BufConfig(USB_CORE_HANDLE *pudev, uint8_t EpAddr, uint8_t EpKind, uint32_t BufAddr)
Configure buffer for endpoint.
Definition: usb_core.c:107
void USBD_EnumError(USB_DEVICE_HANDLE *pudev, USB_DEVICE_REQ *req)
Handle usb enumeration error event.
Definition: usbd_enum.c:755
USB standard device request struct.
Definition: usb_core.h:122
Generated by   doxygen 1.8.10