Ejemplo n.º 1
0
/****************************************************************************
  Function:
    BOOL USB_HID_DataCollectionHandler(void)
  Description:
    This function is invoked by HID client , purpose is to collect the
    details extracted from the report descriptor. HID client will store
    information extracted from the report descriptor in data structures.
    Application needs to create object for each report type it needs to
    extract.
    For ex: HID_DATA_DETAILS pickit.keys.modifier.details;
    HID_DATA_DETAILS is defined in file usb_host_hid_appl_interface.h
    Each member of the structure must be initialized inside this function.
    Application interface layer provides functions :
    USBHostHID_ApiFindBit()
    USBHostHID_ApiFindValue()
    These functions can be used to fill in the details as shown in the demo
    code.

  Precondition:
    None

  Parameters:
    None

  Return Values:
    true    - If the report details are collected successfully.
    false   - If the application does not find the the supported format.

  Remarks:
    This Function name should be entered in the USB configuration tool
    in the field "Parsed Data Collection handler".
    If the application does not define this function , then HID cient
    assumes that Application is aware of report format of the attached
    device.
 ***************************************************************************/
bool APP_HostHIDKeyboardReportParser(void) {
    uint8_t NumOfReportItem = 0;
    uint8_t i;
    USB_HID_ITEM_LIST* pitemListPtrs;
    USB_HID_DEVICE_RPT_INFO* pDeviceRptinfo;
    HID_REPORTITEM *reportItem;
    HID_USAGEITEM *hidUsageItem;
    //uint8_t usageIndex;
   // uint8_t reportIndex;
   // uint8_t usageItem;
    
    /* The pickit is already in use. */
    if (pickit.inUse == true) {

        //PRINT_String( "-In Use-\r\n",10);
        return false;
    }

    pDeviceRptinfo = USBHostHID_GetCurrentReportInfo(); // Get current Report Info pointer
    pitemListPtrs = USBHostHID_GetItemListPointers(); // Get pointer to list of item pointers

    /* Find Report Item Index for Modifier Keys */
    /* Once report Item is located , extract information from data structures provided by the parser */
    NumOfReportItem = pDeviceRptinfo->reportItems;

#ifdef DEBUG_MODE
    UART2PrintString("APP: NumOfReportItem:");
    UART2PutHex(NumOfReportItem);
    UART2PutChar('\n');

    USBHID_ReportDecriptor_Dump();
#endif
    
    reportItem = &pitemListPtrs->reportItemList[0];
    
    pickit.details.reportLength = 64; // (pitemListPtrs->reportList[reportIndex].inputBits + 7) / 8;
    pickit.details.reportID = (uint8_t) reportItem->globals.reportID;
    pickit.details.bitOffset = (uint8_t) reportItem->startBit;
    pickit.details.bitLength = (uint8_t) reportItem->globals.reportsize;
    pickit.details.count = (uint8_t) reportItem->globals.reportCount;
    pickit.details.interfaceNum = USBHostHID_ApiGetCurrentInterfaceNum();

    pickit.size = 64;
    pickit.buffer = (uint8_t*) malloc(pickit.size);
    pickit.inUse = true;

    return (pickit.inUse);
}
Ejemplo n.º 2
0
static BOOL USB_HID_KEYBOARD_DataCollectionHandler(BYTE deviceAddress)
{
    BYTE                     NumOfReportItem;
    BYTE                     i;
    USB_HID_ITEM_LIST       *pitemListPtrs;
    USB_HID_DEVICE_RPT_INFO *pDeviceRptinfo;
    HID_REPORTITEM          *reportItem;
    HID_USAGEITEM           *hidUsageItem;
    BYTE                     usageIndex;
    BYTE                     reportIndex;
    BOOL                     foundLEDIndicator = FALSE;
    BOOL                     foundModifierKey = FALSE;
    BOOL                     foundNormalKey = FALSE;
    BOOL                     status;

    pDeviceRptinfo = USBHostHID_GetCurrentReportInfo(); // Get current Report Info pointer
    pitemListPtrs = USBHostHID_GetItemListPointers();   // Get pointer to list of item pointers

    foundLEDIndicator = foundModifierKey = foundNormalKey = FALSE;
    status = FALSE;
    reportIndex = 0;
    NumOfReportItem = pDeviceRptinfo->reportItems;

    for(i=0;i<NumOfReportItem;i++){
        reportItem = &pitemListPtrs->reportItemList[i];
        if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Variable)&&
                (reportItem->globals.usagePage==USAGE_PAGE_KEY_CODES)){
            usageIndex = reportItem->firstUsageItem;
            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];
            if((hidUsageItem->usageMinimum == USAGE_MIN_MODIFIER_KEY)
                    &&(hidUsageItem->usageMaximum == USAGE_MAX_MODIFIER_KEY)){ //else application cannot suuport

                reportIndex = reportItem->globals.reportIndex;
                Appl_ModifierKeysDetails[deviceAddress].reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
                Appl_ModifierKeysDetails[deviceAddress].reportID = (BYTE)reportItem->globals.reportID;
                Appl_ModifierKeysDetails[deviceAddress].bitOffset = (BYTE)reportItem->startBit;
                Appl_ModifierKeysDetails[deviceAddress].bitLength = (BYTE)reportItem->globals.reportsize;
                Appl_ModifierKeysDetails[deviceAddress].count=(BYTE)reportItem->globals.reportCount;
                Appl_ModifierKeysDetails[deviceAddress].interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
                foundModifierKey = TRUE;
            }
        }else if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Array)&&
                (reportItem->globals.usagePage==USAGE_PAGE_KEY_CODES)){
            usageIndex = reportItem->firstUsageItem;
            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

            if((hidUsageItem->usageMinimum == USAGE_MIN_NORMAL_KEY)
                    &&(hidUsageItem->usageMaximum <= USAGE_MAX_NORMAL_KEY)){ //else application cannot suuport
                reportIndex = reportItem->globals.reportIndex;
                Appl_NormalKeysDetails[deviceAddress].reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
                Appl_NormalKeysDetails[deviceAddress].reportID = (BYTE)reportItem->globals.reportID;
                Appl_NormalKeysDetails[deviceAddress].bitOffset = (BYTE)reportItem->startBit;
                Appl_NormalKeysDetails[deviceAddress].bitLength = (BYTE)reportItem->globals.reportsize;
                Appl_NormalKeysDetails[deviceAddress].count=(BYTE)reportItem->globals.reportCount;
                Appl_NormalKeysDetails[deviceAddress].interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
                foundNormalKey = TRUE;
            }
        }else if((reportItem->reportType==hidReportOutput) &&
                (reportItem->globals.usagePage==USAGE_PAGE_LEDS)){
            usageIndex = reportItem->firstUsageItem;
            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

            reportIndex = reportItem->globals.reportIndex;
            Appl_LED_Indicator[deviceAddress].reportLength = (pitemListPtrs->reportList[reportIndex].outputBits + 7)/8;
            Appl_LED_Indicator[deviceAddress].reportID = (BYTE)reportItem->globals.reportID;
            Appl_LED_Indicator[deviceAddress].bitOffset = (BYTE)reportItem->startBit;
            Appl_LED_Indicator[deviceAddress].bitLength = (BYTE)reportItem->globals.reportsize;
            Appl_LED_Indicator[deviceAddress].count=(BYTE)reportItem->globals.reportCount;
            Appl_LED_Indicator[deviceAddress].interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
            foundLEDIndicator = TRUE;
        }
    }

    if(pDeviceRptinfo->reports == 1){
        Appl_raw_report_buffer[deviceAddress].Report_ID = 0;
        Appl_raw_report_buffer[deviceAddress].ReportSize = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
        Appl_raw_report_buffer[deviceAddress].ReportData = (BYTE*)USB_MALLOC(Appl_raw_report_buffer[deviceAddress].ReportSize);
        Appl_raw_report_buffer[deviceAddress].ReportPollRate = pDeviceRptinfo->reportPollingRate;
        if((foundNormalKey == TRUE)&&(foundModifierKey == TRUE)) status = TRUE;
    }

    return(status);
}
Ejemplo n.º 3
0
/****************************************************************************
  Function:
    BOOL USB_HID_DataCollectionHandler(void)
  Description:
    This function is invoked by HID client , purpose is to collect the
    details extracted from the report descriptor. HID client will store
    information extracted from the report descriptor in data structures.
    Application needs to create object for each report type it needs to
    extract.
    For ex: HID_DATA_DETAILS Appl_ModifierKeysDetails;
    HID_DATA_DETAILS is defined in file usb_host_hid_appl_interface.h
    Each member of the structure must be initialized inside this function.
    Application interface layer provides functions :
    USBHostHID_ApiFindBit()
    USBHostHID_ApiFindValue()
    These functions can be used to fill in the details as shown in the demo
    code.

  Precondition:
    None

  Parameters:
    None

  Return Values:
    TRUE    - If the report details are collected successfully.
    FALSE   - If the application does not find the the supported format.

  Remarks:
    This Function name should be entered in the USB configuration tool
    in the field "Parsed Data Collection handler".
    If the application does not define this function , then HID cient
    assumes that Application is aware of report format of the attached
    device.
***************************************************************************/
BOOL USB_HID_DataCollectionHandler(void)
{
  BYTE NumOfReportItem = 0;
  BYTE i;
  USB_HID_ITEM_LIST* pitemListPtrs;
  USB_HID_DEVICE_RPT_INFO* pDeviceRptinfo;
  HID_REPORTITEM *reportItem;
  HID_USAGEITEM *hidUsageItem;
  BYTE usageIndex;
  BYTE reportIndex;

  pDeviceRptinfo = USBHostHID_GetCurrentReportInfo(); // Get current Report Info pointer
  pitemListPtrs = USBHostHID_GetItemListPointers();   // Get pointer to list of item pointers

  BOOL status = FALSE;
   /* Find Report Item Index for Modifier Keys */
   /* Once report Item is located , extract information from data structures provided by the parser */
   NumOfReportItem = pDeviceRptinfo->reportItems;

	int deviceValue = 0;
	deviceValue = USBHID_ReportDecriptor_Difference();
	if(deviceValue == USB_HID_MOUSE)
	{

	   for(i=0;i<NumOfReportItem;i++)
	    {
	       reportItem = &pitemListPtrs->reportItemList[i];
	       if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == (HIDData_Variable|HIDData_Relative))&&
	           (reportItem->globals.usagePage==USAGE_PAGE_GEN_DESKTOP))
	        {
	           /* We now know report item points to modifier keys */
	           /* Now make sure usage Min & Max are as per application */
	            usageIndex = reportItem->firstUsageItem;
	            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

	            reportIndex = reportItem->globals.reportIndex;
	            Appl_XY_Axis_Details.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
	            Appl_XY_Axis_Details.reportID = (BYTE)reportItem->globals.reportID;
	            Appl_XY_Axis_Details.bitOffset = (BYTE)reportItem->startBit;
	            Appl_XY_Axis_Details.bitLength = (BYTE)reportItem->globals.reportsize;
	            Appl_XY_Axis_Details.count=(BYTE)reportItem->globals.reportCount;
	            Appl_XY_Axis_Details.interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
	        }
	        else if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Variable)&&
	           (reportItem->globals.usagePage==USAGE_PAGE_BUTTONS))
	        {
	           /* We now know report item points to modifier keys */
	           /* Now make sure usage Min & Max are as per application */
	            usageIndex = reportItem->firstUsageItem;
	            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

	            reportIndex = reportItem->globals.reportIndex;
	            Appl_Mouse_Buttons_Details.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
	            Appl_Mouse_Buttons_Details.reportID = (BYTE)reportItem->globals.reportID;
	            Appl_Mouse_Buttons_Details.bitOffset = (BYTE)reportItem->startBit;
	            Appl_Mouse_Buttons_Details.bitLength = (BYTE)reportItem->globals.reportsize;
	            Appl_Mouse_Buttons_Details.count =(BYTE)reportItem->globals.reportCount;
	            Appl_Mouse_Buttons_Details.interfaceNum = USBHostHID_ApiGetCurrentInterfaceNum();
	        }
	    }

	   if(pDeviceRptinfo->reports == 1)
	    {
	        Appl_raw_report_buffer.Report_ID = 0;
	        Appl_raw_report_buffer.ReportSize = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
	        Appl_raw_report_buffer.ReportPollRate = pDeviceRptinfo->reportPollingRate;
	        status = TRUE;
	    }
	}
	else if(deviceValue == USB_HID_KEYBOARD)
	{
		BOOL foundLEDIndicator = FALSE;
		BOOL foundModifierKey = FALSE;
		BOOL foundNormalKey = FALSE;

	   for(i=0;i<NumOfReportItem;i++)
	    {
	       reportItem = &pitemListPtrs->reportItemList[i];
	       if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Variable)&&
	           (reportItem->globals.usagePage==USAGE_PAGE_KEY_CODES))
	        {
	           /* We now know report item points to modifier keys */
	           /* Now make sure usage Min & Max are as per application */
	            usageIndex = reportItem->firstUsageItem;
	            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];
	            if((hidUsageItem->usageMinimum == USAGE_MIN_MODIFIER_KEY)
	                &&(hidUsageItem->usageMaximum == USAGE_MAX_MODIFIER_KEY)) //else application cannot suuport
	            {
	               reportIndex = reportItem->globals.reportIndex;
	               Appl_ModifierKeysDetails.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
	               Appl_ModifierKeysDetails.reportID = (BYTE)reportItem->globals.reportID;
	               Appl_ModifierKeysDetails.bitOffset = (BYTE)reportItem->startBit;
	               Appl_ModifierKeysDetails.bitLength = (BYTE)reportItem->globals.reportsize;
	               Appl_ModifierKeysDetails.count=(BYTE)reportItem->globals.reportCount;
	               Appl_ModifierKeysDetails.interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
	               foundModifierKey = TRUE;
	            }

	        }
	        else if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Array)&&
	           (reportItem->globals.usagePage==USAGE_PAGE_KEY_CODES))
	        {
	           /* We now know report item points to modifier keys */
	           /* Now make sure usage Min & Max are as per application */
	            usageIndex = reportItem->firstUsageItem;
	            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];
	            if((hidUsageItem->usageMinimum == USAGE_MIN_NORMAL_KEY)
	                &&(hidUsageItem->usageMaximum <= USAGE_MAX_NORMAL_KEY)) //else application cannot suuport
	            {
	               reportIndex = reportItem->globals.reportIndex;
	               Appl_NormalKeysDetails.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
	               Appl_NormalKeysDetails.reportID = (BYTE)reportItem->globals.reportID;
	               Appl_NormalKeysDetails.bitOffset = (BYTE)reportItem->startBit;
	               Appl_NormalKeysDetails.bitLength = (BYTE)reportItem->globals.reportsize;
	               Appl_NormalKeysDetails.count=(BYTE)reportItem->globals.reportCount;
	               Appl_NormalKeysDetails.interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
	               foundNormalKey = TRUE;
	            }

	        }
	        else if((reportItem->reportType==hidReportOutput) &&
	                (reportItem->globals.usagePage==USAGE_PAGE_LEDS))
	        {
	            usageIndex = reportItem->firstUsageItem;
	            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

	            reportIndex = reportItem->globals.reportIndex;
	            Appl_LED_Indicator.reportLength = (pitemListPtrs->reportList[reportIndex].outputBits + 7)/8;
	            Appl_LED_Indicator.reportID = (BYTE)reportItem->globals.reportID;
	            Appl_LED_Indicator.bitOffset = (BYTE)reportItem->startBit;
	            Appl_LED_Indicator.bitLength = (BYTE)reportItem->globals.reportsize;
	            Appl_LED_Indicator.count=(BYTE)reportItem->globals.reportCount;
	            Appl_LED_Indicator.interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
	            foundLEDIndicator = TRUE;
	        }

	    }

	   if(pDeviceRptinfo->reports == 1)
	    {
	        Appl_raw_report_buffer.Report_ID = 0;
	        Appl_raw_report_buffer.ReportSize = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
	        Appl_raw_report_buffer.ReportData_Keyboard = (BYTE*)malloc(Appl_raw_report_buffer.ReportSize);
	        Appl_raw_report_buffer.ReportPollRate = pDeviceRptinfo->reportPollingRate;
	        if((foundNormalKey == TRUE)&&(foundModifierKey == TRUE))
	        status = TRUE;
	    }
	}
	    return(status);
}
/****************************************************************************
  Function:
    BOOL USB_HID_DataCollectionHandler(void)
  Description:
    This function is invoked by HID client , purpose is to collect the
    details extracted from the report descriptor. HID client will store
    information extracted from the report descriptor in data structures.
    Application needs to create object for each report type it needs to
    extract.
    For ex: HID_DATA_DETAILS keyboard.keys.modifier.details;
    HID_DATA_DETAILS is defined in file usb_host_hid_appl_interface.h
    Each member of the structure must be initialized inside this function.
    Application interface layer provides functions :
    USBHostHID_ApiFindBit()
    USBHostHID_ApiFindValue()
    These functions can be used to fill in the details as shown in the demo
    code.

  Precondition:
    None

  Parameters:
    None

  Return Values:
    true    - If the report details are collected successfully.
    false   - If the application does not find the the supported format.

  Remarks:
    This Function name should be entered in the USB configuration tool
    in the field "Parsed Data Collection handler".
    If the application does not define this function , then HID cient
    assumes that Application is aware of report format of the attached
    device.
***************************************************************************/
bool APP_HostHIDKeyboardReportParser(void)
{
    uint8_t NumOfReportItem = 0;
    uint8_t i;
    USB_HID_ITEM_LIST* pitemListPtrs;
    USB_HID_DEVICE_RPT_INFO* pDeviceRptinfo;
    HID_REPORTITEM *reportItem;
    HID_USAGEITEM *hidUsageItem;
    uint8_t usageIndex;
    uint8_t reportIndex;
    bool foundLEDIndicator = false;
    bool foundModifierKey = false;
    bool foundNormalKey = false;

    /* The keyboard is already in use. */
    if(keyboard.inUse == true)
    {
        return false;
    }

    pDeviceRptinfo = USBHostHID_GetCurrentReportInfo(); // Get current Report Info pointer
    pitemListPtrs = USBHostHID_GetItemListPointers();   // Get pointer to list of item pointers

    /* Find Report Item Index for Modifier Keys */
    /* Once report Item is located , extract information from data structures provided by the parser */
    NumOfReportItem = pDeviceRptinfo->reportItems;
    for(i=0;i<NumOfReportItem;i++)
    {
        reportItem = &pitemListPtrs->reportItemList[i];
        if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Variable)&&
           (reportItem->globals.usagePage==USB_HID_USAGE_PAGE_KEYBOARD_KEYPAD))
        {
            /* We now know report item points to modifier keys */
            /* Now make sure usage Min & Max are as per application */
            usageIndex = reportItem->firstUsageItem;
            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];
            if((hidUsageItem->usageMinimum == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_LEFT_CONTROL)
                &&(hidUsageItem->usageMaximum == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_RIGHT_GUI)) //else application cannot suuport
            {
               reportIndex = reportItem->globals.reportIndex;
               keyboard.keys.modifier.parsed.details.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
               keyboard.keys.modifier.parsed.details.reportID = (uint8_t)reportItem->globals.reportID;
               keyboard.keys.modifier.parsed.details.bitOffset = (uint8_t)reportItem->startBit;
               keyboard.keys.modifier.parsed.details.bitLength = (uint8_t)reportItem->globals.reportsize;
               keyboard.keys.modifier.parsed.details.count=(uint8_t)reportItem->globals.reportCount;
               keyboard.keys.modifier.parsed.details.interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
               foundModifierKey = true;
            }

        }
        else if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Array)&&
           (reportItem->globals.usagePage==USB_HID_USAGE_PAGE_KEYBOARD_KEYPAD))
        {
            /* We now know report item points to modifier keys */
            /* Now make sure usage Min & Max are as per application */
            usageIndex = reportItem->firstUsageItem;
            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];
           reportIndex = reportItem->globals.reportIndex;
           keyboard.keys.normal.parsed.details.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
           keyboard.keys.normal.parsed.details.reportID = (uint8_t)reportItem->globals.reportID;
           keyboard.keys.normal.parsed.details.bitOffset = (uint8_t)reportItem->startBit;
           keyboard.keys.normal.parsed.details.bitLength = (uint8_t)reportItem->globals.reportsize;
           keyboard.keys.normal.parsed.details.count = (uint8_t)reportItem->globals.reportCount;
           keyboard.keys.normal.parsed.details.interfaceNum = USBHostHID_ApiGetCurrentInterfaceNum();
           foundNormalKey = true;
        }
        else if((reportItem->reportType==hidReportOutput) &&
                (reportItem->globals.usagePage==USB_HID_USAGE_PAGE_LEDS))
        {
            usageIndex = reportItem->firstUsageItem;
            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

            reportIndex = reportItem->globals.reportIndex;
            keyboard.leds.parsed.details.reportLength = (pitemListPtrs->reportList[reportIndex].outputBits + 7)/8;
            keyboard.leds.parsed.details.reportID = (uint8_t)reportItem->globals.reportID;
            keyboard.leds.parsed.details.bitOffset = (uint8_t)reportItem->startBit;
            keyboard.leds.parsed.details.bitLength = (uint8_t)reportItem->globals.reportsize;
            keyboard.leds.parsed.details.count = (uint8_t)reportItem->globals.reportCount;
            keyboard.leds.parsed.details.interfaceNum = USBHostHID_ApiGetCurrentInterfaceNum();
            foundLEDIndicator = true;
        }
    }

    if(pDeviceRptinfo->reports == 1)
    {
        keyboard.keys.id = 0;
        keyboard.keys.size = keyboard.keys.normal.parsed.details.reportLength;
        keyboard.keys.buffer = (uint8_t*)malloc(keyboard.keys.size);
        keyboard.keys.pollRate = pDeviceRptinfo->reportPollingRate;

        if( (foundNormalKey == true) &&
            (foundModifierKey == true) &&
            (keyboard.keys.buffer != NULL)
        )
        {
            keyboard.inUse = true;
        }
    }

    return(keyboard.inUse);
}
Ejemplo n.º 5
0
/****************************************************************************
  Function:
    BOOL USB_HID_DataCollectionHandler(void)
  Description:
    This function is invoked by HID client , purpose is to collect the
    details extracted from the report descriptor. HID client will store
    information extracted from the report descriptor in data structures.
    Application needs to create object for each report type it needs to
    extract.
    For ex: HID_DATA_DETAILS mouse.report.modifier.details;
    HID_DATA_DETAILS is defined in file usb_host_hid_appl_interface.h
    Each member of the structure must be initialized inside this function.
    Application interface layer provides functions :
    USBHostHID_ApiFindBit()
    USBHostHID_ApiFindValue()
    These functions can be used to fill in the details as shown in the demo
    code.

  Precondition:
    None

  Parameters:
    None

  Return Values:
    true    - If the report details are collected successfully.
    false   - If the application does not find the the supported format.

  Remarks:
    This Function name should be entered in the USB configuration tool
    in the field "Parsed Data Collection handler".
    If the application does not define this function , then HID cient
    assumes that Application is aware of report format of the attached
    device.
***************************************************************************/
bool APP_HostHIDMouseReportParser(void)
{
    uint8_t NumOfReportItem = 0;
    uint8_t i;
    USB_HID_ITEM_LIST* pitemListPtrs;
    USB_HID_DEVICE_RPT_INFO* pDeviceRptinfo;
    HID_REPORTITEM *reportItem;
    HID_USAGEITEM *hidUsageItem;
    uint8_t usageIndex;
    uint8_t reportIndex;
    uint8_t usageItem;
    bool foundX = false;
    bool foundY = false;

    /* The keyboard is already in use. */
    if(mouse.inUse == true)
    {
        return false;
    }

    pDeviceRptinfo = USBHostHID_GetCurrentReportInfo(); // Get current Report Info pointer
    pitemListPtrs = USBHostHID_GetItemListPointers();   // Get pointer to list of item pointers

    /* Find Report Item Index for Modifier Keys */
    /* Once report Item is located , extract information from data structures provided by the parser */
    NumOfReportItem = pDeviceRptinfo->reportItems;
    for(i=0;i<NumOfReportItem;i++)
    {
        reportItem = &pitemListPtrs->reportItemList[i];
        if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == (HIDData_Variable|HIDData_Relative))&&
           (reportItem->globals.usagePage==USB_HID_USAGE_PAGE_GENERIC_DESKTOP_CONTROLS))
        {
            if( (foundX == false) && (foundY == false) )
            {
                usageIndex = reportItem->firstUsageItem;

                for(usageItem = 0; usageItem < reportItem->usageItems; usageItem++, usageIndex++)
                {
                    hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

                    if(hidUsageItem->usage == USB_HID_GENERIC_DESKTOP_X)
                    {
                        foundX = true;
                    }

                    if(hidUsageItem->usage == USB_HID_GENERIC_DESKTOP_Y)
                    {
                        foundY = true;
                    }
                }

                reportIndex = reportItem->globals.reportIndex;
                mouse.deflection.parsed.details.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
                mouse.deflection.parsed.details.reportID = (uint8_t)reportItem->globals.reportID;
                mouse.deflection.parsed.details.bitOffset = (uint8_t)reportItem->startBit;
                mouse.deflection.parsed.details.bitLength = (uint8_t)reportItem->globals.reportsize;
                mouse.deflection.parsed.details.count=(uint8_t)reportItem->globals.reportCount;
                mouse.deflection.parsed.details.interfaceNum= USBHostHID_ApiGetCurrentInterfaceNum();
            }

        }
        else if((reportItem->reportType==hidReportInput) && (reportItem->dataModes == HIDData_Variable)&&
           (reportItem->globals.usagePage==USB_HID_USAGE_PAGE_BUTTON))
        {
            /* Now make sure usage Min & Max are as per application */
            usageIndex = reportItem->firstUsageItem;
            hidUsageItem = &pitemListPtrs->usageItemList[usageIndex];

            reportIndex = reportItem->globals.reportIndex;
            mouse.buttons.parsed.details.reportLength = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
            mouse.buttons.parsed.details.reportID = (uint8_t)reportItem->globals.reportID;
            mouse.buttons.parsed.details.bitOffset = (uint8_t)reportItem->startBit;
            mouse.buttons.parsed.details.bitLength = (uint8_t)reportItem->globals.reportsize;
            mouse.buttons.parsed.details.count = (uint8_t)reportItem->globals.reportCount;
            mouse.buttons.parsed.details.interfaceNum = USBHostHID_ApiGetCurrentInterfaceNum();

        }
    }

    if(pDeviceRptinfo->reports == 1)
    {
        mouse.size = (pitemListPtrs->reportList[reportIndex].inputBits + 7)/8;
        mouse.buffer = (uint8_t*)malloc(mouse.size);
        mouse.pollRate = pDeviceRptinfo->reportPollingRate;

        if( (foundX == true) && (foundY == true) )
        {
            mouse.inUse = true;
        }
    }

    return(mouse.inUse);
}