GD32F1x0: USB/GD32_USB_Device_Library/Class/hid_msc_wrapper/src/usbd_hid_msc_wrapper.c Source File

GD32F1x0

usbd_hid_msc_wrapper.c
1 
10 /* Includes ------------------------------------------------------------------*/
11 #include "usbd_hid_msc_wrapper.h"
12 #include "usbd_custom_hid_core.h"
13 #include "usbd_msc_core.h"
14 #include "usbd_desc.h"
15 
16 /* Private variables ---------------------------------------------------------*/
17 static uint8_t USBD_HID_MSC_Init (void *pudev, uint8_t cfgidx);
18 static uint8_t USBD_HID_MSC_DeInit (void *pudev, uint8_t cfgidx);
19 static uint8_t USBD_HID_MSC_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req);
20 static uint8_t USBD_HID_MSC_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req);
21 static uint8_t USBD_HID_MSC_GetInterface (void *pudev, USB_DEVICE_REQ *req);
22 static uint8_t USBD_HID_MSC_SetInterface (void *pudev, USB_DEVICE_REQ *req);
23 static uint8_t USBD_HID_MSC_EP0_RxReady (void *pudev);
24 static uint8_t USBD_HID_MSC_DataIn (void *pudev, uint8_t EpID);
25 static uint8_t USBD_HID_MSC_DataOut (void *pudev, uint8_t EpID);
26 static uint8_t* USBD_HID_MSC_GetCfgDesc (uint8_t USBSpeed, uint16_t *len);
27 
28 USBD_Class_cb_TypeDef USBD_HID_MSC_cb =
29 {
30  USBD_HID_MSC_Init,
31  USBD_HID_MSC_DeInit,
32  USBD_HID_MSC_GetClassDescriptor,
33  USBD_HID_MSC_ClassReqHandle,
34  USBD_HID_MSC_GetInterface,
35  USBD_HID_MSC_SetInterface,
36  NULL,
37  USBD_HID_MSC_EP0_RxReady,
38  USBD_HID_MSC_DataIn,
39  USBD_HID_MSC_DataOut,
40  NULL,
41  USBD_HID_MSC_GetCfgDesc,
42 };
43 
44 
45 /* USB MSC_HID device Configuration Descriptor */
46 const uint8_t USBD_HID_MSC_CfgDesc[USB_HID_MSC_CONFIG_DESC_SIZE] =
47 {
48  0x09, /* bLength: Configuration Descriptor size */
49  USB_DESCTYPE_CONFIGURATION, /* bDescriptorType: configuration descriptor type */
50  USB_HID_MSC_CONFIG_DESC_SIZE,/* wTotalLength: configuration descriptor set total length */
51  0x00,
52  0x02, /* bNumInterfaces: 2 interfaces (1 for MSC, 1 for HID) */
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  /************** Descriptor of CUSTOM HID interface ****************/
59  0x09, /* bLength: Interface Descriptor size */
60  USB_DESCTYPE_INTERFACE,/* bDescriptorType: Interface descriptor type */
61  HID_INTERFACE, /* bInterfaceNumber: Number of Interface */
62  0x00, /* bAlternateSetting: Alternate setting */
63  0x02, /* bNumEndpoints: 2 endpoints */
64  0x03, /* bInterfaceClass: HID */
65  0x00, /* bInterfaceSubClass: 1 = BIOS boot, 0 = no boot */
66  0x00, /* nInterfaceProtocol: 0 = none, 1 = keyboard, 2 = mouse */
67  0x00, /* iInterface: Index of string descriptor */
68 
69  /******************** Descriptor of CUSTOM HID **************************/
70  0x09, /* bLength: HID Descriptor size */
71  CUSTOMHID_DESC_TYPE, /* bDescriptorType: HID */
72  0x11, /* bcdHID: HID class protocol(HID1.11) */
73  0x01,
74  0x00, /* bCountryCode: Hardware target country */
75  0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
76  0x22, /* bDescriptorType: followed class descriptor type(report descriptor) */
77  CUSTOMHID_REPORT_DESC_SIZE,/* wDescriptorLength: Total length of Report descriptor */
78  0x00,
79 
80  /******************** Custom HID endpoints descriptor *********************/
81  0x07, /* bLength: Endpoint Descriptor size*/
82  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
83  CUSTOMHID_IN_EP, /* bEndpointAddress: Endpoint Address (IN) */
84  0x03, /* bmAttributes: Interrupt endpoint */
85  CUSTOMHID_IN_PACKET, /* wMaxPacketSize: 2 Byte max */
86  0x00,
87  0x20, /*bInterval: Polling Interval (32 ms)*/
88 
89  0x07, /* bLength: Endpoint Descriptor size */
90  USB_DESCTYPE_ENDPOINT, /* bDescriptorType: Endpoint descriptor type */
91  CUSTOMHID_OUT_EP, /* bEndpointAddress: Endpoint Address (OUT) */
92  0x03, /* bmAttributes: Interrupt endpoint */
93  CUSTOMHID_OUT_PACKET, /* wMaxPacketSize: 2 Bytes max */
94  0x00,
95  0x20, /* bInterval: Polling Interval (32 ms) */
96 
97  /******************** Mass Storage interface ********************/
98  0x09, /* bLength: Interface Descriptor size */
99  0x04, /* bDescriptorType: interface descriptor type */
100  MSC_INTERFACE, /* bInterfaceNumber: Number of Interface */
101  0x00, /* bAlternateSetting: Alternate setting */
102  0x02, /* bNumEndpoints: use 2 endpoints for Tx and Rx */
103  0x08, /* bInterfaceClass: MSC Class */
104  0x06, /* bInterfaceSubClass: SCSI transparent */
105  0x50, /* nInterfaceProtocol: Bulk-only transport */
106  0x01, /* iInterface: index of interface string descriptor */
107 
108  /******************** Mass Storage Endpoints ********************/
109  0x07, /* bLength: Endpoint descriptor length = 7 */
110  0x05, /* bDescriptorType: Endpoint descriptor type */
111  MSC_IN_EP, /* bEndpointAddress: Endpoint address (IN, address 2) */
112  0x02, /* bmAttributes:Bulk endpoint type */
113  LOWBYTE(MSC_DATA_PACKET_SIZE), /* wMaxPacketSize: 64 bytes max */
114  HIGHBYTE(MSC_DATA_PACKET_SIZE),
115  0x00, /* bInterval: polling interval is ignored */
116 
117  0x07, /* bLength: Endpoint descriptor length = 7 */
118  0x05, /* bDescriptorType: Endpoint descriptor type */
119  MSC_OUT_EP,/* bEndpointAddress: Endpoint address (OUT, address 2) */
120  0x02, /* bmAttributes: endpoint attribute(bulk endpoint) */
121  LOWBYTE(MSC_DATA_PACKET_SIZE), /* wMaxPacketSize: 64 bytes max */
122  HIGHBYTE(MSC_DATA_PACKET_SIZE),
123  0x00 /* bInterval: polling interval is ignored */
124 };
125 
126 /* Private function prototypes -----------------------------------------------*/
127 extern USBD_Class_cb_TypeDef USBD_CUSTOMHID_cb;
128 extern USBD_Class_cb_TypeDef USBD_MSC_cb;
129 
130 /* Private functions ---------------------------------------------------------*/
131 
138 static uint8_t USBD_HID_MSC_Init (void *pudev, uint8_t cfgidx)
139 {
140  /* HID initialization */
141  USBD_CUSTOMHID_cb.Init(pudev, cfgidx);
142 
143  /* MSC initialization */
144  USBD_MSC_cb.Init(pudev, cfgidx);
145 
146  return USBD_OK;
147 
148 }
149 
156 static uint8_t USBD_HID_MSC_DeInit (void *pudev, uint8_t cfgidx)
157 {
158  /* HID De-initialization */
159  USBD_CUSTOMHID_cb.DeInit(pudev, cfgidx);
160 
161  /* MSC De-initialization */
162  USBD_MSC_cb.DeInit(pudev, cfgidx);
163 
164  return USBD_OK;
165 }
166 
173 static uint8_t USBD_HID_MSC_GetClassDescriptor (void *pudev, USB_DEVICE_REQ *req)
174 {
175  if (req->wIndex == HID_INTERFACE)
176  {
177  return USBD_CUSTOMHID_cb.GetClassDescriptor(pudev, req);
178  }
179  else
180  {
181  return USBD_MSC_cb.GetClassDescriptor(pudev, req);
182  }
183 }
184 
191 static uint8_t USBD_HID_MSC_ClassReqHandle (void *pudev, USB_DEVICE_REQ *req)
192 {
193  if (req->wIndex == HID_INTERFACE)
194  {
195  return USBD_CUSTOMHID_cb.ClassReqHandle(pudev, req);
196  }
197  else
198  {
199  return USBD_MSC_cb.ClassReqHandle(pudev, req);
200  }
201 }
202 
209 static uint8_t USBD_HID_MSC_GetInterface (void *pudev, USB_DEVICE_REQ *req)
210 {
211  if (req->wIndex == HID_INTERFACE)
212  {
213  return USBD_CUSTOMHID_cb.GetInterface(pudev, req);
214  }
215  else
216  {
217  return USBD_MSC_cb.GetInterface(pudev, req);
218  }
219 }
220 
227 static uint8_t USBD_HID_MSC_SetInterface (void *pudev, USB_DEVICE_REQ *req)
228 {
229  if (req->wIndex == HID_INTERFACE)
230  {
231  return USBD_CUSTOMHID_cb.SetInterface(pudev, req);
232  }
233  else
234  {
235  return USBD_MSC_cb.SetInterface(pudev, req);
236  }
237 }
238 
245 static uint8_t* USBD_HID_MSC_GetCfgDesc (uint8_t USBSpeed, uint16_t *len)
246 {
247  *len = sizeof (USBD_HID_MSC_CfgDesc);
248 
249  return (uint8_t*)USBD_HID_MSC_CfgDesc;
250 }
251 
258 static uint8_t USBD_HID_MSC_DataIn (void *pudev, uint8_t EpID)
259 {
260  /*DataIN can be for MSC or HID */
261  if (EpID == (MSC_IN_EP & ~0x80))
262  {
263  return USBD_MSC_cb.DataIn(pudev, EpID);
264  }
265  else
266  {
267  return USBD_CUSTOMHID_cb.DataIn(pudev, EpID);
268  }
269 }
270 
277 static uint8_t USBD_HID_MSC_DataOut(void *pudev , uint8_t EpID)
278 {
279  /*DataOut can be for MSC or HID */
280  if (EpID == (MSC_OUT_EP & ~0x80))
281  {
282  return USBD_MSC_cb.DataOut(pudev, EpID);
283  }
284  else
285  {
286  return USBD_CUSTOMHID_cb.DataOut(pudev, EpID);
287  }
288 }
289 
295 static uint8_t USBD_HID_MSC_EP0_RxReady (void *pudev)
296 {
297  /*RxReady processing needed for Custom HID only*/
298  return USBD_CUSTOMHID_cb.EP0_RxReady(pudev);
299 }
300 
301 /************************ (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
USB device class callback type define.
Definition: usb_core.h:153
Header file for the usbd_msc_core.c file.
USB standard device request struct.
Definition: usb_core.h:122
Custom HID device class core defines.
USB descriptor defines and function prototype.
Generated by   doxygen 1.8.10