if (HIDP_Machine->poll < HID_MIN_POLL)
{
HIDP_Machine->poll = HID_MIN_POLL;
}
/* Check fo available number of endpoints */
/* Find the number of EPs in the Interface Descriptor */
/* Choose the lower number in order not to overrun the buffer allocated */
maxEP = ( (pphost->device_prop.Itf_Desc[itf].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ?
pphost->device_prop.Itf_Desc[itf].bNumEndpoints :
USBH_MAX_NUM_ENDPOINTS);
/* Decode endpoint IN and OUT address from interface descriptor */
for (num=0; num < maxEP; num++)
{
if(pphost->device_prop.Ep_Desc[itf][num].bEndpointAddress & 0x80)
{
HIDP_Machine->HIDIntInEp = (pphost->device_prop.Ep_Desc[itf][num].bEndpointAddress);
HIDP_Machine->hc_num_in =\
USBH_Alloc_Channel(pdev,
pphost->device_prop.Ep_Desc[itf][num].bEndpointAddress);
/* Open channel for IN endpoint */
USBH_Open_Channel (pdev,
HIDP_Machine->hc_num_in,
pphost->device_prop.address,
pphost->device_prop.speed,
EP_TYPE_INTR,
HIDP_Machine->length);
}
else
{
HIDP_Machine->HIDIntOutEp = (pphost->device_prop.Ep_Desc[itf][num].bEndpointAddress);
HIDP_Machine->hc_num_out =\
USBH_Alloc_Channel(pdev,
pphost->device_prop.Ep_Desc[itf][num].bEndpointAddress);
/* Open channel for OUT endpoint */
USBH_Open_Channel (pdev,
HIDP_Machine->hc_num_out,
pphost->device_prop.address,
pphost->device_prop.speed,
EP_TYPE_INTR,
HIDP_Machine->length);
}
}
HIDP_Machine->start_toggle = 0;
status = USBH_OK;
}
}
case HID_POLL:
//SysTick_Delayms(1);
if(( HCD_GetCurrentFrame(pdev) - HIDP_Machine->timer) >= HIDP_Machine->poll)
{
if (HIDP_Machine == &HID_KeyBoard && HID_Mouse.cb != NULL)
HIDP_Machine = &HID_Mouse;
else if (HIDP_Machine == &HID_Mouse && HID_KeyBoard.cb != NULL)
HIDP_Machine = &HID_KeyBoard;
HIDP_Machine->state = HID_GET_DATA;
}
else if(HCD_GetURB_State(pdev , HIDP_Machine->hc_num_in) == URB_DONE)
{
if(HIDP_Machine->start_toggle == 1) /* handle data once */
{
HIDP_Machine->start_toggle = 0; HIDP_Machine->cb->Decode(HIDP_Machine->buff);//data is decoded here
}
}
else if(HCD_GetURB_State(pdev, HIDP_Machine->hc_num_in) == URB_STALL) /* IN Endpoint Stalled */
{
/* Issue Clear Feature on interrupt IN endpoint */
if( (USBH_ClrFeature(pdev,
pphost,
HIDP_Machine->ep_addr,
HIDP_Machine->hc_num_in)) == USBH_OK)
{
/* Change state to issue next IN token */
HIDP_Machine->state = HID_GET_DATA;
}
}
break;
default:
break;
}
return status;
}
/**
* @brief USBH_Get_HID_ReportDescriptor
* Issue report Descriptor command to the device. Once the response
* received, parse the report descriptor and update the status.
* @param pdev : Selected device
* @param Length : HID Report Descriptor Length
* @retval USBH_Status : Response for USB HID Get Report Descriptor Request
*/
static USBH_Status USBH_Get_HID_ReportDescriptor (USB_OTG_CORE_HANDLE *pdev,
USBH_HOST *phost,
uint16_t length)
{
USBH_Status status;
status = USBH_GetDescriptor(pdev,
phost,
USB_REQ_RECIPIENT_INTERFACE
| USB_REQ_TYPE_STANDARD,
USB_DESC_HID_REPORT,
pdev->host.Rx_Buffer,
length);
/* HID report descriptor is available in pdev->host.Rx_Buffer.
In case of USB Boot Mode devices for In report handling ,
HID report descriptor parsing is not required.
In case, for supporting Non-Boot Protocol devices and output reports,
user may parse the report descriptor*/
return status;
}
/**
* @brief USBH_Get_HID_Descriptor
* Issue HID Descriptor command to the device. Once the response
* received, parse the report descriptor and update the status.
* @param pdev : Selected device
* @param Length : HID Descriptor Length
* @retval USBH_Status : Response for USB HID Get Report Descriptor Request
*/
static USBH_Status USBH_Get_HID_Descriptor (USB_OTG_CORE_HANDLE *pdev,
USBH_HOST *phost,
uint16_t length)
{
USBH_Status status;
status = USBH_GetDescriptor(pdev,
phost,
USB_REQ_RECIPIENT_INTERFACE
| USB_REQ_TYPE_STANDARD,
USB_DESC_HID,
pdev->host.Rx_Buffer,
length);
return status;
}
/**
* @brief USBH_Set_Idle
* Set Idle State.
* @param pdev: Selected device
* @param duration: Duration for HID Idle request
* @param reportID : Targetted report ID for Set Idle request
* @retval USBH_Status : Response for USB Set Idle request
*/
static USBH_Status USBH_Set_Idle (USB_OTG_CORE_HANDLE *pdev,
USBH_HOST *phost,
uint8_t duration,
uint8_t reportId)
{
/**
* @brief USBH_ParseHIDDesc
* This function Parse the HID descriptor
* @param buf: Buffer where the source descriptor is available
* @retval None
*/
static void USBH_ParseHIDDesc (USBH_HIDDesc_TypeDef *desc, uint8_t *buf)
{