aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/Class
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-09-21 12:23:09 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-09-21 12:23:09 +0000
commit242303c1607fca405d9407b9fab6fb78cae676e2 (patch)
tree1163c20f5035ee4df711d1c718ef310ba89d2b53 /LUFA/Drivers/USB/Class
parent3ffa7543a05761a0c69144c9b66196b08d8f1249 (diff)
downloadlufa-242303c1607fca405d9407b9fab6fb78cae676e2.tar.gz
lufa-242303c1607fca405d9407b9fab6fb78cae676e2.tar.bz2
lufa-242303c1607fca405d9407b9fab6fb78cae676e2.zip
Add new attributes to the HID Report Parser and HID Host Mode Class driver to keep track of the largest report the device can send for buffer allocation purposes. Change MouseHostWithParser and KeyboardHostWithParser demos to only allocate the needed number of bytes.
Diffstat (limited to 'LUFA/Drivers/USB/Class')
-rw-r--r--LUFA/Drivers/USB/Class/Host/HID.c5
-rw-r--r--LUFA/Drivers/USB/Class/Host/HID.h2
-rw-r--r--LUFA/Drivers/USB/Class/Host/HIDParser.c15
-rw-r--r--LUFA/Drivers/USB/Class/Host/HIDParser.h5
4 files changed, 21 insertions, 6 deletions
diff --git a/LUFA/Drivers/USB/Class/Host/HID.c b/LUFA/Drivers/USB/Class/Host/HID.c
index 87d37933e..b420a5b91 100644
--- a/LUFA/Drivers/USB/Class/Host/HID.c
+++ b/LUFA/Drivers/USB/Class/Host/HID.c
@@ -101,6 +101,7 @@ uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo
}
}
+ HIDInterfaceInfo->State.LargestReportSize = 8;
HIDInterfaceInfo->State.IsActive = true;
return HID_ENUMERROR_NoError;
}
@@ -288,6 +289,7 @@ uint8_t USB_HID_Host_SetBootProtocol(USB_ClassInfo_HID_Host_t* const HIDInterfac
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
+ HIDInterfaceInfo->State.LargestReportSize = 8;
HIDInterfaceInfo->State.UsingBootProtocol = true;
return HOST_SENDCONTROL_Successful;
@@ -339,6 +341,9 @@ uint8_t USB_HID_Host_SetReportProtocol(USB_ClassInfo_HID_Host_t* const HIDInterf
return HID_ERROR_LOGICAL | ErrorCode;
}
+ uint8_t LargestReportSizeBits = HIDInterfaceInfo->Config.HIDParserData->LargestReportSizeBits;
+ HIDInterfaceInfo->State.LargestReportSize = (LargestReportSizeBits >> 3) + ((LargestReportSizeBits & 0x07) != 0);
+
return 0;
}
diff --git a/LUFA/Drivers/USB/Class/Host/HID.h b/LUFA/Drivers/USB/Class/Host/HID.h
index 8f80ea8c2..5526990ad 100644
--- a/LUFA/Drivers/USB/Class/Host/HID.h
+++ b/LUFA/Drivers/USB/Class/Host/HID.h
@@ -101,6 +101,8 @@
*/
bool UsingBootProtocol; /**< Indicates that the interface is currently initialised in Boot Protocol mode */
uint16_t HIDReportSize; /**< Size in bytes of the HID report descriptor in the device */
+
+ uint8_t LargestReportSize; /**< Largest report the device will send, in bytes */
} State; /**< State data for the USB class interface within the device. All elements in this section
* <b>may</b> be set to initial values, but may also be ignored to default to sane values when
* the interface is enumerated.
diff --git a/LUFA/Drivers/USB/Class/Host/HIDParser.c b/LUFA/Drivers/USB/Class/Host/HIDParser.c
index b302a94b4..450f6afb0 100644
--- a/LUFA/Drivers/USB/Class/Host/HIDParser.c
+++ b/LUFA/Drivers/USB/Class/Host/HIDParser.c
@@ -241,29 +241,36 @@ uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID
{
NewReportItem.Attributes.Usage.Usage = 0;
}
-
+
+ uint8_t ReportSizeIndex = 0;
+
switch (HIDReportItem & TAG_MASK)
{
case TAG_MAIN_INPUT:
NewReportItem.ItemType = REPORT_ITEM_TYPE_In;
NewReportItem.BitOffset = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_In];
- CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_In] += CurrStateTable->Attributes.BitSize;
+ ReportSizeIndex = REPORT_ITEM_TYPE_In;
break;
case TAG_MAIN_OUTPUT:
NewReportItem.ItemType = REPORT_ITEM_TYPE_Out;
NewReportItem.BitOffset = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Out];
- CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Out] += CurrStateTable->Attributes.BitSize;
+ ReportSizeIndex = REPORT_ITEM_TYPE_Out;
break;
case TAG_MAIN_FEATURE:
NewReportItem.ItemType = REPORT_ITEM_TYPE_Feature;
NewReportItem.BitOffset = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Feature];
- CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Feature] += CurrStateTable->Attributes.BitSize;
+ ReportSizeIndex = REPORT_ITEM_TYPE_Feature;
break;
}
+
+ CurrReportIDInfo->ReportSizeBits[ReportSizeIndex] += CurrStateTable->Attributes.BitSize;
+ if (ParserData->LargestReportSizeBits < CurrReportIDInfo->ReportSizeBits[ReportSizeIndex])
+ ParserData->LargestReportSizeBits = CurrReportIDInfo->ReportSizeBits[ReportSizeIndex];
+
if (!(ReportItemData & IOF_CONSTANT) && CALLBACK_HIDParser_FilterHIDReportItem(&CurrStateTable->Attributes))
{
if (ParserData->TotalReportItems == HID_MAX_REPORTITEMS)
diff --git a/LUFA/Drivers/USB/Class/Host/HIDParser.h b/LUFA/Drivers/USB/Class/Host/HIDParser.h
index f2cd35b88..2ee3f7032 100644
--- a/LUFA/Drivers/USB/Class/Host/HIDParser.h
+++ b/LUFA/Drivers/USB/Class/Host/HIDParser.h
@@ -225,8 +225,9 @@
HID_CollectionPath_t CollectionPaths[HID_MAX_COLLECTIONS]; /**< All collection items, referenced
* by the report items.
*/
- uint8_t TotalDeviceReports; /** Number of reports within the HID interface */
- HID_ReportSizeInfo_t ReportIDSizes[HID_MAX_REPORT_IDS]; /** Report sizes for each report in the interface */
+ uint8_t TotalDeviceReports; /**< Number of reports within the HID interface */
+ HID_ReportSizeInfo_t ReportIDSizes[HID_MAX_REPORT_IDS]; /**< Report sizes for each report in the interface */
+ uint16_t LargestReportSizeBits; /**< Largest report that the attached device will generate, in bits */
bool UsingReportIDs; /**< Indicates if the device has at least one REPORT ID
* element in its HID report descriptor.
*/