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_DataIn (
void *pudev, uint8_t EpID);
36 static uint8_t USBD_CUSTOMHID_DataOut (
void *pudev, uint8_t EpID);
37 static uint8_t* USBD_CUSTOMHID_GetCfgDesc (uint8_t USBSpeed, uint16_t *len);
42 uint8_t Report_buf[2];
43 uint8_t USBD_CUSTOMHID_Report_ID = 0;
46 static uint32_t USBD_CUSTOMHID_AltSet = 0;
47 static uint32_t USBD_CUSTOMHID_Protocol = 0;
48 static uint32_t USBD_CUSTOMHID_IdleState = 0;
53 USBD_CUSTOMHID_DeInit,
54 USBD_CUSTOMHID_GetClassDescriptor,
55 USBD_CUSTOMHID_ClassReqHandle,
56 USBD_CUSTOMHID_GetInterface,
57 USBD_CUSTOMHID_SetInterface,
60 USBD_CUSTOMHID_DataIn,
61 USBD_CUSTOMHID_DataOut,
63 USBD_CUSTOMHID_GetCfgDesc,
67 const uint8_t USBD_HID_CfgDesc[CUSTOMHID_CONFIG_DESC_SIZE] =
70 USB_DESCTYPE_CONFIGURATION,
71 CUSTOMHID_CONFIG_DESC_SIZE,
81 USB_DESCTYPE_INTERFACE,
98 CUSTOMHID_REPORT_DESC_SIZE,
103 USB_DESCTYPE_ENDPOINT,
111 USB_DESCTYPE_ENDPOINT,
114 CUSTOMHID_OUT_PACKET,
120 const uint8_t CustomHID_ReportDescriptor[CUSTOMHID_REPORT_DESC_SIZE] =
201 uint8_t USBD_CUSTOMHID_Init (
void *pudev, uint8_t ConfigIndex)
210 CUSTOMHID_IN_PACKET);
216 CUSTOMHID_OUT_PACKET);
219 USB_EP_Rx(pudev, CUSTOMHID_OUT_EP, Report_buf, 2);
230 uint8_t USBD_CUSTOMHID_DeInit (
void *pudev, uint8_t ConfigIndex)
245 uint8_t USBD_CUSTOMHID_ClassReqHandle (
void *pudev,
USB_DEVICE_REQ *req)
247 uint8_t USBD_CUSTOMHID_Report_LENGTH = 0;
249 switch (req->bRequest)
256 USB_CtlTx (pudev, (uint8_t *)&USBD_CUSTOMHID_IdleState, 1);
260 USB_CtlTx (pudev, (uint8_t *)&USBD_CUSTOMHID_Protocol, 1);
265 USBD_CUSTOMHID_Report_ID = (uint8_t)(req->wValue);
266 USBD_CUSTOMHID_Report_LENGTH = (uint8_t)(req->wLength);
267 USB_CtlRx (pudev, Report_buf, USBD_CUSTOMHID_Report_LENGTH);
271 USBD_CUSTOMHID_IdleState = (uint8_t)(req->wValue >> 8);
275 USBD_CUSTOMHID_Protocol = (uint8_t)(req->wValue);
292 uint8_t USBD_CUSTOMHID_GetClassDescriptor (
void *pudev,
USB_DEVICE_REQ *req)
295 uint8_t *pbuf = NULL;
297 switch(req->wValue >> 8)
299 case CUSTOMHID_REPORT_DESCTYPE:
300 len = MIN(CUSTOMHID_REPORT_DESC_SIZE, req->wLength);
301 pbuf = (uint8_t *)CustomHID_ReportDescriptor;
304 case CUSTOMHID_DESC_TYPE:
305 len = MIN(USB_CUSTOMHID_DESC_SIZE, req->wLength);
306 pbuf = (uint8_t *)USBD_HID_CfgDesc + 0x12;
324 uint8_t USBD_CUSTOMHID_GetInterface (
void *pudev,
USB_DEVICE_REQ *req)
326 USB_CtlTx (pudev, (uint8_t *)&USBD_CUSTOMHID_AltSet, 1);
337 uint8_t USBD_CUSTOMHID_SetInterface (
void *pudev,
USB_DEVICE_REQ *req)
339 USBD_CUSTOMHID_AltSet = (uint8_t)(req->wValue);
355 if (pudev->dev.device_cur_status == USB_STATUS_CONFIGURED)
357 USB_EP_Tx (pudev, CUSTOMHID_IN_EP, report, Len);
369 uint8_t *USBD_CUSTOMHID_GetCfgDesc (uint8_t USBSpeed, uint16_t *len)
371 *len =
sizeof (USBD_HID_CfgDesc);
373 return (uint8_t*)USBD_HID_CfgDesc;
382 uint8_t USBD_CUSTOMHID_DataIn (
void *pudev, uint8_t EpID)
393 uint8_t USBD_CUSTOMHID_DataOut (
void *pudev, uint8_t EpID)
397 switch (Report_buf[0])
400 if (Report_buf[1] != Bit_RESET)
406 GD_EVAL_LEDOff(LED1);
411 if (Report_buf[1] != Bit_RESET)
417 GD_EVAL_LEDOff(LED2);
422 if (Report_buf[1] != Bit_RESET)
428 GD_EVAL_LEDOff(LED3);
433 if (Report_buf[1] != Bit_RESET)
439 GD_EVAL_LEDOff(LED4);
444 GD_EVAL_LEDOff(LED1);
445 GD_EVAL_LEDOff(LED2);
446 GD_EVAL_LEDOff(LED3);
447 GD_EVAL_LEDOff(LED4);
452 USB_EP_Rx(pudev, CUSTOMHID_IN_EP, Report_buf, 2);
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.