Commit dab7e06a authored by Dean Camera's avatar Dean Camera
Browse files

Split HIDReportViewer project sub-components into seperate functions for readability/convenience.

parent ea3b5c74
......@@ -123,10 +123,29 @@ int main(void)
case HOST_STATE_Configured:
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
OutputReportSizes();
OutputParsedReportItems();
LEDs_SetAllLEDs(LEDMASK_USB_READY);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
HID_Host_USBTask(&Device_HID_Interface);
USB_USBTask();
}
}
/** Prints a summary of the device's HID report sizes from the HID parser output to the serial port
* for display to the user.
*/
void OutputReportSizes(void)
{
printf_P(PSTR("\r\n\r\nTotal Device Reports: %" PRId8 "\r\n"), HIDReportInfo.TotalDeviceReports);
for (uint8_t ReportIndex = 0; ReportIndex < HIDReportInfo.TotalDeviceReports; ReportIndex++)
{
HID_ReportSizeInfo_t* CurrReportIDInfo = &HIDReportInfo.ReportIDSizes[ReportIndex];
const HID_ReportSizeInfo_t* CurrReportIDInfo = &HIDReportInfo.ReportIDSizes[ReportIndex];
uint8_t ReportSizeInBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_In];
uint8_t ReportSizeOutBits = CurrReportIDInfo->ReportSizeBits[HID_REPORT_ITEM_Out];
......@@ -145,8 +164,15 @@ int main(void)
ReportSizeFeatureBits,
((ReportSizeFeatureBits >> 3) + ((ReportSizeFeatureBits & 0x07) != 0)));
}
}
/** Prints a summary of the device's parsed and stored report items along with their attributes
* to the serial port for display to the user.
*/
void OutputParsedReportItems(void)
{
printf_P(PSTR("\r\nReport Items (%" PRId8 " in Table):\r\n"), HIDReportInfo.TotalReportItems);
printf_P(PSTR("\r\nReport Items (%" PRId8 " Stored in Table):\r\n"), HIDReportInfo.TotalReportItems);
for (uint8_t ItemIndex = 0; ItemIndex < HIDReportInfo.TotalReportItems; ItemIndex++)
{
const HID_ReportItem_t* RItem = &HIDReportInfo.ReportItems[ItemIndex];
......@@ -181,27 +207,31 @@ int main(void)
RItem->Attributes.Physical.Minimum,
RItem->Attributes.Physical.Maximum);
const HID_CollectionPath_t* CollectionPath = RItem->CollectionPath;
OutputCollectionPath(RItem->CollectionPath);
}
}
while (CollectionPath != NULL)
/** Prints the HID Collection path (along with each node's attributes) to the serial port
* for display to the user, from the given starting node to the root node.
*
* \param[in] CollectionPath Starting HID Collection node to print
*/
void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath)
{
const HID_CollectionPath_t* CurrentNode = CollectionPath;
while (CurrentNode != NULL)
{
printf_P(PSTR(" |\r\n"
" - Type: 0x%02" PRIX8 "\r\n"
" - Usage: 0x%02" PRIX8 "\r\n"),
CollectionPath->Type, CollectionPath->Usage);
CurrentNode->Type, CurrentNode->Usage);
CollectionPath = CollectionPath->Parent;
}
CurrentNode = CurrentNode->Parent;
}
LEDs_SetAllLEDs(LEDMASK_USB_READY);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
HID_Host_USBTask(&Device_HID_Interface);
USB_USBTask();
}
printf_P(PSTR(" |\r\n"
" END\r\n"));
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
......
......@@ -69,6 +69,9 @@
/* Function Prototypes: */
void SetupHardware(void);
void OutputReportSizes(void);
void OutputParsedReportItems(void);
void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath);
void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
void EVENT_USB_Host_DeviceAttached(void);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment