29 static uint8_t USBD_CUSTOMHID_Init (
void *pudev, uint8_t ConfigIndex);
30 static uint8_t USBD_CUSTOMHID_DeInit (
void *pudev, uint8_t ConfigIndex);
31 static uint8_t USBD_CUSTOMHID_GetClassDescriptor (
void *pudev,
USB_DEVICE_REQ *req);
32 static uint8_t USBD_CUSTOMHID_ClassReqHandle (
void *pudev,
USB_DEVICE_REQ *req);
33 static uint8_t USBD_CUSTOMHID_GetInterface (
void *pudev,
USB_DEVICE_REQ *req);
34 static uint8_t USBD_CUSTOMHID_SetInterface (
void *pudev,
USB_DEVICE_REQ *req);
35 static uint8_t USBD_CUSTOMHID_EP0_RxReady (
void *pudev);
36 static uint8_t USBD_CUSTOMHID_DataIn (
void *pudev, uint8_t EpID);
37 static uint8_t USBD_CUSTOMHID_DataOut (
void *pudev, uint8_t EpID);
38 static uint8_t* USBD_CUSTOMHID_GetCfgDesc (uint8_t USBSpeed, uint16_t *len);
43 uint8_t Report_buf[2];
44 uint8_t USBD_CUSTOMHID_Report_ID = 0;
47 static uint32_t USBD_CUSTOMHID_AltSet = 0;
48 static uint32_t USBD_CUSTOMHID_Protocol = 0;
49 static uint32_t USBD_CUSTOMHID_IdleState = 0;
54 USBD_CUSTOMHID_DeInit,
55 USBD_CUSTOMHID_GetClassDescriptor,
56 USBD_CUSTOMHID_ClassReqHandle,
57 USBD_CUSTOMHID_GetInterface,
58 USBD_CUSTOMHID_SetInterface,
60 USBD_CUSTOMHID_EP0_RxReady,
61 USBD_CUSTOMHID_DataIn,
62 USBD_CUSTOMHID_DataOut,
64 USBD_CUSTOMHID_GetCfgDesc,
68 const uint8_t USBD_HID_CfgDesc[CUSTOMHID_CONFIG_DESC_SIZE] =
71 USB_DESCTYPE_CONFIGURATION,
72 CUSTOMHID_CONFIG_DESC_SIZE,
82 USB_DESCTYPE_INTERFACE,
99 CUSTOMHID_REPORT_DESC_SIZE,
104 USB_DESCTYPE_ENDPOINT,
112 USB_DESCTYPE_ENDPOINT,
115 CUSTOMHID_OUT_PACKET,
121 const uint8_t CustomHID_ReportDescriptor[CUSTOMHID_REPORT_DESC_SIZE] =
202 uint8_t USBD_CUSTOMHID_Init (
void *pudev, uint8_t ConfigIndex)
211 CUSTOMHID_IN_PACKET);
217 CUSTOMHID_OUT_PACKET);
220 USB_EP_Rx(pudev, CUSTOMHID_OUT_EP, Report_buf, 2);
231 uint8_t USBD_CUSTOMHID_DeInit (
void *pudev, uint8_t ConfigIndex)
246 uint8_t USBD_CUSTOMHID_ClassReqHandle (
void *pudev,
USB_DEVICE_REQ *req)
248 uint8_t USBD_CUSTOMHID_Report_LENGTH = 0;
250 switch (req->bRequest)
257 USB_CtlTx (pudev, (uint8_t *)&USBD_CUSTOMHID_IdleState, 1);
261 USB_CtlTx (pudev, (uint8_t *)&USBD_CUSTOMHID_Protocol, 1);
266 USBD_CUSTOMHID_Report_ID = (uint8_t)(req->wValue);
267 USBD_CUSTOMHID_Report_LENGTH = (uint8_t)(req->wLength);
268 USB_CtlRx (pudev, Report_buf, USBD_CUSTOMHID_Report_LENGTH);
272 USBD_CUSTOMHID_IdleState = (uint8_t)(req->wValue >> 8);
276 USBD_CUSTOMHID_Protocol = (uint8_t)(req->wValue);
293 uint8_t USBD_CUSTOMHID_GetClassDescriptor (
void *pudev,
USB_DEVICE_REQ *req)
296 uint8_t *pbuf = NULL;
298 switch(req->wValue >> 8)
300 case CUSTOMHID_REPORT_DESCTYPE:
301 len = MIN(CUSTOMHID_REPORT_DESC_SIZE, req->wLength);
302 pbuf = (uint8_t *)CustomHID_ReportDescriptor;
305 case CUSTOMHID_DESC_TYPE:
306 len = MIN(USB_CUSTOMHID_DESC_SIZE, req->wLength);
307 pbuf = (uint8_t *)USBD_HID_CfgDesc + 0x12;
325 uint8_t USBD_CUSTOMHID_GetInterface (
void *pudev,
USB_DEVICE_REQ *req)
327 USB_CtlTx (pudev, (uint8_t *)&USBD_CUSTOMHID_AltSet, 1);
338 uint8_t USBD_CUSTOMHID_SetInterface (
void *pudev,
USB_DEVICE_REQ *req)
340 USBD_CUSTOMHID_AltSet = (uint8_t)(req->wValue);
356 if (pudev->dev.device_cur_status == USB_STATUS_CONFIGURED)
358 USB_EP_Tx (pudev, CUSTOMHID_IN_EP, report, Len);
370 uint8_t *USBD_CUSTOMHID_GetCfgDesc (uint8_t USBSpeed, uint16_t *len)
372 *len =
sizeof (USBD_HID_CfgDesc);
374 return (uint8_t*)USBD_HID_CfgDesc;
383 uint8_t USBD_CUSTOMHID_DataIn (
void *pudev, uint8_t EpID)
394 uint8_t USBD_CUSTOMHID_DataOut (
void *pudev, uint8_t EpID)
398 switch (Report_buf[0])
401 if (Report_buf[1] != Bit_RESET)
407 GD_EVAL_LEDOff(LED1);
412 if (Report_buf[1] != Bit_RESET)
418 GD_EVAL_LEDOff(LED2);
423 if (Report_buf[1] != Bit_RESET)
429 GD_EVAL_LEDOff(LED3);
434 if (Report_buf[1] != Bit_RESET)
440 GD_EVAL_LEDOff(LED4);
445 GD_EVAL_LEDOff(LED1);
446 GD_EVAL_LEDOff(LED2);
447 GD_EVAL_LEDOff(LED3);
448 GD_EVAL_LEDOff(LED4);
453 USB_EP_Rx(pudev, CUSTOMHID_IN_EP, Report_buf, 2);
463 static uint8_t USBD_CUSTOMHID_EP0_RxReady (
void *pudev)
469 switch (Report_buf[0])
472 if (Report_buf[1] != Bit_RESET)
478 GD_EVAL_LEDOff(LED1);
483 if (Report_buf[1] != Bit_RESET)
489 GD_EVAL_LEDOff(LED2);
494 if (Report_buf[1] != Bit_RESET)
500 GD_EVAL_LEDOff(LED3);
505 if (Report_buf[1] != Bit_RESET)
511 GD_EVAL_LEDOff(LED4);
516 GD_EVAL_LEDOff(LED1);
517 GD_EVAL_LEDOff(LED2);
518 GD_EVAL_LEDOff(LED3);
519 GD_EVAL_LEDOff(LED4);
USB device class callback type define.
void USB_EP_Tx(USB_CORE_HANDLE *pudev, uint8_t EpAddr, uint8_t *pbuf, uint16_t BufLen)
Endpoint prepare to transmit data.
uint8_t USBD_CUSTOMHID_SendReport(USB_DEVICE_HANDLE *pudev, uint8_t *report, uint16_t Len)
Send custom HID Report.
void USB_EP_DeInit(USB_CORE_HANDLE *pudev, uint8_t EpAddr)
Configure the endpoint when it is disabled.
void USB_EP_Init(USB_CORE_HANDLE *pudev, uint8_t EpAddr, uint8_t EpType, uint16_t EpMps)
Endpoint initialization.
uint8_t USB_CtlRx(USB_CORE_HANDLE *pudev, uint8_t *pbuf, uint16_t Len)
Receive data on the control pipe.
uint8_t USB_CtlTx(USB_CORE_HANDLE *pudev, uint8_t *pbuf, uint16_t Len)
Transmit data on the control pipe.
#define USB_SNG_BUFTYPE
USB endpoint kind.
void USB_EP_BufConfig(USB_CORE_HANDLE *pudev, uint8_t EpAddr, uint8_t EpKind, uint32_t BufAddr)
Configure buffer for endpoint.
void USBD_EnumError(USB_DEVICE_HANDLE *pudev, USB_DEVICE_REQ *req)
Handle usb enumeration error event.
USB standard device request struct.
void USB_EP_Rx(USB_CORE_HANDLE *pudev, uint8_t EpAddr, uint8_t *pbuf, uint16_t BufLen)
Endpoint prepare to receive data.
Custom HID device class core defines.