From dac7b046fd5d5c5332ca82cd538dd2c50f9128fd Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 31 Aug 2009 13:58:03 +0000 Subject: Add return codes to the CDC Host Class driver String/Byte transmission functions. --- LUFA/Drivers/USB/Class/Host/CDC.c | 16 ++++++++++++---- LUFA/Drivers/USB/Class/Host/CDC.h | 8 ++++++-- LUFA/Drivers/USB/Class/Host/HIDParser.c | 3 ++- LUFA/Drivers/USB/Class/Host/HIDParser.h | 6 +++--- 4 files changed, 23 insertions(+), 10 deletions(-) (limited to 'LUFA/Drivers/USB/Class/Host') diff --git a/LUFA/Drivers/USB/Class/Host/CDC.c b/LUFA/Drivers/USB/Class/Host/CDC.c index e75bee2d0..cb70808a1 100644 --- a/LUFA/Drivers/USB/Class/Host/CDC.c +++ b/LUFA/Drivers/USB/Class/Host/CDC.c @@ -256,21 +256,27 @@ uint8_t CDC_Host_SendControlLineStateChange(USB_ClassInfo_CDC_Host_t* CDCInterfa return USB_Host_SendControlRequest(NULL); } -void CDC_Host_SendString(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, char* Data, uint16_t Length) +uint8_t CDC_Host_SendString(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, char* Data, uint16_t Length) { if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.Active)) return; + uint8_t ErrorCode; + Pipe_SelectPipe(CDCInterfaceInfo->Config.DataOUTPipeNumber); Pipe_Unfreeze(); - Pipe_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK); + ErrorCode = Pipe_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK); Pipe_Freeze(); + + return ErrorCode; } -void CDC_Host_SendByte(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint8_t Data) +uint8_t CDC_Host_SendByte(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint8_t Data) { if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.Active)) return; + + uint8_t ErrorCode = PIPE_READYWAIT_NoError; Pipe_SelectPipe(CDCInterfaceInfo->Config.DataOUTPipeNumber); Pipe_Unfreeze(); @@ -278,11 +284,13 @@ void CDC_Host_SendByte(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint8_t Data) if (!(Pipe_IsReadWriteAllowed())) { Pipe_ClearOUT(); - Pipe_WaitUntilReady(); + ErrorCode = Pipe_WaitUntilReady(); } Pipe_Write_Byte(Data); Pipe_Freeze(); + + return ErrorCode; } uint16_t CDC_Host_BytesReceived(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo) diff --git a/LUFA/Drivers/USB/Class/Host/CDC.h b/LUFA/Drivers/USB/Class/Host/CDC.h index f7dc08839..99fbdbbd3 100644 --- a/LUFA/Drivers/USB/Class/Host/CDC.h +++ b/LUFA/Drivers/USB/Class/Host/CDC.h @@ -163,16 +163,20 @@ * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class host configuration and state * \param[in] Data Pointer to the string to send to the device * \param[in] Length Size in bytes of the string to send to the device + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum */ - void CDC_Host_SendString(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, char* Data, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1, 2); + uint8_t CDC_Host_SendString(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, char* Data, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1, 2); /** Sends a given byte to the attached USB device, if connected. If a host is not connected when the function is called, the * byte is discarded. * * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class host configuration and state * \param[in] Data Byte of data to send to the device + * + * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum */ - void CDC_Host_SendByte(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint8_t Data) ATTR_NON_NULL_PTR_ARG(1); + uint8_t CDC_Host_SendByte(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint8_t Data) ATTR_NON_NULL_PTR_ARG(1); /** Determines the number of bytes received by the CDC interface from the device, waiting to be read. * diff --git a/LUFA/Drivers/USB/Class/Host/HIDParser.c b/LUFA/Drivers/USB/Class/Host/HIDParser.c index fdce8e577..3fbad6508 100644 --- a/LUFA/Drivers/USB/Class/Host/HIDParser.c +++ b/LUFA/Drivers/USB/Class/Host/HIDParser.c @@ -51,9 +51,10 @@ uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID while (ReportSize) { - uint8_t HIDReportItem = *(ReportData++); + uint8_t HIDReportItem = *ReportData; uint32_t ReportItemData = 0; + ReportData++; ReportSize--; switch (HIDReportItem & DATA_SIZE_MASK) diff --git a/LUFA/Drivers/USB/Class/Host/HIDParser.h b/LUFA/Drivers/USB/Class/Host/HIDParser.h index 942fe1177..ec7ff53be 100644 --- a/LUFA/Drivers/USB/Class/Host/HIDParser.h +++ b/LUFA/Drivers/USB/Class/Host/HIDParser.h @@ -79,11 +79,11 @@ #if !defined(HID_STATETABLE_STACK_DEPTH) || defined(__DOXYGEN__) /** Constant indicating the maximum stack depth of the state table. A larger state table * allows for more PUSH/POP report items to be nested, but consumes more memory. By default - * this is set to 3 levels (allowing for two PUSHes to be nested) but this can be overridden by + * this is set to 2 levels (allowing non-nested PUSH items) but this can be overridden by * defining HID_STATETABLE_STACK_DEPTH to another value in the user project makefile, passing the * define to the compiler using the -D compiler switch. */ - #define HID_STATETABLE_STACK_DEPTH 3 + #define HID_STATETABLE_STACK_DEPTH 2 #endif #if !defined(HID_USAGE_STACK_DEPTH) || defined(__DOXYGEN__) @@ -134,7 +134,7 @@ HID_PARSE_HIDStackOverflow = 1, /**< More than \ref HID_STATETABLE_STACK_DEPTH nested PUSHes in the report. */ HID_PARSE_HIDStackUnderflow = 2, /**< A POP was found when the state table stack was empty. */ HID_PARSE_InsufficientReportItems = 3, /**< More than \ref HID_MAX_REPORTITEMS report items in the report. */ - HID_PARSE_UnexpectedEndCollection = 4, /**< END COLLECTION found without matching COLLECTION item. */ + HID_PARSE_UnexpectedEndCollection = 4, /**< An END COLLECTION item found without matching COLLECTION item. */ HID_PARSE_InsufficientCollectionPaths = 5, /**< More than \ref HID_MAX_COLLECTIONS collections in the report. */ HID_PARSE_UsageStackOverflow = 6, /**< More than \ref HID_USAGE_STACK_DEPTH usages listed in a row. */ }; -- cgit v1.2.3