aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/Class
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-09-02 07:16:52 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-09-02 07:16:52 +0000
commit205b35d131a1cc8196786de4370cb90fec17835e (patch)
treee7b8e03e03a3f8fafa8a19997547a4772674d1a9 /LUFA/Drivers/USB/Class
parentecf7c18cf24a10df8d843c8f7c195d803e073330 (diff)
downloadlufa-205b35d131a1cc8196786de4370cb90fec17835e.tar.gz
lufa-205b35d131a1cc8196786de4370cb90fec17835e.tar.bz2
lufa-205b35d131a1cc8196786de4370cb90fec17835e.zip
Add user-filtering to the HID report parser, so that the user code can decide which items are to be stored into the HID_ReportInfo_t structure and which should be discarded to save on RAM usage.
Diffstat (limited to 'LUFA/Drivers/USB/Class')
-rw-r--r--LUFA/Drivers/USB/Class/Host/HIDParser.c73
-rw-r--r--LUFA/Drivers/USB/Class/Host/HIDParser.h30
2 files changed, 49 insertions, 54 deletions
diff --git a/LUFA/Drivers/USB/Class/Host/HIDParser.c b/LUFA/Drivers/USB/Class/Host/HIDParser.c
index 241e17a05..accb8f36b 100644
--- a/LUFA/Drivers/USB/Class/Host/HIDParser.c
+++ b/LUFA/Drivers/USB/Class/Host/HIDParser.c
@@ -35,16 +35,14 @@
uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData)
{
- HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH];
- HID_StateTable_t* CurrStateTable = &StateTable[0];
- uint16_t UsageStack[HID_USAGE_STACK_DEPTH];
- uint8_t UsageStackSize = 0;
- uint16_t BitOffsetIn = 0;
- uint16_t BitOffsetOut = 0;
-#if defined(HID_ENABLE_FEATURE_PROCESSING)
- uint16_t BitOffsetFeature = 0;
-#endif
+ HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH];
+ HID_StateTable_t* CurrStateTable = &StateTable[0];
HID_CollectionPath_t* CurrCollectionPath = NULL;
+ uint16_t UsageStack[HID_USAGE_STACK_DEPTH];
+ uint8_t UsageStackSize = 0;
+ uint16_t BitOffsetIn = 0;
+ uint16_t BitOffsetOut = 0;
+ uint16_t BitOffsetFeature = 0;
ParserData->TotalReportItems = 0;
ParserData->UsingMultipleReports = false;
@@ -131,10 +129,7 @@ uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID
ParserData->UsingMultipleReports = true;
BitOffsetIn = 0;
BitOffsetOut = 0;
-
- #if defined(HID_ENABLE_FEATURE_PROCESSING)
BitOffsetFeature = 0;
- #endif
break;
case (TYPE_LOCAL | TAG_LOCAL_USAGE):
if (UsageStackSize == HID_USAGE_STACK_DEPTH)
@@ -197,27 +192,22 @@ uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID
break;
case (TYPE_MAIN | TAG_MAIN_INPUT):
case (TYPE_MAIN | TAG_MAIN_OUTPUT):
-#if defined(HID_ENABLE_FEATURE_PROCESSING)
case (TYPE_MAIN | TAG_MAIN_FEATURE):
-#endif
for (uint8_t ReportItemNum = 0; ReportItemNum < CurrStateTable->ReportCount; ReportItemNum++)
{
- HID_ReportItem_t* CurrReportItem = &ParserData->ReportItems[ParserData->TotalReportItems];
-
- if (ParserData->TotalReportItems == HID_MAX_REPORTITEMS)
- return HID_PARSE_InsufficientReportItems;
+ HID_ReportItem_t NewReportItem;
- memcpy(&CurrReportItem->Attributes,
+ memcpy(&NewReportItem.Attributes,
&CurrStateTable->Attributes,
sizeof(HID_ReportItem_Attributes_t));
- CurrReportItem->ItemFlags = ReportItemData;
- CurrReportItem->CollectionPath = CurrCollectionPath;
- CurrReportItem->ReportID = CurrStateTable->ReportID;
+ NewReportItem.ItemFlags = ReportItemData;
+ NewReportItem.CollectionPath = CurrCollectionPath;
+ NewReportItem.ReportID = CurrStateTable->ReportID;
if (UsageStackSize)
{
- CurrReportItem->Attributes.Usage.Usage = UsageStack[0];
+ NewReportItem.Attributes.Usage.Usage = UsageStack[0];
for (uint8_t i = 0; i < UsageStackSize; i++)
UsageStack[i] = UsageStack[i + 1];
@@ -226,42 +216,41 @@ uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID
}
else
{
- CurrReportItem->Attributes.Usage.Usage = 0;
+ NewReportItem.Attributes.Usage.Usage = 0;
}
switch (HIDReportItem & TAG_MASK)
{
case TAG_MAIN_INPUT:
- CurrReportItem->ItemType = REPORT_ITEM_TYPE_In;
- CurrReportItem->BitOffset = BitOffsetIn;
+ NewReportItem.ItemType = REPORT_ITEM_TYPE_In;
+ NewReportItem.BitOffset = BitOffsetIn;
BitOffsetIn += CurrStateTable->Attributes.BitSize;
-
break;
case TAG_MAIN_OUTPUT:
- CurrReportItem->ItemType = REPORT_ITEM_TYPE_Out;
- CurrReportItem->BitOffset = BitOffsetOut;
+ NewReportItem.ItemType = REPORT_ITEM_TYPE_Out;
+ NewReportItem.BitOffset = BitOffsetOut;
BitOffsetOut += CurrStateTable->Attributes.BitSize;
-
break;
-#if defined(HID_ENABLE_FEATURE_PROCESSING)
case TAG_MAIN_FEATURE:
- CurrReportItem->ItemType = REPORT_ITEM_TYPE_Feature;
- CurrReportItem->BitOffset = BitOffsetFeature;
+ NewReportItem.ItemType = REPORT_ITEM_TYPE_Feature;
+ NewReportItem.BitOffset = BitOffsetFeature;
- BitOffsetFeature += CurrStateTable->Attributes.BitSize;
-
+ BitOffsetFeature += CurrStateTable->Attributes.BitSize;
break;
-#endif
}
+
+ if (!(ReportItemData & IOF_CONSTANT) && CALLBACK_HIDParser_FilterHIDReportItem(&CurrStateTable->Attributes))
+ {
+ if (ParserData->TotalReportItems == HID_MAX_REPORTITEMS)
+ return HID_PARSE_InsufficientReportItems;
-#if defined(HID_INCLUDE_CONSTANT_DATA_ITEMS)
- ParserData->TotalReportItems++;
-#else
- if (!(ReportItemData & IOF_CONSTANT))
- ParserData->TotalReportItems++;
-#endif
+ memcpy(&ParserData->ReportItems[ParserData->TotalReportItems],
+ &NewReportItem, sizeof(HID_ReportItem_t));
+
+ ParserData->TotalReportItems++;
+ }
}
UsageStackSize = 0;
diff --git a/LUFA/Drivers/USB/Class/Host/HIDParser.h b/LUFA/Drivers/USB/Class/Host/HIDParser.h
index ec7ff53be..8d3fbf212 100644
--- a/LUFA/Drivers/USB/Class/Host/HIDParser.h
+++ b/LUFA/Drivers/USB/Class/Host/HIDParser.h
@@ -46,16 +46,11 @@
* Functions, macros, variables, enums and types related to the parsing of HID class device report descriptors.
*
* The processed HID report is presented back to the user application as a flat structure containing each report
- * item's IN, OUT and FEATURE (if desired) items along with each item's attributes.
+ * item's IN, OUT and FEATURE items along with each item's attributes.
*
* This library portion also allows for easy setting and retrieval of data from a HID report, including devices
* with multiple reports on the one HID interface.
*
- * By default, FEATURE reports and IN/OUT reports with constant data are ignored in the HID report when processed
- * to save on memory. This can be overridden by defining the HID_ENABLE_FEATURE_PROCESSING or
- * HID_INCLUDE_CONSTANT_DATA_ITEMS tokens in the user project makefile, passing them to the compiler via the -D
- * switch.
- *
* @{
*/
@@ -108,13 +103,13 @@
#endif
#if !defined(HID_MAX_REPORTITEMS) || defined(__DOXYGEN__)
- /** Constant indicating the maximum number of report items (IN, OUT or FEATURE if enabled) that can be
- * processed in the report item descriptor. A large value allows for more report items to be
- * processed, but consumes more memory. By default this is set to 30 items, but this can be
- * overridden by defining HID_MAX_REPORTITEMS to another value in the user project makefile, passing
- * the define to the compiler using the -D compiler switch.
+ /** Constant indicating the maximum number of report items (IN, OUT or FEATURE) that can be processed
+ * in the report item descriptor and stored in the user HID Report Info structure. A large value allows
+ * for more report items to be stored, but consumes more memory. By default this is set to 20 items,
+ * but this can be overridden by defining HID_MAX_REPORTITEMS to another value in the user project
+ * makefile, passing the define to the compiler using the -D compiler switch.
*/
- #define HID_MAX_REPORTITEMS 30
+ #define HID_MAX_REPORTITEMS 20
#endif
/* Public Interface - May be used in end-application: */
@@ -250,6 +245,17 @@
*/
void USB_SetHIDReportItemInfo(uint8_t* ReportData, const HID_ReportItem_t* ReportItem)
ATTR_NON_NULL_PTR_ARG(1, 2);
+
+ /** Callback routine for the HID Report Parser. This callback <b>must</b> be implemented by the user code when
+ * the parser is used, to determine what report IN, OUT and FEATURE item's information is stored into the user
+ * HID_ReportInfo_t structure. This can be used to filter only those items the application will be using, so that
+ * no RAM is wasted storing the attributes for report items which will never be referenced by the application.
+ *
+ * \param CurrentItemAttributes Pointer to the current report item attributes for user checking
+ *
+ * \return Boolean true if the item should be stored into the HID_ReportInfo_t structure, false if it should be ignored
+ */
+ bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_Attributes_t* CurrentItemAttributes);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)