return ParseSuccessful;\r
}\r
\r
+/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store\r
+ * an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items\r
+ * we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would\r
+ * have occupied).\r
+ *\r
+ * \param CurrentItemAttributes Pointer to the attrbutes of the item the HID report parser is currently working with\r
+ *\r
+ * \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded\r
+ */\r
+bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_Attributes_t* CurrentItemAttributes)\r
+{\r
+ /* Check the attributes of the current item - see if we are interested in it or not */\r
+ if (CurrentItemAttributes->Usage.Page == USAGE_PAGE_KEYBOARD)\r
+ {\r
+ /* Only store KEYBOARD usage page items into the Processed HID Report structure to save RAM */\r
+ return true;\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+}\r
\r
/* Function Prototypes: */\r
uint8_t GetHIDReportData(void);\r
+\r
+ bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_Attributes_t* CurrentItemAttributes);\r
\r
#endif\r
\r
return ParseSuccessful;\r
}\r
+\r
+/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store\r
+ * an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items\r
+ * we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would\r
+ * have occupied).\r
+ *\r
+ * \param CurrentItemAttributes Pointer to the attrbutes of the item the HID report parser is currently working with\r
+ *\r
+ * \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded\r
+ */\r
+bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_Attributes_t* CurrentItemAttributes)\r
+{\r
+ /* Check the attributes of the current item - see if we are interested in it or not */\r
+ if ((CurrentItemAttributes->Usage.Page == USAGE_PAGE_BUTTON) ||\r
+ (CurrentItemAttributes->Usage.Page == USAGE_PAGE_GENERIC_DCTRL))\r
+ {\r
+ /* Only store BUTTON and GENERIC_DESKTOP_CONTROL items into the Processed HID Report structure to save RAM */\r
+ return true;\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+}\r
/* Function Prototypes: */\r
uint8_t GetHIDReportData(void);\r
\r
+ bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_Attributes_t* CurrentItemAttributes);\r
+ \r
#endif\r
\r
uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData)\r
{\r
- HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH];\r
- HID_StateTable_t* CurrStateTable = &StateTable[0];\r
- uint16_t UsageStack[HID_USAGE_STACK_DEPTH];\r
- uint8_t UsageStackSize = 0;\r
- uint16_t BitOffsetIn = 0;\r
- uint16_t BitOffsetOut = 0;\r
-#if defined(HID_ENABLE_FEATURE_PROCESSING)\r
- uint16_t BitOffsetFeature = 0;\r
-#endif\r
+ HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH];\r
+ HID_StateTable_t* CurrStateTable = &StateTable[0];\r
HID_CollectionPath_t* CurrCollectionPath = NULL;\r
+ uint16_t UsageStack[HID_USAGE_STACK_DEPTH];\r
+ uint8_t UsageStackSize = 0;\r
+ uint16_t BitOffsetIn = 0;\r
+ uint16_t BitOffsetOut = 0;\r
+ uint16_t BitOffsetFeature = 0;\r
\r
ParserData->TotalReportItems = 0;\r
ParserData->UsingMultipleReports = false;\r
ParserData->UsingMultipleReports = true;\r
BitOffsetIn = 0;\r
BitOffsetOut = 0;\r
-\r
- #if defined(HID_ENABLE_FEATURE_PROCESSING)\r
BitOffsetFeature = 0;\r
- #endif\r
break;\r
case (TYPE_LOCAL | TAG_LOCAL_USAGE):\r
if (UsageStackSize == HID_USAGE_STACK_DEPTH)\r
break;\r
case (TYPE_MAIN | TAG_MAIN_INPUT):\r
case (TYPE_MAIN | TAG_MAIN_OUTPUT):\r
-#if defined(HID_ENABLE_FEATURE_PROCESSING)\r
case (TYPE_MAIN | TAG_MAIN_FEATURE):\r
-#endif\r
for (uint8_t ReportItemNum = 0; ReportItemNum < CurrStateTable->ReportCount; ReportItemNum++)\r
{\r
- HID_ReportItem_t* CurrReportItem = &ParserData->ReportItems[ParserData->TotalReportItems];\r
- \r
- if (ParserData->TotalReportItems == HID_MAX_REPORTITEMS)\r
- return HID_PARSE_InsufficientReportItems;\r
+ HID_ReportItem_t NewReportItem;\r
\r
- memcpy(&CurrReportItem->Attributes,\r
+ memcpy(&NewReportItem.Attributes,\r
&CurrStateTable->Attributes,\r
sizeof(HID_ReportItem_Attributes_t));\r
\r
- CurrReportItem->ItemFlags = ReportItemData;\r
- CurrReportItem->CollectionPath = CurrCollectionPath;\r
- CurrReportItem->ReportID = CurrStateTable->ReportID;\r
+ NewReportItem.ItemFlags = ReportItemData;\r
+ NewReportItem.CollectionPath = CurrCollectionPath;\r
+ NewReportItem.ReportID = CurrStateTable->ReportID;\r
\r
if (UsageStackSize)\r
{\r
- CurrReportItem->Attributes.Usage.Usage = UsageStack[0];\r
+ NewReportItem.Attributes.Usage.Usage = UsageStack[0];\r
\r
for (uint8_t i = 0; i < UsageStackSize; i++)\r
UsageStack[i] = UsageStack[i + 1];\r
}\r
else\r
{\r
- CurrReportItem->Attributes.Usage.Usage = 0;\r
+ NewReportItem.Attributes.Usage.Usage = 0;\r
}\r
\r
switch (HIDReportItem & TAG_MASK)\r
{\r
case TAG_MAIN_INPUT:\r
- CurrReportItem->ItemType = REPORT_ITEM_TYPE_In;\r
- CurrReportItem->BitOffset = BitOffsetIn;\r
+ NewReportItem.ItemType = REPORT_ITEM_TYPE_In;\r
+ NewReportItem.BitOffset = BitOffsetIn;\r
\r
BitOffsetIn += CurrStateTable->Attributes.BitSize;\r
- \r
break;\r
case TAG_MAIN_OUTPUT:\r
- CurrReportItem->ItemType = REPORT_ITEM_TYPE_Out;\r
- CurrReportItem->BitOffset = BitOffsetOut;\r
+ NewReportItem.ItemType = REPORT_ITEM_TYPE_Out;\r
+ NewReportItem.BitOffset = BitOffsetOut;\r
\r
BitOffsetOut += CurrStateTable->Attributes.BitSize;\r
- \r
break;\r
-#if defined(HID_ENABLE_FEATURE_PROCESSING)\r
case TAG_MAIN_FEATURE:\r
- CurrReportItem->ItemType = REPORT_ITEM_TYPE_Feature; \r
- CurrReportItem->BitOffset = BitOffsetFeature;\r
+ NewReportItem.ItemType = REPORT_ITEM_TYPE_Feature; \r
+ NewReportItem.BitOffset = BitOffsetFeature;\r
\r
- BitOffsetFeature += CurrStateTable->Attributes.BitSize; \r
-\r
+ BitOffsetFeature += CurrStateTable->Attributes.BitSize;\r
break;\r
-#endif\r
}\r
+\r
+ if (!(ReportItemData & IOF_CONSTANT) && CALLBACK_HIDParser_FilterHIDReportItem(&CurrStateTable->Attributes))\r
+ { \r
+ if (ParserData->TotalReportItems == HID_MAX_REPORTITEMS)\r
+ return HID_PARSE_InsufficientReportItems;\r
\r
-#if defined(HID_INCLUDE_CONSTANT_DATA_ITEMS)\r
- ParserData->TotalReportItems++;\r
-#else\r
- if (!(ReportItemData & IOF_CONSTANT))\r
- ParserData->TotalReportItems++;\r
-#endif\r
+ memcpy(&ParserData->ReportItems[ParserData->TotalReportItems],\r
+ &NewReportItem, sizeof(HID_ReportItem_t));\r
+ \r
+ ParserData->TotalReportItems++;\r
+ }\r
}\r
\r
UsageStackSize = 0;\r
* Functions, macros, variables, enums and types related to the parsing of HID class device report descriptors.\r
*\r
* The processed HID report is presented back to the user application as a flat structure containing each report\r
- * item's IN, OUT and FEATURE (if desired) items along with each item's attributes.\r
+ * item's IN, OUT and FEATURE items along with each item's attributes.\r
*\r
* This library portion also allows for easy setting and retrieval of data from a HID report, including devices\r
* with multiple reports on the one HID interface.\r
*\r
- * By default, FEATURE reports and IN/OUT reports with constant data are ignored in the HID report when processed\r
- * to save on memory. This can be overridden by defining the HID_ENABLE_FEATURE_PROCESSING or\r
- * HID_INCLUDE_CONSTANT_DATA_ITEMS tokens in the user project makefile, passing them to the compiler via the -D\r
- * switch.\r
- *\r
* @{\r
*/\r
\r
#endif\r
\r
#if !defined(HID_MAX_REPORTITEMS) || defined(__DOXYGEN__)\r
- /** Constant indicating the maximum number of report items (IN, OUT or FEATURE if enabled) that can be\r
- * processed in the report item descriptor. A large value allows for more report items to be\r
- * processed, but consumes more memory. By default this is set to 30 items, but this can be\r
- * overridden by defining HID_MAX_REPORTITEMS to another value in the user project makefile, passing\r
- * the define to the compiler using the -D compiler switch.\r
+ /** Constant indicating the maximum number of report items (IN, OUT or FEATURE) that can be processed \r
+ * in the report item descriptor and stored in the user HID Report Info structure. A large value allows\r
+ * for more report items to be stored, but consumes more memory. By default this is set to 20 items, \r
+ * but this can be overridden by defining HID_MAX_REPORTITEMS to another value in the user project\r
+ * makefile, passing the define to the compiler using the -D compiler switch.\r
*/\r
- #define HID_MAX_REPORTITEMS 30\r
+ #define HID_MAX_REPORTITEMS 20\r
#endif\r
\r
/* Public Interface - May be used in end-application: */\r
*/\r
void USB_SetHIDReportItemInfo(uint8_t* ReportData, const HID_ReportItem_t* ReportItem)\r
ATTR_NON_NULL_PTR_ARG(1, 2);\r
+ \r
+ /** Callback routine for the HID Report Parser. This callback <b>must</b> be implemented by the user code when\r
+ * the parser is used, to determine what report IN, OUT and FEATURE item's information is stored into the user\r
+ * HID_ReportInfo_t structure. This can be used to filter only those items the application will be using, so that\r
+ * no RAM is wasted storing the attributes for report items which will never be referenced by the application.\r
+ *\r
+ * \param CurrentItemAttributes Pointer to the current report item attributes for user checking\r
+ *\r
+ * \return Boolean true if the item should be stored into the HID_ReportInfo_t structure, false if it should be ignored\r
+ */\r
+ bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_Attributes_t* CurrentItemAttributes);\r
\r
/* Private Interface - For use in library only: */\r
#if !defined(__DOXYGEN__)\r
* - Added ShutDown() functions for all hardware peripheral drivers, so that peripherals can be turned off after use\r
* - Added new CDC_Device_Flush() command to the device mode CDC Class driver to flush Device->Host data\r
* - Added extra masks to the SPI driver, changed SPI_Init() so that the clock polarity and sample modes can be set\r
+ * - Added new callback to the HID report parser, so that the user application can filter only the items it is interested\r
+ * in to be stored into the HIDReportInfo structure to save RAM\r
* \r
* <b>Changed:</b>\r
* - SetIdle requests to the HID device driver with a 0 idle period (send changes only) now only affect the requested\r
* - Changed the parameters and behaviour of the USB_GetDeviceConfigDescriptor() function so that it now performs size checks\r
* and data validations internally, to simplify user code\r
* - Changed HIDParser to only zero out important values in the Parsed HID Report Item Information structure to save cycles\r
+ * - The HID report parser now always processed FEATURE items - HID_ENABLE_FEATURE_PROCESSING token now has no effect\r
+ * - The HID report parser now always ignores constant-data items, HID_INCLUDE_CONSTANT_DATA_ITEMS token now has no effect\r
*\r
* <b>Fixed:</b>\r
* - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the\r
* \section Sec_SummaryUSBClassTokens USB Class Driver Related Tokens\r
* This section describes compile tokens which affect USB class-specific drivers in the LUFA library.\r
*\r
- * <b>HID_ENABLE_FEATURE_PROCESSING</b> - ( \ref Group_HIDParser ) \n\r
- * Define this token to enable the processing of FEATURE HID report items, if any, into the processed HID structure.\r
- * By default FEATURE items (which are device features settable by the host but not directly visible by the user) are\r
- * skipped when processing a device HID report.\r
- *\r
- * <b>HID_INCLUDE_CONSTANT_DATA_ITEMS</b> - ( \ref Group_HIDParser ) \n\r
- * By default, constant data items (usually used as spacers to align separate report items to a byte or word boundary)\r
- * in the HID report are skipped during report processing. It is highly unusual for an application to make any use of\r
- * constant data items (as they do not carry any useful data and only occupy limited RAM) however if required defining\r
- * this switch will put constant data items into the processed HID report structure.\r
- *\r
* <b>HID_STATETABLE_STACK_DEPTH</b> - ( \ref Group_HIDParser ) \n\r
* HID reports may contain PUSH and POP elements, to store and retrieve the current HID state table onto a stack. This\r
* allows for reports to save the state table before modifying it slightly for a data item, and then restore the previous\r
* preallocate the largest allowable buffer, and pass the size of the buffer to the function. This allows for a single\r
* call to the function to retrieve, size check and validate the Configuration Descriptor rather than having the user\r
* application perform these intermediatary steps.\r
+ * - The HID report parser now requires a mandatory callback in the user code, to filter only the items the application\r
+ * is interested in into the processed HID report item structure to save RAM. See \ref CALLBACK_HIDParser_FilterHIDReportItem().\r
+ * - The HID report parser now always parses FEATURE and always ignores constant-data items - the HID_ENABLE_FEATURE_PROCESSING\r
+ * and HID_INCLUDE_CONSTANT_DATA_ITEMS compile time tokens now have no effect.\r
*\r
* \section Sec_Migration090810 Migrating from 090605 to 090810\r
*\r