From 3ffa7543a05761a0c69144c9b66196b08d8f1249 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 21 Sep 2009 10:49:06 +0000 Subject: Finish initial draft of the Host Mode HID Class driver. Add new MouseHostWithParser and KeyboardHostWithParser Host Class driver demos. --- LUFA/Drivers/USB/Class/Host/HID.c | 116 +++++++++++++++++--------------- LUFA/Drivers/USB/Class/Host/HID.h | 27 +++++--- LUFA/Drivers/USB/Class/Host/HIDParser.h | 4 +- LUFA/ManPages/LibraryApps.txt | 1 - 4 files changed, 78 insertions(+), 70 deletions(-) (limited to 'LUFA') diff --git a/LUFA/Drivers/USB/Class/Host/HID.c b/LUFA/Drivers/USB/Class/Host/HID.c index 741f56a18..87d37933e 100644 --- a/LUFA/Drivers/USB/Class/Host/HID.c +++ b/LUFA/Drivers/USB/Class/Host/HID.c @@ -34,8 +34,6 @@ #define INCLUDE_FROM_HID_CLASS_HOST_C #include "HID.h" -#warning The HID Host mode Class driver is currently incomplete and is for preview purposes only. - uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, uint16_t ConfigDescriptorSize, uint8_t* ConfigDescriptorData) { @@ -154,62 +152,62 @@ void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo) } -uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, const bool ControlRequest, - uint8_t* ReportID, void* Buffer) +uint8_t HID_Host_ReceiveReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, const uint8_t ReportID, void* Buffer) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), + .bRequest = REQ_SetReport, + .wValue = ReportID, + .wIndex = HIDInterfaceInfo->State.InterfaceNumber, + .wLength = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, ReportID, REPORT_ITEM_TYPE_In), + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(Buffer); +} + +uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, void* Buffer) { if ((USB_HostState != HOST_STATE_Configured) || !(HIDInterfaceInfo->State.IsActive)) return false; - if (ControlRequest) - { - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - .bRequest = REQ_SetReport, - .wValue = *ReportID, - .wIndex = HIDInterfaceInfo->State.InterfaceNumber, - .wLength = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, *ReportID, REPORT_ITEM_TYPE_In), - }; + uint8_t ErrorCode; - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - return USB_Host_SendControlRequest(Buffer); + Pipe_SelectPipe(HIDInterfaceInfo->Config.DataINPipeNumber); + Pipe_Unfreeze(); + + uint16_t ReportSize; + + if (HIDInterfaceInfo->State.UsingBootProtocol) + { + ReportSize = Pipe_BytesInPipe(); } else { - uint8_t ErrorCode; + uint8_t ReportID = 0; - Pipe_SelectPipe(HIDInterfaceInfo->Config.DataINPipeNumber); - Pipe_Unfreeze(); - - uint16_t ReportSize; - - if (HIDInterfaceInfo->State.UsingBootProtocol) + if (HIDInterfaceInfo->Config.HIDParserData->UsingReportIDs) { - ReportSize = Pipe_BytesInPipe(); + ReportID = Pipe_Read_Byte(); + *((uint8_t*)Buffer++) = ReportID; } - else - { - if (HIDInterfaceInfo->Config.HIDParserData->UsingReportIDs) - *ReportID = Pipe_Read_Byte(); - else - *ReportID = 0; - - ReportSize = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, *ReportID, REPORT_ITEM_TYPE_In); - } - - if ((ErrorCode = Pipe_Read_Stream_LE(Buffer, ReportSize, NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - Pipe_ClearIN(); - Pipe_Freeze(); - return PIPE_RWSTREAM_NoError; + ReportSize = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, ReportID, REPORT_ITEM_TYPE_In); } + + if ((ErrorCode = Pipe_Read_Stream_LE(Buffer, ReportSize, NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError) + return ErrorCode; + + Pipe_ClearIN(); + Pipe_Freeze(); + + return PIPE_RWSTREAM_NoError; } -uint8_t HID_Host_SendReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, uint8_t ReportID, void* Buffer, - const uint16_t ReportSize) +uint8_t HID_Host_SendReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, uint8_t ReportID, void* Buffer, + const uint16_t ReportSize) { if ((USB_HostState != HOST_STATE_Configured) || !(HIDInterfaceInfo->State.IsActive)) return false; @@ -268,6 +266,9 @@ bool HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo) uint8_t USB_HID_Host_SetBootProtocol(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo) { + if (HIDInterfaceInfo->State.UsingBootProtocol) + return HOST_SENDCONTROL_Successful; + uint8_t ErrorCode; USB_ControlRequest = (USB_Request_Header_t) @@ -312,23 +313,26 @@ uint8_t USB_HID_Host_SetReportProtocol(USB_ClassInfo_HID_Host_t* const HIDInterf if ((ErrorCode = USB_Host_SendControlRequest(HIDReportData)) != HOST_SENDCONTROL_Successful) return ErrorCode; - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - .bRequest = REQ_SetProtocol, - .wValue = 1, - .wIndex = HIDInterfaceInfo->State.InterfaceNumber, - .wLength = 0, - }; - - if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) - return ErrorCode; + if (HIDInterfaceInfo->State.UsingBootProtocol) + { + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), + .bRequest = REQ_SetProtocol, + .wValue = 1, + .wIndex = HIDInterfaceInfo->State.InterfaceNumber, + .wLength = 0, + }; + + if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) + return ErrorCode; - HIDInterfaceInfo->State.UsingBootProtocol = false; + HIDInterfaceInfo->State.UsingBootProtocol = false; + } if (HIDInterfaceInfo->Config.HIDParserData == NULL) return HID_ERROR_LOGICAL; - + if ((ErrorCode = USB_ProcessHIDReport(HIDReportData, HIDInterfaceInfo->State.HIDReportSize, HIDInterfaceInfo->Config.HIDParserData)) != HID_PARSE_Successful) { diff --git a/LUFA/Drivers/USB/Class/Host/HID.h b/LUFA/Drivers/USB/Class/Host/HID.h index a8865a5c1..8f80ea8c2 100644 --- a/LUFA/Drivers/USB/Class/Host/HID.h +++ b/LUFA/Drivers/USB/Class/Host/HID.h @@ -146,20 +146,25 @@ uint8_t* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1, 3); - /** Receives a HID IN report from the attached HID device, either the next report from the device's IN data pipe, - * or a given report (by Report ID) if a specific report is desired. + /** Receives a HID IN report from the attached HID device, when a report has been received on the HID IN Data pipe. * * \param[in,out] HIDInterfaceInfo Pointer to a structure containing a HID Class host configuration and state - * \param[in] ControlRequest Set to true if the report should be requested by a control request, false otherwise - * \param[in,out] ReportID Report ID of the received report if ControlRequest is false, set by the to the Report ID - * to fetch if ControlRequest is true * \param[in] Buffer Buffer to store the received report into * - * \return An error code from the \ref USB_Host_SendControlErrorCodes_t enum if the ControlRequest flag is set, - * a value from the \ref Pipe_Stream_RW_ErrorCodes_t enum otherwise + * \return An error code from the \ref Pipe_Stream_RW_ErrorCodes_t enum */ - uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, const bool ControlRequest, uint8_t* ReportID, - void* Buffer) ATTR_NON_NULL_PTR_ARG(1, 3); + uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, void* Buffer) ATTR_NON_NULL_PTR_ARG(1, 2); + + /** Received a HID IN report from the attached device, by the report ID. + * + * \param[in,out] HIDInterfaceInfo Pointer to a structure containing a HID Class host configuration and state + * \param[in] ReportID Report ID of the received report if ControlRequest is false, set by the to the Report ID to fetch + * \param[in] Buffer Buffer to store the received report into + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum + */ + uint8_t HID_Host_ReceiveReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, const uint8_t ReportID, + void* Buffer) ATTR_NON_NULL_PTR_ARG(1, 3); /** Sends an OUT report to the currently attached HID device, using the device's OUT pipe if available or the device's * Control pipe if not. @@ -172,8 +177,8 @@ * \return An error code from the \ref USB_Host_SendControlErrorCodes_t enum if the DeviceUsesOUTPipe flag is set in * the interface's state structure, a value from the \ref Pipe_Stream_RW_ErrorCodes_t enum otherwise */ - uint8_t HID_Host_SendReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, const uint8_t ReportID, - void* Buffer, const uint16_t ReportSize) ATTR_NON_NULL_PTR_ARG(1, 3); + uint8_t HID_Host_SendReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, const uint8_t ReportID, + void* Buffer, const uint16_t ReportSize) ATTR_NON_NULL_PTR_ARG(1, 3); /** Determines if a HID IN report has been received from the attached device on the data IN pipe. * diff --git a/LUFA/Drivers/USB/Class/Host/HIDParser.h b/LUFA/Drivers/USB/Class/Host/HIDParser.h index a2830dd30..f2cd35b88 100644 --- a/LUFA/Drivers/USB/Class/Host/HIDParser.h +++ b/LUFA/Drivers/USB/Class/Host/HIDParser.h @@ -120,7 +120,7 @@ * makefile, and passing the define to the compiler using the -D compiler switch. Note that IN, OUT and FEATURE * items sharing the same report ID consume only one size item in the array. */ - #define HID_MAX_REPORT_IDS 5 + #define HID_MAX_REPORT_IDS 10 #endif /* Public Interface - May be used in end-application: */ @@ -279,7 +279,7 @@ * \return Size of the report in bytes, or 0 if the report does not exist */ uint16_t USB_GetHIDReportSize(HID_ReportInfo_t* const ParserData, const uint8_t ReportID, - const uint8_t ReportType) ATTR_NON_NULL_PTR_ARG(1); + const uint8_t ReportType) ATTR_NON_NULL_PTR_ARG(1) ATTR_CONST; /** Callback routine for the HID Report Parser. This callback must 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 diff --git a/LUFA/ManPages/LibraryApps.txt b/LUFA/ManPages/LibraryApps.txt index 49c745890..253802b1f 100644 --- a/LUFA/ManPages/LibraryApps.txt +++ b/LUFA/ManPages/LibraryApps.txt @@ -65,7 +65,6 @@ * - Host * - ClassDriver * - CDCHost - Virtual Serial Port host demo, using the library USB CDC Class driver framework - * - GenericHIDHost - Generic HID host demo, using the library USB HID Class driver framework * - KeyboardHost - USB Keyboard host demo, using the library USB HID Class driver framework * - KeyboardHostWithParser - USB Keyboard host demo with HID Descriptor parser, using the library USB HID Class * driver framework -- cgit v1.2.3