From 88a3d6b20d4a17016a934bef154fc5352c44e42b Mon Sep 17 00:00:00 2001 From: mbanth Date: Wed, 24 Nov 2021 16:06:17 +0000 Subject: [PATCH 01/58] Initial commit made to keep a safe copy. Builds but will not run and definitely very incomplete. --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 6 +-- lib_xua/src/core/user/hid/user_hid.h | 53 +++++++++++++++++---- lib_xua/src/hid/hid_report_descriptor.c | 20 +++++--- lib_xua/src/hid/xua_hid_report_descriptor.h | 47 ++++++++++++++---- 4 files changed, 101 insertions(+), 25 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index eb6b373a..2802ff15 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -373,7 +373,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #if( 0 < HID_CONTROLS ) { - int hidDataLength = hidGetReportLength(); + int hidDataLength = hidGetReportLength(0); // TODO Replace argument with HID Report ID XUD_SetReady_In(ep_hid, g_hidData, hidDataLength); } #endif @@ -889,8 +889,8 @@ void XUA_Buffer_Ep(register chanend c_aud_out, /* HID Report Data */ case XUD_SetData_Select(c_hid, ep_hid, result): { - int hidDataLength = hidGetReportLength(); - UserHIDGetData(g_hidData); + int hidDataLength = hidGetReportLength(0); // TODO Replace argument with HID Report ID + UserHIDGetData(0, g_hidData); // TODO Replace 1st argument with HID Report ID XUD_SetReady_In(ep_hid, g_hidData, hidDataLength); } break; diff --git a/lib_xua/src/core/user/hid/user_hid.h b/lib_xua/src/core/user/hid/user_hid.h index 3fcb52ee..6010af85 100644 --- a/lib_xua/src/core/user/hid/user_hid.h +++ b/lib_xua/src/core/user/hid/user_hid.h @@ -1,19 +1,31 @@ // Copyright 2013-2021 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. +/** + * @brief Human Interface Device (HID) API + * + * This file defines the Application Programming Interface (API) used to record HID + * events and retrieve a HID Report for sending to a host. + * The using application has the responsibility to fulfill this API. + * Document section numbers refer to the HID Device Class Definition, version 1.11. + */ + #ifndef __USER_HID_H__ #define __USER_HID_H__ /** * \brief HID event * - * This struct identifies the location within the HID Report for an event and - * The value to report for that location. + * This struct identifies: + * - the HID Report that reports an event, + * - the location within the HID Report for the event, and + * - the value to report for that location (typically interpreted as a Boolean). * It assumes only single bit flags within the HID Report. */ typedef struct hidEvent_t { unsigned bit; unsigned byte; + unsigned id; unsigned value; } hidEvent_t; @@ -22,15 +34,27 @@ typedef struct hidEvent_t { #if( 0 < HID_CONTROLS ) /** - * \brief Get the data for the next HID report + * \brief Get the data for the next HID Report * * \note This function returns the HID data as a list of unsigned char because the * \c XUD_SetReady_In() accepts data for transmission to the USB Host using * this type. * - * \param{out} hidData The HID data + * \param[in] id The HID Report ID (see 5.6, 6.2.2.7, 8.1 and 8.2) + * \param[out] hidData The HID data */ -void UserHIDGetData( unsigned char hidData[ HID_MAX_DATA_BYTES ]); +void UserHIDGetData( const unsigned id, unsigned char hidData[ HID_MAX_DATA_BYTES ]); + +/** + * \brief Get the upper limit of HID Report identifiers + * + * This function returns the upper limit of the HID Report identifiers. + * The upper limit has a value one greater than the maximum HID Report identifier. + * In the case that HID Report identifiers are not in use, this function returns the value 1. + * + * \returns The upper limit of HID Report identifiers + */ +unsigned UserHIDGetReportIdLimit ( void ); /** * \brief Initialize HID processing @@ -40,9 +64,10 @@ void UserHIDInit( void ); /** * \brief Record that a HID event has occurred * - * \param{in} hidEvent A list of events which have occurred. - * Each element specifies a bit and byte in the HID Report and the value for it. - * \param{in} hidEventCnt The length of the \a hidEvent list. + * \param[in] hidEvent A list of events which have occurred. + * Each element specifies a HID Report ID, a bit and byte + * within the HID Report and the value for it. + * \param[in] hidEventCnt The length of the \a hidEvent list. * * \returns A Boolean flag indicating the status of the operation * \retval False No recording of the event(s) occurred @@ -50,5 +75,17 @@ void UserHIDInit( void ); */ unsigned UserHIDRecordEvent( const hidEvent_t hidEvent[], const unsigned hidEventCnt ); +/** + * \brief Indicate if a HID Report ID has new data to report + * + * \param[in] id A HID Report ID (see 5.6, 6.2.2.7, 8.1 and 8.2) + * + * \returns A Boolean flag indicating the status of the operation + * \retval False The given \a id either does not have new data to report or lies + * outside the range of supported HID Report identifiers + * \retval True The given \a id has new data to report to the USB Host + */ +unsigned UserHIDReportChanged( const unsigned id ); + #endif /* ( 0 < HID_CONTROLS ) */ #endif /* __USER_HID_H__ */ diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 1b899aaf..a9b6088e 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -77,11 +77,11 @@ static unsigned hidGetItemType( const unsigned char header ); * * Parameters: * - * @param[in] byte The byte location in the HID Report + * @param[in] id The HID Report ID for the Usage Page * - * @return The USB HID Usage Page code or zero if the \a byte parameter is out-of-range + * @return The USB HID Usage Page code or zero if the \a id parameter is out-of-range */ -static unsigned hidGetUsagePage( const unsigned byte ); +static unsigned hidGetUsagePage( const unsigned id ); /** * @brief Translate an Item from the \c USB_HID_Short_Item format to raw bytes @@ -147,6 +147,7 @@ size_t hidGetReportDescriptorLength( void ) #define HID_CONFIGURABLE_ITEM_COUNT ( sizeof hidConfigurableItems / sizeof ( USB_HID_Short_Item_t* )) unsigned hidGetReportItem( + const unsigned id, const unsigned byte, const unsigned bit, unsigned char* const page, @@ -175,15 +176,21 @@ unsigned hidGetReportItem( return retVal; } -size_t hidGetReportLength( void ) +size_t hidGetReportLength( const unsigned id ) { size_t retVal = ( hidReportDescriptorPrepared ) ? HID_REPORT_LENGTH : 0; return retVal; } -static unsigned hidGetUsagePage( const unsigned byte ) +static unsigned hidGetUsagePage( const unsigned id ) { - unsigned retVal = ( byte < HID_REPORT_LENGTH ) ? hidUsagePages[ byte ]->data[ 0 ] : 0; + unsigned retVal = 0U; + for( unsigned idx = 0; idx < 1; ++idx) { // TODO Fix the upper limit! + if( id == hidUsagePages[ idx ]->id ) { + retVal = hidUsagePages[ idx ]->data[ 0 ]; + break; + } + } return retVal; } @@ -206,6 +213,7 @@ void hidResetReportDescriptor( void ) } unsigned hidSetReportItem( + const unsigned id, const unsigned byte, const unsigned bit, const unsigned char page, diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index dc8878ae..00128407 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -40,9 +40,10 @@ #define HID_STATUS_GOOD ( 0 ) #define HID_STATUS_BAD_HEADER ( 1 ) -#define HID_STATUS_BAD_LOCATION ( 2 ) -#define HID_STATUS_BAD_PAGE ( 3 ) -#define HID_STATUS_IN_USE ( 4 ) +#define HID_STATUS_BAD_ID ( 2 ) +#define HID_STATUS_BAD_LOCATION ( 3 ) +#define HID_STATUS_BAD_PAGE ( 4 ) +#define HID_STATUS_IN_USE ( 5 ) /** * @brief USB HID Report Descriptor. Short Item @@ -57,6 +58,8 @@ * Format (bit range): bSize (0:1), bType (2:3), bTag (4:7) * data - a two byte array for holding the item's data * The bSize field indicates which data bytes are in use + * id - a non-standard extension identifying the HID Report ID associated with + * the item (see 5.6, 6.2.2.7, 8.1 and 8.2) * location - a non-standard extension locating the item within the HID Report * Format (bit range): iByte (0:3), iBit (4:6), Reserved (7) */ @@ -64,6 +67,7 @@ typedef struct { unsigned char header; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; + unsigned char id; unsigned char location; } USB_HID_Short_Item_t; @@ -100,6 +104,7 @@ size_t hidGetReportDescriptorLength( void ); * * Parameters: * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) * @param[in] byte The byte position of the control within the HID Report * @param[in] bit The bit position of the control within the \a byte * @param[out] page The USB HID Usage Page code for the Item (see 5.5) @@ -108,13 +113,26 @@ size_t hidGetReportDescriptorLength( void ); * * @return A status value * @retval \c HID_STATUS_GOOD Item successfully returned + * @retval \c HID_STATUS_BAD_ID The \a id argument specifies a non-existant HID Report * @retval \c HID_STATUS_BAD_LOCATION The \a bit or \a byte arguments specify a location outside * of the HID Report */ #if defined(__XC__) -unsigned hidGetReportItem( const unsigned byte, const unsigned bit, unsigned char* unsafe const page, unsigned char* unsafe const header, unsigned char* unsafe const data); +unsigned hidGetReportItem( + const unsigned id, + const unsigned byte, + const unsigned bit, + unsigned char* unsafe const page, + unsigned char* unsafe const header, + unsigned char* unsafe const data); #else -unsigned hidGetReportItem( const unsigned byte, const unsigned bit, unsigned char* const page, unsigned char* const header, unsigned char data[]); +unsigned hidGetReportItem( + const unsigned id, + const unsigned byte, + const unsigned bit, + unsigned char* const page, + unsigned char* const header, + unsigned char data[]); #endif /** @@ -122,11 +140,16 @@ unsigned hidGetReportItem( const unsigned byte, const unsigned bit, unsigned cha * * This function returns the length of the USB HID Report. * It returns zero if the Report descriptor has not been prepared, - * i.e., no one has called \c hidPrepareReportDescriptor(). + * i.e., no one has called \c hidPrepareReportDescriptor(), + * or if the \a id argument specifies a non-existent HID Report + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) * * @return The length of the Report in bytes */ -size_t hidGetReportLength( void ); +size_t hidGetReportLength( const unsigned id ); /** * @brief Prepare the USB HID Report descriptor @@ -154,6 +177,7 @@ void hidResetReportDescriptor( void ); * * Parameters: * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) * @param[in] byte The byte position of the control within the HID Report * @param[in] bit The bit position of the control within the \a byte * @param[in] page The USB HID Usage Page code for the Item (see 5.5) @@ -164,12 +188,19 @@ void hidResetReportDescriptor( void ); * @retval \c HID_STATUS_GOOD Item successfully updated * @retval \c HID_STATUS_BAD_HEADER The Item header specified a data size greater than 2 or * a Tag or Type inconsistent with a Usage Item + * @retval \c HID_STATUS_BAD_ID The \a id argument specifies a non-existent HID Report * @retval \c HID_STATUS_BAD_LOCATION The \a bit or \a byte arguments specify a location outside * of the HID Report * @retval \c HID_STATUS_BAD_PAGE The \a byte argument specifies a location for controls from * a Usage Page other than the one given by the \a page parameter * @retval \c HID_STATUS_IN_USE The Report descriptor is in use */ -unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsigned char page, const unsigned char header, const unsigned char data[]); +unsigned hidSetReportItem( + const unsigned id, + const unsigned byte, + const unsigned bit, + const unsigned char page, + const unsigned char header, + const unsigned char data[]); #endif // _HID_REPORT_DESCRIPTOR_ From 1fe4fc67714cdc5a3a550343a7e007f5513fd1b3 Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 25 Nov 2021 17:30:30 +0000 Subject: [PATCH 02/58] Safety commit. Builds but not run. --- lib_xua/src/hid/hid_report_descriptor.c | 79 +++++++++++++-------- lib_xua/src/hid/xua_hid_report_descriptor.h | 60 ++++++++++------ 2 files changed, 86 insertions(+), 53 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index a9b6088e..8edffadf 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -18,26 +18,37 @@ static size_t hidReportDescriptorLength = 0; static unsigned hidReportDescriptorPrepared = 0; /** - * @brief Get the bit position from the location of an Item + * @brief Get the bit position from the location of a report element * * Parameters: * - * @param[in] location The \c location field from a \c USB_HID_Short_Item + * @param[in] location The \c location field from a \c USB_HID_Report_Element_t * - * @return The bit position of the Item + * @return The bit position of the report element */ -static unsigned hidGetItemBitLocation( const unsigned char header ); +static unsigned hidGetElementBitLocation( const unsigned short location ); /** - * @brief Get the byte position from the location of an Item + * @brief Get the byte position from the location of a report element * * Parameters: * - * @param[in] location The \c location field from a \c USB_HID_Short_Item + * @param[in] location The \c location field from a \c USB_HID_Report_Element_t * - * @return The byte position of the Item within the HID Report + * @return The byte position of the report element within the HID report */ -static unsigned hidGetItemByteLocation( const unsigned char header ); +static unsigned hidGetElementByteLocation( const unsigned short location ); + +/** + * @brief Get the report identifier from the location of a report element + * + * Parameters: + * + * @param[in] location The \c location field from a \c USB_HID_Report_Element_t + * + * @return The report id of the report element within the HID report + */ +static unsigned hidGetElementReportId( const unsigned short location ); /** * @brief Get the number of data bytes from the header of an Item @@ -98,18 +109,24 @@ static unsigned hidGetUsagePage( const unsigned id ); static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr ); -static unsigned hidGetItemBitLocation( const unsigned char location ) +static unsigned hidGetElementBitLocation( const unsigned short location ) { - unsigned bBit = ( location & HID_REPORT_ITEM_LOC_BIT_MASK ) >> HID_REPORT_ITEM_LOC_BIT_SHIFT; + unsigned bBit = ( location & HID_REPORT_ELEMENT_LOC_BIT_MASK ) >> HID_REPORT_ELEMENT_LOC_BIT_SHIFT; return bBit; } -static unsigned hidGetItemByteLocation( const unsigned char location ) +static unsigned hidGetElementByteLocation( const unsigned short location ) { - unsigned bByte = ( location & HID_REPORT_ITEM_LOC_BYTE_MASK ) >> HID_REPORT_ITEM_LOC_BYTE_SHIFT; + unsigned bByte = ( location & HID_REPORT_ELEMENT_LOC_BYTE_MASK ) >> HID_REPORT_ELEMENT_LOC_BYTE_SHIFT; return bByte; } +static unsigned hidGetElementReportId( const unsigned short location ) +{ + unsigned bReportId = ( location & HID_REPORT_ELEMENT_LOC_ID_MASK ) >> HID_REPORT_ELEMENT_LOC_ID_SHIFT; + return bReportId; +} + static unsigned hidGetItemSize( const unsigned char header ) { unsigned bSize = ( header & HID_REPORT_ITEM_HDR_SIZE_MASK ) >> HID_REPORT_ITEM_HDR_SIZE_SHIFT; @@ -145,7 +162,7 @@ size_t hidGetReportDescriptorLength( void ) return retVal; } -#define HID_CONFIGURABLE_ITEM_COUNT ( sizeof hidConfigurableItems / sizeof ( USB_HID_Short_Item_t* )) +#define HID_CONFIGURABLE_ELEMENT_COUNT ( sizeof hidConfigurableElements / sizeof ( USB_HID_Report_Element_t* )) unsigned hidGetReportItem( const unsigned id, const unsigned byte, @@ -156,17 +173,17 @@ unsigned hidGetReportItem( ) { unsigned retVal = HID_STATUS_BAD_LOCATION; - for( unsigned itemIdx = 0; itemIdx < HID_CONFIGURABLE_ITEM_COUNT; ++itemIdx ) { - USB_HID_Short_Item_t item = *hidConfigurableItems[ itemIdx ]; - unsigned bBit = hidGetItemBitLocation( item.location ); - unsigned bByte = hidGetItemByteLocation( item.location ); + for( unsigned elementIdx = 0; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { + USB_HID_Report_Element_t element = *hidConfigurableElements[ elementIdx ]; + unsigned bBit = hidGetElementBitLocation( element.location ); + unsigned bByte = hidGetElementByteLocation( element.location ); - if(( bit == bBit ) && ( byte == bByte )) { + if(( bit == bBit ) && ( byte == bByte )) { // TODO Add check for Report ID *page = hidGetUsagePage( byte ); - *header = item.header; + *header = element.item.header; for( unsigned dataIdx = 0; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++data, ++dataIdx ) { - *data = item.data[ dataIdx ]; + *data = element.item.data[ dataIdx ]; } retVal = HID_STATUS_GOOD; @@ -186,8 +203,8 @@ static unsigned hidGetUsagePage( const unsigned id ) { unsigned retVal = 0U; for( unsigned idx = 0; idx < 1; ++idx) { // TODO Fix the upper limit! - if( id == hidUsagePages[ idx ]->id ) { - retVal = hidUsagePages[ idx ]->data[ 0 ]; + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + retVal = hidReports[ idx ]->item.data[ 0 ]; break; } } @@ -234,26 +251,26 @@ unsigned hidSetReportItem( ( HID_REPORT_ITEM_USAGE_TYPE != bType )) { retVal = HID_STATUS_BAD_HEADER; } else { - for( unsigned itemIdx = 0; itemIdx < HID_CONFIGURABLE_ITEM_COUNT; ++itemIdx ) { - USB_HID_Short_Item_t item = *hidConfigurableItems[ itemIdx ]; - unsigned bBit = hidGetItemBitLocation( item.location ); - unsigned bByte = hidGetItemByteLocation( item.location ); + for( unsigned elementIdx = 0; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { + USB_HID_Report_Element_t element = *hidConfigurableElements[ elementIdx ]; + unsigned bBit = hidGetElementBitLocation( element.location ); + unsigned bByte = hidGetElementByteLocation( element.location ); - if(( bit == bBit ) && ( byte == bByte )) { + if(( bit == bBit ) && ( byte == bByte )) { // TODO Add check for Report ID unsigned pg = hidGetUsagePage( byte ); if( page == pg ) { - item.header = header; + element.item.header = header; for( unsigned dataIdx = 0; dataIdx < bSize; ++dataIdx ) { - item.data[ dataIdx ] = data[ dataIdx ]; + element.item.data[ dataIdx ] = data[ dataIdx ]; } for( unsigned dataIdx = bSize; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++dataIdx ) { - item.data[ dataIdx ] = 0; + element.item.data[ dataIdx ] = 0; } - *hidConfigurableItems[ itemIdx ] = item; + *hidConfigurableElements[ elementIdx ] = element; retVal = HID_STATUS_GOOD; } else { retVal = HID_STATUS_BAD_PAGE; diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index 00128407..8786ebc8 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -18,35 +18,47 @@ #include -#define HID_REPORT_ITEM_HDR_SIZE_MASK ( 0x03 ) -#define HID_REPORT_ITEM_HDR_SIZE_SHIFT ( 0 ) +#define HID_REPORT_ITEM_HDR_SIZE_MASK ( 0x03 ) +#define HID_REPORT_ITEM_HDR_SIZE_SHIFT ( 0 ) -#define HID_REPORT_ITEM_HDR_TAG_MASK ( 0xF0 ) -#define HID_REPORT_ITEM_HDR_TAG_SHIFT ( 4 ) +#define HID_REPORT_ITEM_HDR_TAG_MASK ( 0xF0 ) +#define HID_REPORT_ITEM_HDR_TAG_SHIFT ( 4 ) -#define HID_REPORT_ITEM_HDR_TYPE_MASK ( 0x0C ) -#define HID_REPORT_ITEM_HDR_TYPE_SHIFT ( 2 ) +#define HID_REPORT_ITEM_HDR_TYPE_MASK ( 0x0C ) +#define HID_REPORT_ITEM_HDR_TYPE_SHIFT ( 2 ) -#define HID_REPORT_ITEM_LOC_BIT_MASK ( 0x70 ) -#define HID_REPORT_ITEM_LOC_BIT_SHIFT ( 4 ) +#define HID_REPORT_ELEMENT_LOC_BIT_MASK ( 0x0070 ) +#define HID_REPORT_ELEMENT_LOC_BIT_SHIFT ( 4 ) -#define HID_REPORT_ITEM_LOC_BYTE_MASK ( 0x0F ) -#define HID_REPORT_ITEM_LOC_BYTE_SHIFT ( 0 ) +#define HID_REPORT_ELEMENT_LOC_BYTE_MASK ( 0x000F ) +#define HID_REPORT_ELEMENT_LOC_BYTE_SHIFT ( 0 ) -#define HID_REPORT_ITEM_MAX_SIZE ( 2 ) +#define HID_REPORT_ELEMENT_LOC_ID_MASK ( 0xF000 ) +#define HID_REPORT_ELEMENT_LOC_ID_SHIFT ( 12 ) -#define HID_REPORT_ITEM_USAGE_TAG ( 0 ) -#define HID_REPORT_ITEM_USAGE_TYPE ( 2 ) +#define HID_REPORT_ELEMENT_LOC_LEN_MASK ( 0x0F00 ) +#define HID_REPORT_ELEMENT_LOC_LEN_SHIFT ( 8 ) -#define HID_STATUS_GOOD ( 0 ) -#define HID_STATUS_BAD_HEADER ( 1 ) -#define HID_STATUS_BAD_ID ( 2 ) -#define HID_STATUS_BAD_LOCATION ( 3 ) -#define HID_STATUS_BAD_PAGE ( 4 ) -#define HID_STATUS_IN_USE ( 5 ) +#define HID_REPORT_ITEM_MAX_SIZE ( 2 ) + +#define HID_REPORT_ITEM_USAGE_TAG ( 0 ) +#define HID_REPORT_ITEM_USAGE_TYPE ( 2 ) + +#define HID_REPORT_SET_LOC(id, len, byte, bit) (\ + (( id << HID_REPORT_ELEMENT_LOC_ID_SHIFT ) & HID_REPORT_ELEMENT_LOC_ID_MASK ) | \ + (( len << HID_REPORT_ELEMENT_LOC_LEN_SHIFT ) & HID_REPORT_ELEMENT_LOC_LEN_MASK ) | \ + (( byte << HID_REPORT_ELEMENT_LOC_BYTE_SHIFT ) & HID_REPORT_ELEMENT_LOC_BYTE_MASK ) | \ + (( bit << HID_REPORT_ELEMENT_LOC_BIT_SHIFT ) & HID_REPORT_ELEMENT_LOC_BIT_MASK )) + +#define HID_STATUS_GOOD ( 0 ) +#define HID_STATUS_BAD_HEADER ( 1 ) +#define HID_STATUS_BAD_ID ( 2 ) +#define HID_STATUS_BAD_LOCATION ( 3 ) +#define HID_STATUS_BAD_PAGE ( 4 ) +#define HID_STATUS_IN_USE ( 5 ) /** - * @brief USB HID Report Descriptor. Short Item + * @brief USB HID Report Descriptor Short Item * * @note * To reduce memory use, this type does not support Short Items with 4 data bytes. @@ -67,10 +79,14 @@ typedef struct { unsigned char header; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; - unsigned char id; - unsigned char location; } USB_HID_Short_Item_t; +typedef struct +{ + USB_HID_Short_Item_t item; + unsigned short location; +} USB_HID_Report_Element_t; + /** * @brief Get the HID Report descriptor * From 145c0cb80f59a17630a3189432ab803e38198b19 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 26 Nov 2021 10:46:03 +0000 Subject: [PATCH 03/58] Set constant values explicitly to unsigned --- lib_xua/src/hid/xua_hid_report_descriptor.h | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index 8786ebc8..fedbba65 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -19,30 +19,30 @@ #include #define HID_REPORT_ITEM_HDR_SIZE_MASK ( 0x03 ) -#define HID_REPORT_ITEM_HDR_SIZE_SHIFT ( 0 ) +#define HID_REPORT_ITEM_HDR_SIZE_SHIFT ( 0U ) #define HID_REPORT_ITEM_HDR_TAG_MASK ( 0xF0 ) -#define HID_REPORT_ITEM_HDR_TAG_SHIFT ( 4 ) +#define HID_REPORT_ITEM_HDR_TAG_SHIFT ( 4U ) #define HID_REPORT_ITEM_HDR_TYPE_MASK ( 0x0C ) -#define HID_REPORT_ITEM_HDR_TYPE_SHIFT ( 2 ) +#define HID_REPORT_ITEM_HDR_TYPE_SHIFT ( 2U ) #define HID_REPORT_ELEMENT_LOC_BIT_MASK ( 0x0070 ) -#define HID_REPORT_ELEMENT_LOC_BIT_SHIFT ( 4 ) +#define HID_REPORT_ELEMENT_LOC_BIT_SHIFT ( 4U ) #define HID_REPORT_ELEMENT_LOC_BYTE_MASK ( 0x000F ) -#define HID_REPORT_ELEMENT_LOC_BYTE_SHIFT ( 0 ) +#define HID_REPORT_ELEMENT_LOC_BYTE_SHIFT ( 0U ) #define HID_REPORT_ELEMENT_LOC_ID_MASK ( 0xF000 ) -#define HID_REPORT_ELEMENT_LOC_ID_SHIFT ( 12 ) +#define HID_REPORT_ELEMENT_LOC_ID_SHIFT ( 12U ) #define HID_REPORT_ELEMENT_LOC_LEN_MASK ( 0x0F00 ) -#define HID_REPORT_ELEMENT_LOC_LEN_SHIFT ( 8 ) +#define HID_REPORT_ELEMENT_LOC_LEN_SHIFT ( 8U ) -#define HID_REPORT_ITEM_MAX_SIZE ( 2 ) +#define HID_REPORT_ITEM_MAX_SIZE ( 2U ) -#define HID_REPORT_ITEM_USAGE_TAG ( 0 ) -#define HID_REPORT_ITEM_USAGE_TYPE ( 2 ) +#define HID_REPORT_ITEM_USAGE_TAG ( 0U ) +#define HID_REPORT_ITEM_USAGE_TYPE ( 2U ) #define HID_REPORT_SET_LOC(id, len, byte, bit) (\ (( id << HID_REPORT_ELEMENT_LOC_ID_SHIFT ) & HID_REPORT_ELEMENT_LOC_ID_MASK ) | \ @@ -50,12 +50,12 @@ (( byte << HID_REPORT_ELEMENT_LOC_BYTE_SHIFT ) & HID_REPORT_ELEMENT_LOC_BYTE_MASK ) | \ (( bit << HID_REPORT_ELEMENT_LOC_BIT_SHIFT ) & HID_REPORT_ELEMENT_LOC_BIT_MASK )) -#define HID_STATUS_GOOD ( 0 ) -#define HID_STATUS_BAD_HEADER ( 1 ) -#define HID_STATUS_BAD_ID ( 2 ) -#define HID_STATUS_BAD_LOCATION ( 3 ) -#define HID_STATUS_BAD_PAGE ( 4 ) -#define HID_STATUS_IN_USE ( 5 ) +#define HID_STATUS_GOOD ( 0U ) +#define HID_STATUS_BAD_HEADER ( 1U ) +#define HID_STATUS_BAD_ID ( 2U ) +#define HID_STATUS_BAD_LOCATION ( 3U ) +#define HID_STATUS_BAD_PAGE ( 4U ) +#define HID_STATUS_IN_USE ( 5U ) /** * @brief USB HID Report Descriptor Short Item From 1857ddbc67667a7cb9287c30cc7c9ceca4eed2f0 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 26 Nov 2021 10:50:53 +0000 Subject: [PATCH 04/58] Set constant values explicitly to unsigned. Add access function for HID Report length. Update hidGetReportItem() and hidSetReportItem() to check for correct Reporty ID. Update hidGetReportLength() to report the length of the given HID Report. Update hidGetUsagePage() to iterate across all HID Reports. --- lib_xua/src/hid/hid_report_descriptor.c | 116 +++++++++++++++--------- 1 file changed, 75 insertions(+), 41 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 8edffadf..daad9758 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -14,8 +14,8 @@ ( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE )) static unsigned char hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; -static size_t hidReportDescriptorLength = 0; -static unsigned hidReportDescriptorPrepared = 0; +static size_t hidReportDescriptorLength = 0U; +static unsigned hidReportDescriptorPrepared = 0U; /** * @brief Get the bit position from the location of a report element @@ -50,6 +50,17 @@ static unsigned hidGetElementByteLocation( const unsigned short location ); */ static unsigned hidGetElementReportId( const unsigned short location ); +/** + * @brief Get the report length from the location of a report element + * + * Parameters: + * + * @param[in] location The \c location field from a \c USB_HID_Report_Element_t + * + * @return The length of the HID report + */ +static size_t hidGetElementReportLength( const unsigned short location ); + /** * @brief Get the number of data bytes from the header of an Item * @@ -127,6 +138,12 @@ static unsigned hidGetElementReportId( const unsigned short location ) return bReportId; } +static size_t hidGetElementReportLength( const unsigned short location ) +{ + size_t bReportId = (size_t)( location & HID_REPORT_ELEMENT_LOC_LEN_MASK ) >> HID_REPORT_ELEMENT_LOC_LEN_SHIFT; + return bReportId; +} + static unsigned hidGetItemSize( const unsigned char header ) { unsigned bSize = ( header & HID_REPORT_ITEM_HDR_SIZE_MASK ) >> HID_REPORT_ITEM_HDR_SIZE_SHIFT; @@ -158,7 +175,7 @@ unsigned char* hidGetReportDescriptor( void ) size_t hidGetReportDescriptorLength( void ) { - size_t retVal = ( hidReportDescriptorPrepared ) ? hidReportDescriptorLength : 0; + size_t retVal = ( hidReportDescriptorPrepared ) ? hidReportDescriptorLength : 0U; return retVal; } @@ -172,37 +189,50 @@ unsigned hidGetReportItem( unsigned char data[] ) { - unsigned retVal = HID_STATUS_BAD_LOCATION; - for( unsigned elementIdx = 0; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { + unsigned retVal = HID_STATUS_BAD_ID; + for( unsigned elementIdx = 0U; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { USB_HID_Report_Element_t element = *hidConfigurableElements[ elementIdx ]; - unsigned bBit = hidGetElementBitLocation( element.location ); + unsigned bBit = hidGetElementBitLocation( element.location ); unsigned bByte = hidGetElementByteLocation( element.location ); + unsigned bId = hidGetElementReportId( element.location ); - if(( bit == bBit ) && ( byte == bByte )) { // TODO Add check for Report ID - *page = hidGetUsagePage( byte ); - *header = element.item.header; + if( id == bId ) { + retVal = HID_STATUS_BAD_LOCATION; - for( unsigned dataIdx = 0; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++data, ++dataIdx ) { - *data = element.item.data[ dataIdx ]; + if(( bit == bBit ) && ( byte == bByte )) { + *page = hidGetUsagePage( id ); + *header = element.item.header; + + for( unsigned dataIdx = 0U; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++data, ++dataIdx ) { + *data = element.item.data[ dataIdx ]; + } + + retVal = HID_STATUS_GOOD; + break; } - - retVal = HID_STATUS_GOOD; - break; } } return retVal; } +#define HID_REPORT_COUNT ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) size_t hidGetReportLength( const unsigned id ) { - size_t retVal = ( hidReportDescriptorPrepared ) ? HID_REPORT_LENGTH : 0; + size_t retVal = 0U; + if( hidReportDescriptorPrepared ) { + for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + retVal = hidGetElementReportLength( hidReports[ idx ]->location ); + } + } + } return retVal; } static unsigned hidGetUsagePage( const unsigned id ) { unsigned retVal = 0U; - for( unsigned idx = 0; idx < 1; ++idx) { // TODO Fix the upper limit! + for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx) { if( id == hidGetElementReportId( hidReports[ idx ]->location )) { retVal = hidReports[ idx ]->item.data[ 0 ]; break; @@ -214,19 +244,20 @@ static unsigned hidGetUsagePage( const unsigned id ) void hidPrepareReportDescriptor( void ) { if( !hidReportDescriptorPrepared ) { - hidReportDescriptorLength = 0; + hidReportDescriptorLength = 0U; unsigned char* ptr = hidReportDescriptor; - for( unsigned idx = 0; idx < HID_REPORT_DESCRIPTOR_ITEM_COUNT; ++idx ) { + + for( unsigned idx = 0U; idx < HID_REPORT_DESCRIPTOR_ITEM_COUNT; ++idx ) { hidReportDescriptorLength += hidTranslateItem( hidReportDescriptorItems[ idx ], &ptr ); } - hidReportDescriptorPrepared = 1; + hidReportDescriptorPrepared = 1U; } } void hidResetReportDescriptor( void ) { - hidReportDescriptorPrepared = 0; + hidReportDescriptorPrepared = 0U; } unsigned hidSetReportItem( @@ -241,7 +272,7 @@ unsigned hidSetReportItem( unsigned retVal = HID_STATUS_IN_USE; if( !hidReportDescriptorPrepared ) { - retVal = HID_STATUS_BAD_LOCATION; + retVal = HID_STATUS_BAD_ID; unsigned bSize = hidGetItemSize( header ); unsigned bTag = hidGetItemTag ( header ); unsigned bType = hidGetItemType( header ); @@ -251,32 +282,35 @@ unsigned hidSetReportItem( ( HID_REPORT_ITEM_USAGE_TYPE != bType )) { retVal = HID_STATUS_BAD_HEADER; } else { - for( unsigned elementIdx = 0; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { + for( unsigned elementIdx = 0U; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { USB_HID_Report_Element_t element = *hidConfigurableElements[ elementIdx ]; - unsigned bBit = hidGetElementBitLocation( element.location ); + unsigned bBit = hidGetElementBitLocation( element.location ); unsigned bByte = hidGetElementByteLocation( element.location ); + unsigned bId = hidGetElementReportId( element.location ); - if(( bit == bBit ) && ( byte == bByte )) { // TODO Add check for Report ID - unsigned pg = hidGetUsagePage( byte ); + if( id == bId ) { + retVal = HID_STATUS_BAD_PAGE; + unsigned pg = hidGetUsagePage( id ); if( page == pg ) { - element.item.header = header; + retVal = HID_STATUS_BAD_LOCATION; - for( unsigned dataIdx = 0; dataIdx < bSize; ++dataIdx ) { - element.item.data[ dataIdx ] = data[ dataIdx ]; + if(( bit == bBit ) && ( byte == bByte )) { + element.item.header = header; + + for( unsigned dataIdx = 0U; dataIdx < bSize; ++dataIdx ) { + element.item.data[ dataIdx ] = data[ dataIdx ]; + } + + for( unsigned dataIdx = bSize; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++dataIdx ) { + element.item.data[ dataIdx ] = 0U; + } + + *hidConfigurableElements[ elementIdx ] = element; + retVal = HID_STATUS_GOOD; + break; } - - for( unsigned dataIdx = bSize; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++dataIdx ) { - element.item.data[ dataIdx ] = 0; - } - - *hidConfigurableElements[ elementIdx ] = element; - retVal = HID_STATUS_GOOD; - } else { - retVal = HID_STATUS_BAD_PAGE; } - - break; } } } @@ -287,12 +321,12 @@ unsigned hidSetReportItem( static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr ) { - size_t count = 0; + size_t count = 0U; *(*outPtrPtr)++ = inPtr->header; ++count; unsigned dataLength = hidGetItemSize( inPtr->header ); - for( unsigned idx = 0; idx < dataLength; ++idx ) { + for( unsigned idx = 0U; idx < dataLength; ++idx ) { *(*outPtrPtr)++ = inPtr->data[ idx ]; ++count; } From bf9e150310e2de02161ae572bd881e7798848914 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 26 Nov 2021 13:40:58 +0000 Subject: [PATCH 05/58] Use size_t for each index into an array. --- lib_xua/src/hid/hid_report_descriptor.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index daad9758..7e67e994 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -190,7 +190,7 @@ unsigned hidGetReportItem( ) { unsigned retVal = HID_STATUS_BAD_ID; - for( unsigned elementIdx = 0U; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { + for( size_t elementIdx = 0U; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { USB_HID_Report_Element_t element = *hidConfigurableElements[ elementIdx ]; unsigned bBit = hidGetElementBitLocation( element.location ); unsigned bByte = hidGetElementByteLocation( element.location ); @@ -203,7 +203,7 @@ unsigned hidGetReportItem( *page = hidGetUsagePage( id ); *header = element.item.header; - for( unsigned dataIdx = 0U; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++data, ++dataIdx ) { + for( size_t dataIdx = 0U; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++data, ++dataIdx ) { *data = element.item.data[ dataIdx ]; } @@ -220,7 +220,7 @@ size_t hidGetReportLength( const unsigned id ) { size_t retVal = 0U; if( hidReportDescriptorPrepared ) { - for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { if( id == hidGetElementReportId( hidReports[ idx ]->location )) { retVal = hidGetElementReportLength( hidReports[ idx ]->location ); } @@ -232,7 +232,7 @@ size_t hidGetReportLength( const unsigned id ) static unsigned hidGetUsagePage( const unsigned id ) { unsigned retVal = 0U; - for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { if( id == hidGetElementReportId( hidReports[ idx ]->location )) { retVal = hidReports[ idx ]->item.data[ 0 ]; break; @@ -247,7 +247,7 @@ void hidPrepareReportDescriptor( void ) hidReportDescriptorLength = 0U; unsigned char* ptr = hidReportDescriptor; - for( unsigned idx = 0U; idx < HID_REPORT_DESCRIPTOR_ITEM_COUNT; ++idx ) { + for( size_t idx = 0U; idx < HID_REPORT_DESCRIPTOR_ITEM_COUNT; ++idx ) { hidReportDescriptorLength += hidTranslateItem( hidReportDescriptorItems[ idx ], &ptr ); } @@ -282,7 +282,7 @@ unsigned hidSetReportItem( ( HID_REPORT_ITEM_USAGE_TYPE != bType )) { retVal = HID_STATUS_BAD_HEADER; } else { - for( unsigned elementIdx = 0U; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { + for( size_t elementIdx = 0U; elementIdx < HID_CONFIGURABLE_ELEMENT_COUNT; ++elementIdx ) { USB_HID_Report_Element_t element = *hidConfigurableElements[ elementIdx ]; unsigned bBit = hidGetElementBitLocation( element.location ); unsigned bByte = hidGetElementByteLocation( element.location ); @@ -298,11 +298,11 @@ unsigned hidSetReportItem( if(( bit == bBit ) && ( byte == bByte )) { element.item.header = header; - for( unsigned dataIdx = 0U; dataIdx < bSize; ++dataIdx ) { + for( size_t dataIdx = 0U; dataIdx < bSize; ++dataIdx ) { element.item.data[ dataIdx ] = data[ dataIdx ]; } - for( unsigned dataIdx = bSize; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++dataIdx ) { + for( size_t dataIdx = bSize; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++dataIdx ) { element.item.data[ dataIdx ] = 0U; } @@ -326,7 +326,7 @@ static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char ++count; unsigned dataLength = hidGetItemSize( inPtr->header ); - for( unsigned idx = 0U; idx < dataLength; ++idx ) { + for( size_t idx = 0U; idx < dataLength; ++idx ) { *(*outPtrPtr)++ = inPtr->data[ idx ]; ++count; } From 3b6f1c80e20ea2a1e7a66bcb916882489830b711 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 26 Nov 2021 16:30:47 +0000 Subject: [PATCH 06/58] Move HID_REPORT_COUNT to hid_report_descriptor.h --- lib_xua/src/hid/hid_report_descriptor.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 7e67e994..afbb1d28 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -215,7 +215,6 @@ unsigned hidGetReportItem( return retVal; } -#define HID_REPORT_COUNT ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) size_t hidGetReportLength( const unsigned id ) { size_t retVal = 0U; From 65b1b41ec4514f02b453d68352a61ada13889e09 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 26 Nov 2021 16:32:12 +0000 Subject: [PATCH 07/58] Change the interface to UserHIDGetData() and UserHIDRecordEvent() --- lib_xua/src/core/user/hid/user_hid.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib_xua/src/core/user/hid/user_hid.h b/lib_xua/src/core/user/hid/user_hid.h index 6010af85..ba115ff0 100644 --- a/lib_xua/src/core/user/hid/user_hid.h +++ b/lib_xua/src/core/user/hid/user_hid.h @@ -13,12 +13,14 @@ #ifndef __USER_HID_H__ #define __USER_HID_H__ +#include + /** * \brief HID event * * This struct identifies: - * - the HID Report that reports an event, - * - the location within the HID Report for the event, and + * - the HID Report that reports an event, i.e., the ID, + * - the location within the HID Report for the event, i.e., the byte and bit, and * - the value to report for that location (typically interpreted as a Boolean). * It assumes only single bit flags within the HID Report. */ @@ -41,9 +43,17 @@ typedef struct hidEvent_t { * this type. * * \param[in] id The HID Report ID (see 5.6, 6.2.2.7, 8.1 and 8.2) + * Set to zero if the application provides only one HID Report + * which does not include a Report ID * \param[out] hidData The HID data + * If using Report IDs, this function places the Report ID in + * the first element; otherwise the first element holds the + * first byte of HID event data. + * + * \returns The length of the HID Report in the \a hidData argument + * \retval Zero means no new HID event data has been recorded for the given \a id */ -void UserHIDGetData( const unsigned id, unsigned char hidData[ HID_MAX_DATA_BYTES ]); +size_t UserHIDGetData( const unsigned id, unsigned char hidData[ HID_MAX_DATA_BYTES ]); /** * \brief Get the upper limit of HID Report identifiers @@ -67,13 +77,15 @@ void UserHIDInit( void ); * \param[in] hidEvent A list of events which have occurred. * Each element specifies a HID Report ID, a bit and byte * within the HID Report and the value for it. + * Set the Report ID to zero if not using Report IDs + * (see 5.6, 6.2.2.7, 8.1 and 8.2). * \param[in] hidEventCnt The length of the \a hidEvent list. * - * \returns A Boolean flag indicating the status of the operation - * \retval False No recording of the event(s) occurred - * \retval True Recording of the event(s) occurred + * \returns The index of the first unrecorded event in \a hidEvent + * \retval Zero indicates no events were recorded + * \retval \a hidEventCnt indicates all events were recorded */ -unsigned UserHIDRecordEvent( const hidEvent_t hidEvent[], const unsigned hidEventCnt ); +size_t UserHIDRecordEvent( const hidEvent_t hidEvent[], const size_t hidEventCnt ); /** * \brief Indicate if a HID Report ID has new data to report From 0892ff9a8b0fdbf510f362a3452699ca6b034ac8 Mon Sep 17 00:00:00 2001 From: mbanth Date: Mon, 29 Nov 2021 17:09:26 +0000 Subject: [PATCH 08/58] Move the declaration of the HID Get Report Limit function and provide its definition --- lib_xua/src/core/user/hid/user_hid.h | 11 ----------- lib_xua/src/hid/hid_report_descriptor.c | 4 ++++ lib_xua/src/hid/xua_hid_report_descriptor.h | 11 +++++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib_xua/src/core/user/hid/user_hid.h b/lib_xua/src/core/user/hid/user_hid.h index ba115ff0..af826971 100644 --- a/lib_xua/src/core/user/hid/user_hid.h +++ b/lib_xua/src/core/user/hid/user_hid.h @@ -55,17 +55,6 @@ typedef struct hidEvent_t { */ size_t UserHIDGetData( const unsigned id, unsigned char hidData[ HID_MAX_DATA_BYTES ]); -/** - * \brief Get the upper limit of HID Report identifiers - * - * This function returns the upper limit of the HID Report identifiers. - * The upper limit has a value one greater than the maximum HID Report identifier. - * In the case that HID Report identifiers are not in use, this function returns the value 1. - * - * \returns The upper limit of HID Report identifiers - */ -unsigned UserHIDGetReportIdLimit ( void ); - /** * \brief Initialize HID processing */ diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index afbb1d28..cc5bdd2e 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -179,6 +179,10 @@ size_t hidGetReportDescriptorLength( void ) return retVal; } +unsigned hidGetReportIdLimit ( void ) { + return HID_REPORT_COUNT; +} + #define HID_CONFIGURABLE_ELEMENT_COUNT ( sizeof hidConfigurableElements / sizeof ( USB_HID_Report_Element_t* )) unsigned hidGetReportItem( const unsigned id, diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index fedbba65..5a67e769 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -115,6 +115,17 @@ unsigned char* hidGetReportDescriptor( void ); */ size_t hidGetReportDescriptorLength( void ); +/** + * \brief Get the upper limit of HID Report identifiers + * + * This function returns the upper limit of the HID Report identifiers. + * The upper limit has a value one greater than the maximum HID Report identifier. + * In the case that HID Report identifiers are not in use, this function returns the value 1. + * + * \returns The upper limit of HID Report identifiers + */ +unsigned hidGetReportIdLimit ( void ); + /** * @brief Get a HID Report descriptor item * From dc22b0593f3b5e28bd17f705b9fbd2edca6bc1c6 Mon Sep 17 00:00:00 2001 From: mbanth Date: Tue, 30 Nov 2021 15:04:33 +0000 Subject: [PATCH 09/58] Additional documentation --- lib_xua/src/core/user/hid/user_hid.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_xua/src/core/user/hid/user_hid.h b/lib_xua/src/core/user/hid/user_hid.h index af826971..bde24691 100644 --- a/lib_xua/src/core/user/hid/user_hid.h +++ b/lib_xua/src/core/user/hid/user_hid.h @@ -79,7 +79,8 @@ size_t UserHIDRecordEvent( const hidEvent_t hidEvent[], const size_t hidEventCnt /** * \brief Indicate if a HID Report ID has new data to report * - * \param[in] id A HID Report ID (see 5.6, 6.2.2.7, 8.1 and 8.2) + * \param[in] id A HID Report ID (see 5.6, 6.2.2.7, 8.1 and 8.2). + * A value of zero means the application does not use Report IDs. * * \returns A Boolean flag indicating the status of the operation * \retval False The given \a id either does not have new data to report or lies From 966d8db9a98e0e40bb22948c0587f533a011095f Mon Sep 17 00:00:00 2001 From: mbanth Date: Tue, 30 Nov 2021 15:05:37 +0000 Subject: [PATCH 10/58] Additional documentation and a minor renaming of an automatic variable --- lib_xua/src/hid/hid_report_descriptor.c | 7 ++++--- lib_xua/src/hid/xua_hid_report_descriptor.h | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index cc5bdd2e..399d82c7 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -99,7 +99,8 @@ static unsigned hidGetItemType( const unsigned char header ); * * Parameters: * - * @param[in] id The HID Report ID for the Usage Page + * @param[in] id The HID Report ID for the Usage Page. + * A value of zero means the application does not use Report IDs. * * @return The USB HID Usage Page code or zero if the \a id parameter is out-of-range */ @@ -140,8 +141,8 @@ static unsigned hidGetElementReportId( const unsigned short location ) static size_t hidGetElementReportLength( const unsigned short location ) { - size_t bReportId = (size_t)( location & HID_REPORT_ELEMENT_LOC_LEN_MASK ) >> HID_REPORT_ELEMENT_LOC_LEN_SHIFT; - return bReportId; + size_t bReportLen = (size_t)( location & HID_REPORT_ELEMENT_LOC_LEN_MASK ) >> HID_REPORT_ELEMENT_LOC_LEN_SHIFT; + return bReportLen; } static unsigned hidGetItemSize( const unsigned char header ) diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index 5a67e769..c9312be2 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -131,7 +131,8 @@ unsigned hidGetReportIdLimit ( void ); * * Parameters: * - * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2). + * A value of zero means the application does not use Report IDs. * @param[in] byte The byte position of the control within the HID Report * @param[in] bit The bit position of the control within the \a byte * @param[out] page The USB HID Usage Page code for the Item (see 5.5) @@ -173,6 +174,7 @@ unsigned hidGetReportItem( * Parameters: * * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. * * @return The length of the Report in bytes */ @@ -205,6 +207,7 @@ void hidResetReportDescriptor( void ); * Parameters: * * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. * @param[in] byte The byte position of the control within the HID Report * @param[in] bit The bit position of the control within the \a byte * @param[in] page The USB HID Usage Page code for the Item (see 5.5) From b85358912032eeb825a9aae42d6d9a3fcc701a50 Mon Sep 17 00:00:00 2001 From: mbanth Date: Tue, 30 Nov 2021 18:29:17 +0000 Subject: [PATCH 11/58] Move the HID Clear Pending, Is Pending and Set Pending functions from hid.xc to hid_report_descriptor.c. These functions are called from the application so they do not belong in hid.xc which contains internal XUA functionality. --- lib_xua/src/hid/hid.xc | 24 -------------- lib_xua/src/hid/hid_report_descriptor.c | 18 +++++++++++ lib_xua/src/hid/xua_hid.h | 16 ---------- lib_xua/src/hid/xua_hid_report_descriptor.h | 35 +++++++++++++++++++++ 4 files changed, 53 insertions(+), 40 deletions(-) diff --git a/lib_xua/src/hid/hid.xc b/lib_xua/src/hid/hid.xc index f3c741a1..5761a776 100644 --- a/lib_xua/src/hid/hid.xc +++ b/lib_xua/src/hid/hid.xc @@ -11,17 +11,12 @@ #if( 0 < HID_CONTROLS ) #define MS_IN_TICKS 100000U -static unsigned s_hidChangePending = 0U; static unsigned s_hidCurrentPeriod = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; static unsigned s_hidIdleActive = 0U; static unsigned s_hidIndefiniteDuration = 0U; static unsigned s_hidNextReportTime = 0U; static unsigned s_hidReportTime = 0U; -unsafe { - volatile unsigned * unsafe s_hidChangePendingPtr = &s_hidChangePending; -} - static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod ); static unsigned HidCalcReportToSetIdleInterval( const unsigned reportTime ); static unsigned HidFindSetIdleActivationPoint( const unsigned currentPeriod, const unsigned timeWithinPeriod ); @@ -58,18 +53,6 @@ XUD_Result_t HidInterfaceClassRequests( return result; } -void HidClearChangePending( void ) -{ - unsafe { - *s_hidChangePendingPtr = 0U; - } -} - -unsigned HidIsChangePending( void ) -{ - return( s_hidChangePending != 0 ); -} - unsigned HidIsSetIdleSilenced( void ) { unsigned isSilenced = s_hidIdleActive; @@ -86,13 +69,6 @@ unsigned HidIsSetIdleSilenced( void ) return isSilenced; } -void HidSetChangePending( void ) -{ - unsafe { - *s_hidChangePendingPtr = 1; - } -} - /** * \brief Calculate the timer value for sending the next HID Report. * diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 399d82c7..74517a29 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -13,10 +13,13 @@ #define HID_REPORT_DESCRIPTOR_MAX_LENGTH ( HID_REPORT_DESCRIPTOR_ITEM_COUNT * \ ( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE )) +static unsigned hidChangePending = 0U; static unsigned char hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; static size_t hidReportDescriptorLength = 0U; static unsigned hidReportDescriptorPrepared = 0U; +volatile unsigned* s_hidChangePendingPtr = &hidChangePending; + /** * @brief Get the bit position from the location of a report element * @@ -121,6 +124,11 @@ static unsigned hidGetUsagePage( const unsigned id ); static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr ); +void hidClearChangePending( void ) +{ + s_hidChangePending = 0U; +} + static unsigned hidGetElementBitLocation( const unsigned short location ) { unsigned bBit = ( location & HID_REPORT_ELEMENT_LOC_BIT_MASK ) >> HID_REPORT_ELEMENT_LOC_BIT_SHIFT; @@ -245,6 +253,11 @@ static unsigned hidGetUsagePage( const unsigned id ) return retVal; } +unsigned hidIsChangePending( void ) +{ + return( s_hidChangePending != 0 ); +} + void hidPrepareReportDescriptor( void ) { if( !hidReportDescriptorPrepared ) { @@ -264,6 +277,11 @@ void hidResetReportDescriptor( void ) hidReportDescriptorPrepared = 0U; } +void hidSetChangePending( void ) +{ + s_hidChangePending = 1; +} + unsigned hidSetReportItem( const unsigned id, const unsigned byte, diff --git a/lib_xua/src/hid/xua_hid.h b/lib_xua/src/hid/xua_hid.h index 1344b5a2..9d8f1f82 100644 --- a/lib_xua/src/hid/xua_hid.h +++ b/lib_xua/src/hid/xua_hid.h @@ -41,17 +41,6 @@ XUD_Result_t HidInterfaceClassRequests( XUD_ep c_ep0_in, REFERENCE_PARAM( USB_SetupPacket_t, sp )); -/** - * \brief Register that previously changed HID Report data has reported - * to the USB Host. - */ -void HidClearChangePending( void ); - -/** - * \brief Indicate if a change to the HID Report data has been received. - */ -unsigned HidIsChangePending( void ); - /** * \brief Indicate whether to send a HID Report based on elapsed time. * @@ -70,9 +59,4 @@ unsigned HidIsChangePending( void ); */ unsigned HidIsSetIdleSilenced( void ); -/** - * \brief Register that a change to the HID Report data has been received. - */ -void HidSetChangePending( void ); - #endif // __XUA_HID_H__ diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index c9312be2..1196d347 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -87,6 +87,16 @@ typedef struct unsigned short location; } USB_HID_Report_Element_t; +/** + * \brief Register that previously changed HID Report data has been sent + * to the USB Host. + * + * \param[in] id A HID Report ID. + * Zero clears the pending status of all Report IDs. + * Use zero if the application does not use Report IDs. + */ +void hidClearChangePending( const unsigned id ); + /** * @brief Get the HID Report descriptor * @@ -180,6 +190,22 @@ unsigned hidGetReportItem( */ size_t hidGetReportLength( const unsigned id ); +/** + * \brief Indicate if a change to the HID Report data has been received. + * + * \param[in] id A HID Report ID. + * Zero reports the pending status of all Report IDs. + * Use zero if the application does not use Report IDs. + * + * \returns A Boolean indicating whether the given \a id has a changed + * HID Report not yet sent to the USB Host. + * \retval True The given \a id has changed HID Report data. + * For an \a id of zero, some HID Report has changed data. + * \retval False The given \a id does not have changed HID Report data. + * For an \a id of zero, no HID Report has changed data. + */ +unsigned hidIsChangePending( const unsigned id ); + /** * @brief Prepare the USB HID Report descriptor * @@ -197,6 +223,15 @@ void hidPrepareReportDescriptor( void ); */ void hidResetReportDescriptor( void ); +/** + * \brief Register that a change to the HID Report data has been received. + * + * \param[in] id A HID Report ID. + * Zero reports the pending status of all Report IDs. + * Use zero if the application does not use Report IDs. + */ +void hidSetChangePending( const unsigned id ); + /** * @brief Modify a HID Report descriptor item * From d515458b83bff36f6164acc097c1e0a1c51c49e1 Mon Sep 17 00:00:00 2001 From: mbanth Date: Wed, 1 Dec 2021 09:42:32 +0000 Subject: [PATCH 12/58] Add id parameter to hidClearChangePending(), hidIsChangePending() and hidSetChangePending(). Correct the name of the underlying static variable. --- lib_xua/src/hid/hid_report_descriptor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 74517a29..c6e40e1d 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -13,7 +13,7 @@ #define HID_REPORT_DESCRIPTOR_MAX_LENGTH ( HID_REPORT_DESCRIPTOR_ITEM_COUNT * \ ( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE )) -static unsigned hidChangePending = 0U; +static unsigned s_hidChangePending = 0U; static unsigned char hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; static size_t hidReportDescriptorLength = 0U; static unsigned hidReportDescriptorPrepared = 0U; @@ -124,7 +124,7 @@ static unsigned hidGetUsagePage( const unsigned id ); static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr ); -void hidClearChangePending( void ) +void hidClearChangePending( const unsigned id ) { s_hidChangePending = 0U; } @@ -253,7 +253,7 @@ static unsigned hidGetUsagePage( const unsigned id ) return retVal; } -unsigned hidIsChangePending( void ) +unsigned hidIsChangePending( const unsigned id ) { return( s_hidChangePending != 0 ); } @@ -277,7 +277,7 @@ void hidResetReportDescriptor( void ) hidReportDescriptorPrepared = 0U; } -void hidSetChangePending( void ) +void hidSetChangePending( const unsigned id ) { s_hidChangePending = 1; } From 21c1e661aeee4ce444168ba48d6bf416b3f131dd Mon Sep 17 00:00:00 2001 From: mbanth Date: Wed, 1 Dec 2021 09:47:52 +0000 Subject: [PATCH 13/58] Change static variable names to indicate that they are static. --- lib_xua/src/hid/hid_report_descriptor.c | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index c6e40e1d..67d6cdb7 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -14,9 +14,9 @@ ( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE )) static unsigned s_hidChangePending = 0U; -static unsigned char hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; -static size_t hidReportDescriptorLength = 0U; -static unsigned hidReportDescriptorPrepared = 0U; +static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; +static size_t s_hidReportDescriptorLength = 0U; +static unsigned s_hidReportDescriptorPrepared = 0U; volatile unsigned* s_hidChangePendingPtr = &hidChangePending; @@ -175,8 +175,8 @@ unsigned char* hidGetReportDescriptor( void ) { unsigned char* retVal = NULL; - if( hidReportDescriptorPrepared ) { - retVal = hidReportDescriptor; + if( s_hidReportDescriptorPrepared ) { + retVal = s_hidReportDescriptor; } return retVal; @@ -184,7 +184,7 @@ unsigned char* hidGetReportDescriptor( void ) size_t hidGetReportDescriptorLength( void ) { - size_t retVal = ( hidReportDescriptorPrepared ) ? hidReportDescriptorLength : 0U; + size_t retVal = ( s_hidReportDescriptorPrepared ) ? s_hidReportDescriptorLength : 0U; return retVal; } @@ -231,7 +231,7 @@ unsigned hidGetReportItem( size_t hidGetReportLength( const unsigned id ) { size_t retVal = 0U; - if( hidReportDescriptorPrepared ) { + if( s_hidReportDescriptorPrepared ) { for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { if( id == hidGetElementReportId( hidReports[ idx ]->location )) { retVal = hidGetElementReportLength( hidReports[ idx ]->location ); @@ -260,21 +260,21 @@ unsigned hidIsChangePending( const unsigned id ) void hidPrepareReportDescriptor( void ) { - if( !hidReportDescriptorPrepared ) { - hidReportDescriptorLength = 0U; - unsigned char* ptr = hidReportDescriptor; + if( !s_hidReportDescriptorPrepared ) { + s_hidReportDescriptorLength = 0U; + unsigned char* ptr = s_hidReportDescriptor; for( size_t idx = 0U; idx < HID_REPORT_DESCRIPTOR_ITEM_COUNT; ++idx ) { - hidReportDescriptorLength += hidTranslateItem( hidReportDescriptorItems[ idx ], &ptr ); + s_hidReportDescriptorLength += hidTranslateItem( hidReportDescriptorItems[ idx ], &ptr ); } - hidReportDescriptorPrepared = 1U; + s_hidReportDescriptorPrepared = 1U; } } void hidResetReportDescriptor( void ) { - hidReportDescriptorPrepared = 0U; + s_hidReportDescriptorPrepared = 0U; } void hidSetChangePending( const unsigned id ) @@ -293,7 +293,7 @@ unsigned hidSetReportItem( { unsigned retVal = HID_STATUS_IN_USE; - if( !hidReportDescriptorPrepared ) { + if( !s_hidReportDescriptorPrepared ) { retVal = HID_STATUS_BAD_ID; unsigned bSize = hidGetItemSize( header ); unsigned bTag = hidGetItemTag ( header ); From 53f80dfba44c370289b96cbc8452b2f63c11f1f3 Mon Sep 17 00:00:00 2001 From: mbanth Date: Wed, 1 Dec 2021 12:25:18 +0000 Subject: [PATCH 14/58] Add documentation --- lib_xua/src/hid/xua_hid_report_descriptor.h | 68 ++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index 1196d347..5c37972d 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -88,9 +88,29 @@ typedef struct } USB_HID_Report_Element_t; /** - * \brief Register that previously changed HID Report data has been sent + * \brief Register that a previously changed HID Report data has been sent * to the USB Host. * + * HID processing maintains a list of HID Reports with changed data not yet + * reported to the USB Host. + * + * Applications that have only one HID Report may or may not use a Report ID. + * Applications that have more than one HID Report must use Report IDs. + * + * For applications that do not use Report IDs, the list contains one element. + * That element tracks whether or not an unreported change has occurred in the + * HID data. + * For applications that use Report IDs, the list contains one element per + * Report ID. + * Each element tracks unreported changes for the corresponding Report ID. + * + * Calling this function for a given Report ID indicates that the changed + * HID data has been reported to the USB Host. + * + * \warning This function will fail silently if given a Report ID outside of + * the supported range. + * The supported range runs from zero inclusive to HID_REPORT_COUNT exclusive. + * * \param[in] id A HID Report ID. * Zero clears the pending status of all Report IDs. * Use zero if the application does not use Report IDs. @@ -193,6 +213,28 @@ size_t hidGetReportLength( const unsigned id ); /** * \brief Indicate if a change to the HID Report data has been received. * + * HID processing maintains a list of HID Reports with changed data not yet + * reported to the USB Host. + * + * Applications that have only one HID Report may or may not use a Report ID. + * Applications that have more than one HID Report must use Report IDs. + * + * For applications that do not use Report IDs, the list contains one element. + * That element tracks whether or not an unreported change has occurred in the + * HID data. + * For applications that use Report IDs, the list contains one element per + * Report ID. + * Each element tracks unreported changes for the corresponding Report ID. + * + * Calling this function with a given Report ID returns an indication of + * whether unreported HID data exists for that Report ID. + * + * \warning This function will return zero if given a Report ID outside of + * the supported range. + * If not using Report IDs, the supported range consists of the value zero only. + * If using Report IDs, the supported range runs from zero inclusive to + * HID_REPORT_COUNT exclusive. + * * \param[in] id A HID Report ID. * Zero reports the pending status of all Report IDs. * Use zero if the application does not use Report IDs. @@ -226,8 +268,30 @@ void hidResetReportDescriptor( void ); /** * \brief Register that a change to the HID Report data has been received. * + * HID processing maintains a list of HID Reports with changed data not yet + * reported to the USB Host. + * + * Applications that have only one HID Report may or may not use a Report ID. + * Applications that have more than one HID Report must use Report IDs. + * + * For applications that do not use Report IDs, the list contains one element. + * That element tracks whether or not an unreported change has occurred in the + * HID data. + * For applications that use Report IDs, the list contains one element per + * Report ID. + * Each element tracks unreported changes for the corresponding Report ID. + * + * Calling this function with a given Report ID indicates that the HID data + * for that Report ID has changed and has not yet been reported to the USB + * Host. + * + * \warning This function will fail silently if given a Report ID outside of + * the supported range. + * If not using Report IDs, the supported range consists of the value zero only. + * If using Report IDs, the supported range runs from one inclusive to + * HID_REPORT_COUNT exclusive. + * * \param[in] id A HID Report ID. - * Zero reports the pending status of all Report IDs. * Use zero if the application does not use Report IDs. */ void hidSetChangePending( const unsigned id ); From 8c175187c82b5f49b47196a428fa48725b95a75b Mon Sep 17 00:00:00 2001 From: mbanth Date: Wed, 1 Dec 2021 12:26:26 +0000 Subject: [PATCH 15/58] Modify hidClearChangePending(), hidIsChangePending() amd hidSetChangePending() to operate on a Report ID basis --- lib_xua/src/hid/hid_report_descriptor.c | 30 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 67d6cdb7..78bf2fb7 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -13,7 +13,10 @@ #define HID_REPORT_DESCRIPTOR_MAX_LENGTH ( HID_REPORT_DESCRIPTOR_ITEM_COUNT * \ ( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE )) -static unsigned s_hidChangePending = 0U; +/* + * Each element in s_hidChangePending corresponds to an element in hidReports. + */ +static unsigned s_hidChangePending[ HID_REPORT_COUNT ] = { 0U }; static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; static size_t s_hidReportDescriptorLength = 0U; static unsigned s_hidReportDescriptorPrepared = 0U; @@ -126,7 +129,12 @@ static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char void hidClearChangePending( const unsigned id ) { - s_hidChangePending = 0U; + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + if(( id == 0U ) || ( id == hidGetElementReportId( hidReports[ idx ]->location ))) { + s_hidChangePending[ idx ] = 0U; + break; + } + } } static unsigned hidGetElementBitLocation( const unsigned short location ) @@ -255,7 +263,16 @@ static unsigned hidGetUsagePage( const unsigned id ) unsigned hidIsChangePending( const unsigned id ) { - return( s_hidChangePending != 0 ); + unsigned retVal = 0U; + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + if( id == 0U ) { + retVal |= ( s_hidChangePending[ idx ] != 0U ); + } else if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + retVal = ( s_hidChangePending[ idx ] != 0U ); + break; + } + } + return retVal; } void hidPrepareReportDescriptor( void ) @@ -279,7 +296,12 @@ void hidResetReportDescriptor( void ) void hidSetChangePending( const unsigned id ) { - s_hidChangePending = 1; + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + s_hidChangePending[ idx ] = 1U; + break; + } + } } unsigned hidSetReportItem( From 171ef30f429f9b43daf1f2afdefa164786e25c2c Mon Sep 17 00:00:00 2001 From: mbanth Date: Mon, 6 Dec 2021 13:53:20 +0000 Subject: [PATCH 16/58] Remove redundant function declaration --- lib_xua/src/core/user/hid/user_hid.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib_xua/src/core/user/hid/user_hid.h b/lib_xua/src/core/user/hid/user_hid.h index bde24691..0ed07904 100644 --- a/lib_xua/src/core/user/hid/user_hid.h +++ b/lib_xua/src/core/user/hid/user_hid.h @@ -76,18 +76,5 @@ void UserHIDInit( void ); */ size_t UserHIDRecordEvent( const hidEvent_t hidEvent[], const size_t hidEventCnt ); -/** - * \brief Indicate if a HID Report ID has new data to report - * - * \param[in] id A HID Report ID (see 5.6, 6.2.2.7, 8.1 and 8.2). - * A value of zero means the application does not use Report IDs. - * - * \returns A Boolean flag indicating the status of the operation - * \retval False The given \a id either does not have new data to report or lies - * outside the range of supported HID Report identifiers - * \retval True The given \a id has new data to report to the USB Host - */ -unsigned UserHIDReportChanged( const unsigned id ); - #endif /* ( 0 < HID_CONTROLS ) */ #endif /* __USER_HID_H__ */ From 5354d94987eb941ac92bc7bd407f1548cf90067e Mon Sep 17 00:00:00 2001 From: mbanth Date: Mon, 6 Dec 2021 17:16:11 +0000 Subject: [PATCH 17/58] Remove unused pointer --- lib_xua/src/hid/hid_report_descriptor.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 78bf2fb7..c19ec3a0 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -21,8 +21,6 @@ static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; static size_t s_hidReportDescriptorLength = 0U; static unsigned s_hidReportDescriptorPrepared = 0U; -volatile unsigned* s_hidChangePendingPtr = &hidChangePending; - /** * @brief Get the bit position from the location of a report element * From 1d22975fd2fad55fedbb585db09bf90cef298ab8 Mon Sep 17 00:00:00 2001 From: mbanth Date: Mon, 6 Dec 2021 17:28:30 +0000 Subject: [PATCH 18/58] Update HID initialisation and handling to include multiple reports and the effect of the Set Idle command --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 32 ++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 2802ff15..80a913f5 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -23,6 +23,7 @@ #if( 0 < HID_CONTROLS ) #include "xua_hid_report_descriptor.h" #include "user_hid.h" +#include "xua_hid.h" unsigned char g_hidData[HID_MAX_DATA_BYTES] = {0}; #endif @@ -372,9 +373,21 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #if( 0 < HID_CONTROLS ) + UserHIDInit(); { - int hidDataLength = hidGetReportLength(0); // TODO Replace argument with HID Report ID - XUD_SetReady_In(ep_hid, g_hidData, hidDataLength); + int hidReportLength = 0; + unsigned hidReportId; + while(0 == hidReportLength) { + for( hidReportId = 0U; hidReportId < hidGetReportIdLimit(); ++hidReportId) { + hidReportLength = (int) hidGetReportLength(hidReportId); + if(0 < hidReportLength) { + break; + } + } + } + + hidReportLength = (int) UserHIDGetData(hidReportId, g_hidData); + XUD_SetReady_In(ep_hid, g_hidData, hidReportLength); } #endif @@ -887,11 +900,18 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #if( 0 < HID_CONTROLS ) /* HID Report Data */ - case XUD_SetData_Select(c_hid, ep_hid, result): + case hidIsChangePending(0U) || !HidIsSetIdleSilenced() => XUD_SetData_Select(c_hid, ep_hid, result): { - int hidDataLength = hidGetReportLength(0); // TODO Replace argument with HID Report ID - UserHIDGetData(0, g_hidData); // TODO Replace 1st argument with HID Report ID - XUD_SetReady_In(ep_hid, g_hidData, hidDataLength); + HidCaptureReportTime(); + for(unsigned id = 0; id < hidGetReportIdLimit(); ++id) { + if(hidIsChangePending(id)) { + int hidDataLength = (int) UserHIDGetData(id, g_hidData); + XUD_SetReady_In(ep_hid, g_hidData, hidDataLength); + HidCalcNextReportTime(); + hidClearChangePending(id); + break; + } + } } break; #endif From b4d5cb93f19ad233bf1fb0eaafdb83a662498480 Mon Sep 17 00:00:00 2001 From: mbanth Date: Tue, 7 Dec 2021 10:35:20 +0000 Subject: [PATCH 19/58] Use an unsigned constant with an unsigned variable --- lib_xua/src/hid/hid.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/src/hid/hid.xc b/lib_xua/src/hid/hid.xc index 5761a776..e51e6f1f 100644 --- a/lib_xua/src/hid/hid.xc +++ b/lib_xua/src/hid/hid.xc @@ -88,7 +88,7 @@ unsigned HidIsSetIdleSilenced( void ) */ static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod ) { - unsigned nextReportTime = 0; + unsigned nextReportTime = 0U; if( HidFindSetIdleActivationPoint( currentPeriod, reportToSetIdleInterval )) { /* Activate immediately after sending the next HID Report */ From 589c16d56caee5477d3a2f0276657d2a90f8ec6a Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Tue, 7 Dec 2021 17:17:14 +0000 Subject: [PATCH 20/58] Updated gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5b2ff009..466872d6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ test_results.csv _build* **/.venv/** +**/.vscode/** +**.egg-info # waf build files .lock-waf_* From 21b259bc88247a5e9bd6ecb2be5221a050e6f8ef Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Tue, 7 Dec 2021 18:12:00 +0000 Subject: [PATCH 21/58] Update legacy_test to new HID API --- .../hid_report_descriptor.h | 86 ++++++++++++------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h index a049576e..23bda6f7 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -29,41 +29,51 @@ unsigned char hidReportDescriptor[] = }; #endif +#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) +#define USB_HID_USAGE_PAGE_ID_CONSUMER (0x02) + /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }, .location = 0x00 }; - -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }, .location = 0x00 }; - -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }, .location = 0x00 }; - -static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }, .location = 0x00 }; - -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }, .location = 0x00 }; - -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }}; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = 0x09, .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute -static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = 0x09, .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- -static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = 0x09, .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ -static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = 0x09, .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev -static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = 0x09, .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next -static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = 0x09, .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play +static USB_HID_Report_Element_t hidUsageByte0Bit5 = { .item.header = 0x09, .item.data = { 0xE2, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) }; // Mute +static USB_HID_Report_Element_t hidUsageByte0Bit4 = { .item.header = 0x09, .item.data = { 0xEA, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) }; // Vol- +static USB_HID_Report_Element_t hidUsageByte0Bit3 = { .item.header = 0x09, .item.data = { 0xE9, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) }; // Vol+ +static USB_HID_Report_Element_t hidUsageByte0Bit2 = { .item.header = 0x09, .item.data = { 0xB6, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) }; // Scan Prev +static USB_HID_Report_Element_t hidUsageByte0Bit1 = { .item.header = 0x09, .item.data = { 0xB5, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) }; // Scan Next +static USB_HID_Report_Element_t hidUsageByte0Bit0 = { .item.header = 0x09, .item.data = { 0xB0, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) }; // Play + +static USB_HID_Short_Item_t hidReportID1 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00}}; +static const USB_HID_Report_Element_t hidReportConsumer = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 ) +}; /* * List the configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t* const hidConfigurableItems[] = { +static USB_HID_Report_Element_t* const hidConfigurableElements[] = { &hidUsageByte0Bit0, &hidUsageByte0Bit1, &hidUsageByte0Bit2, @@ -75,25 +85,26 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { /* * List Usage pages in the HID Report descriptor, one per byte. */ -static const USB_HID_Short_Item_t* const hidUsagePages[] = { +static const USB_HID_Short_Item_t * const hidUsagePages[] = { &hidUsagePageConsumer }; /* * List all items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { +static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = { + &(hidReportConsumer.item), &hidUsagePageConsumer, &hidUsageConsumerControl, &hidCollectionApplication, &hidLogicalMinimum0, &hidLogicalMaximum1, - &hidUsageByte0Bit0, - &hidUsageByte0Bit1, - &hidUsageByte0Bit2, - &hidUsageByte0Bit3, - &hidUsageByte0Bit4, - &hidUsageByte0Bit5, + &(hidUsageByte0Bit0.item), + &(hidUsageByte0Bit1.item), + &(hidUsageByte0Bit2.item), + &(hidUsageByte0Bit3.item), + &(hidUsageByte0Bit4.item), + &(hidUsageByte0Bit5.item), &hidReportSize1, &hidReportCount6, &hidInputDataVar, @@ -103,10 +114,21 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { &hidCollectionEnd }; +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportConsumer +}; + /* * Define the length of the HID Report. * This value must match the number of Report bytes defined by hidReportDescriptorItems. */ #define HID_REPORT_LENGTH ( 1 ) +/* + * Define the number of HID Reports + * Due to XC not supporting designated initializers, this constant has a hard-coded value. + * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) + */ +#define HID_REPORT_COUNT ( 1 ) + #endif // __hid_report_descriptor_h__ From 8c9e8b11b95a41f0d4ebe66506cac20b12be3d60 Mon Sep 17 00:00:00 2001 From: mbanth Date: Tue, 7 Dec 2021 18:50:28 +0000 Subject: [PATCH 22/58] Changes to support the Set Idle request with multiple Report IDs --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 14 +- lib_xua/src/hid/hid.xc | 46 +++---- lib_xua/src/hid/hid_report_descriptor.c | 106 +++++++++++++++- lib_xua/src/hid/xua_hid.h | 40 ++---- lib_xua/src/hid/xua_hid_report_descriptor.h | 134 ++++++++++++++++++++ 5 files changed, 275 insertions(+), 65 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 80a913f5..27b25751 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -900,14 +900,18 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #if( 0 < HID_CONTROLS ) /* HID Report Data */ - case hidIsChangePending(0U) || !HidIsSetIdleSilenced() => XUD_SetData_Select(c_hid, ep_hid, result): + case hidIsChangePending(0U) || !HidIsSetIdleSilenced(0U) => XUD_SetData_Select(c_hid, ep_hid, result): { - HidCaptureReportTime(); - for(unsigned id = 0; id < hidGetReportIdLimit(); ++id) { - if(hidIsChangePending(id)) { + timer tmr; + unsigned reportTime; + tmr :> reportTime; + + for(unsigned id = 0U; id < hidGetReportIdLimit(); ++id) { + if(0U == id || (hidIsChangePending(id) || !HidIsSetIdleSilenced(id))) { + hidCaptureReportTime(id, reportTime); int hidDataLength = (int) UserHIDGetData(id, g_hidData); XUD_SetReady_In(ep_hid, g_hidData, hidDataLength); - HidCalcNextReportTime(); + hidCalcNextReportTime(id); hidClearChangePending(id); break; } diff --git a/lib_xua/src/hid/hid.xc b/lib_xua/src/hid/hid.xc index e51e6f1f..83286bce 100644 --- a/lib_xua/src/hid/hid.xc +++ b/lib_xua/src/hid/hid.xc @@ -7,33 +7,15 @@ #include "xud.h" #include "xud_std_requests.h" #include "xua_hid.h" +#include "xua_hid_report_descriptor.h" #if( 0 < HID_CONTROLS ) -#define MS_IN_TICKS 100000U - -static unsigned s_hidCurrentPeriod = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; -static unsigned s_hidIdleActive = 0U; -static unsigned s_hidIndefiniteDuration = 0U; -static unsigned s_hidNextReportTime = 0U; -static unsigned s_hidReportTime = 0U; - static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod ); static unsigned HidCalcReportToSetIdleInterval( const unsigned reportTime ); static unsigned HidFindSetIdleActivationPoint( const unsigned currentPeriod, const unsigned timeWithinPeriod ); static XUD_Result_t HidProcessSetIdleRequest( XUD_ep c_ep0_out, XUD_ep c_ep0_in, USB_SetupPacket_t &sp ); static unsigned HidTimeDiff( const unsigned earlierTime, const unsigned laterTime ); -void HidCalcNextReportTime( void ) -{ - s_hidNextReportTime = s_hidReportTime + s_hidCurrentPeriod; -} - -void HidCaptureReportTime( void ) -{ - timer tmr; - tmr :> s_hidReportTime; -} - XUD_Result_t HidInterfaceClassRequests( XUD_ep c_ep0_out, XUD_ep c_ep0_in, @@ -53,17 +35,17 @@ XUD_Result_t HidInterfaceClassRequests( return result; } -unsigned HidIsSetIdleSilenced( void ) +unsigned HidIsSetIdleSilenced( const unsigned id ) { - unsigned isSilenced = s_hidIdleActive; + unsigned isSilenced = hidIsIdleActive( id ); - if( s_hidIdleActive ) { + if( isSilenced ) { unsigned currentTime; // Use inline assembly to access the time without creating a side-effect. // The mapper complains if the time comes from an XC timer because this function is called in the guard of a select case. // Appearently the use of a timer creates a side-effect that prohibits the operation of the select functionality. asm volatile( "gettime %0" : "=r" ( currentTime )); - isSilenced = ( s_hidIndefiniteDuration || ( timeafter( s_hidNextReportTime, currentTime ))); + isSilenced = ( 0U == hidGetReportPeriod( id ) || ( timeafter( hidGetNextReportTime( id ), currentTime ))); } return isSilenced; @@ -185,18 +167,20 @@ static XUD_Result_t HidProcessSetIdleRequest( XUD_ep c_ep0_out, XUD_ep c_ep0_in, Any Interface value other than INTERFACE_NUMBER_HID indicates an error by the USB Host. */ if(( 0U == reportId ) && ( INTERFACE_NUMBER_HID == interfaceNum )) { - s_hidIdleActive = (( 0U == duration ) || ( ENDPOINT_INT_INTERVAL_IN_HID < duration )); + hidSetIdle( reportId, ( 0U == duration ) || ( ENDPOINT_INT_INTERVAL_IN_HID < duration )); - if( s_hidIdleActive ) { - unsigned reportToSetIdleInterval = HidCalcReportToSetIdleInterval( s_hidReportTime ); - s_hidNextReportTime = HidCalcNewReportTime( s_hidCurrentPeriod, s_hidReportTime, reportToSetIdleInterval, duration * MS_IN_TICKS ); - s_hidCurrentPeriod = duration * MS_IN_TICKS; - s_hidIndefiniteDuration = ( 0U == duration ); + unsigned currentPeriod = hidGetReportPeriod( reportId ); + if( hidIsIdleActive( reportId )) { + unsigned reportTime = hidGetReportTime( reportId ); + unsigned reportToSetIdleInterval = HidCalcReportToSetIdleInterval( reportTime ); + unsigned nextReportTime = HidCalcNewReportTime( currentPeriod, reportTime, reportToSetIdleInterval, duration * MS_IN_TICKS ); + hidSetNextReportTime( reportId, nextReportTime ); + currentPeriod = duration * MS_IN_TICKS; } else { - s_hidCurrentPeriod = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; - s_hidIndefiniteDuration = 0U; + currentPeriod = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; } + hidSetReportPeriod( reportId, currentPeriod ); result = XUD_DoSetRequestStatus( c_ep0_in ); } diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index c19ec3a0..b046a2e5 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -3,6 +3,7 @@ #include #include #include +#include "descriptor_defs.h" #include "xua_hid_report_descriptor.h" #include "hid_report_descriptor.h" @@ -12,7 +13,6 @@ #define HID_REPORT_DESCRIPTOR_ITEM_COUNT ( sizeof hidReportDescriptorItems / sizeof ( USB_HID_Short_Item_t* )) #define HID_REPORT_DESCRIPTOR_MAX_LENGTH ( HID_REPORT_DESCRIPTOR_ITEM_COUNT * \ ( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE )) - /* * Each element in s_hidChangePending corresponds to an element in hidReports. */ @@ -21,6 +21,11 @@ static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; static size_t s_hidReportDescriptorLength = 0U; static unsigned s_hidReportDescriptorPrepared = 0U; +static unsigned s_hidCurrentPeriod[ HID_REPORT_COUNT ] = { ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS }; +static unsigned s_hidIdleActive[ HID_REPORT_COUNT ] = { 0U }; +static unsigned s_hidNextReportTime[ HID_REPORT_COUNT ] = { 0U }; +static unsigned s_hidReportTime[ HID_REPORT_COUNT ] = { 0U }; + /** * @brief Get the bit position from the location of a report element * @@ -125,6 +130,24 @@ static unsigned hidGetUsagePage( const unsigned id ); static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr ); +void hidCalcNextReportTime( const unsigned id ) +{ + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + s_hidNextReportTime[ idx ] = s_hidReportTime[ idx ] + s_hidCurrentPeriod[ idx ]; + } + } +} + +void hidCaptureReportTime( const unsigned id, const unsigned time ) +{ + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + s_hidNextReportTime[ idx ] = time; + } + } +} + void hidClearChangePending( const unsigned id ) { for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { @@ -177,6 +200,17 @@ static unsigned hidGetItemType( const unsigned char header ) return bType; } +unsigned hidGetNextReportTime( const unsigned id ) { + unsigned retVal = 0U; + + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + retVal = s_hidNextReportTime[ idx ]; + } + } + return retVal; +} + unsigned char* hidGetReportDescriptor( void ) { unsigned char* retVal = NULL; @@ -247,6 +281,29 @@ size_t hidGetReportLength( const unsigned id ) return retVal; } +unsigned hidGetReportPeriod( const unsigned id ) +{ + unsigned retVal = 0U; + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + retVal = s_hidCurrentPeriod[ idx ]; + break; + } + } + return retVal; +} + +unsigned hidGetReportTime( const unsigned id ) { + unsigned retVal = 0U; + + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + retVal = s_hidReportTime[ idx ]; + } + } + return retVal; +} + static unsigned hidGetUsagePage( const unsigned id ) { unsigned retVal = 0U; @@ -273,6 +330,24 @@ unsigned hidIsChangePending( const unsigned id ) return retVal; } +unsigned hidIsIdleActive( const unsigned id ) +{ + unsigned retVal = 0U; + if( 0U == id ) { + retVal = 1U; + } + + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + if( id == 0U ) { + retVal &= ( s_hidIdleActive[ idx ] != 0U ); + } else if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + retVal = ( s_hidIdleActive[ idx ] != 0U ); + break; + } + } + return retVal; +} + void hidPrepareReportDescriptor( void ) { if( !s_hidReportDescriptorPrepared ) { @@ -302,6 +377,25 @@ void hidSetChangePending( const unsigned id ) } } +void hidSetIdle( const unsigned id, const unsigned state ) +{ + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + s_hidIdleActive[ idx ] = ( state != 0U ); + break; + } + } +} + +void hidSetNextReportTime( const unsigned id, const unsigned time ) +{ + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + s_hidNextReportTime[ idx ] = time; + } + } +} + unsigned hidSetReportItem( const unsigned id, const unsigned byte, @@ -361,6 +455,16 @@ unsigned hidSetReportItem( return retVal; } +void hidSetReportPeriod( const unsigned id, const unsigned period ) +{ + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { + if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + s_hidCurrentPeriod[ idx ] = period; + break; + } + } +} + static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr ) { size_t count = 0U; diff --git a/lib_xua/src/hid/xua_hid.h b/lib_xua/src/hid/xua_hid.h index 9d8f1f82..6e5d31b2 100644 --- a/lib_xua/src/hid/xua_hid.h +++ b/lib_xua/src/hid/xua_hid.h @@ -1,6 +1,12 @@ // Copyright 2019-2021 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. +/** + * @brief Human Interface Device (HID) Class Request functions + * + * Document section numbers refer to the HID Device Class Definition, version 1.11. + */ + #ifndef __XUA_HID_H__ #define __XUA_HID_H__ @@ -9,33 +15,6 @@ #include "xud.h" #include "xud_std_requests.h" -/** - * \brief Calculate the next time to respond with a HID Report. - * - * If the USB Host has previously sent a valid HID Set_Idle request with - * a duration of zero or greater than the default reporting interval, - * the device sends HID Reports periodically or when the value of the - * payload has changed. - * - * This function calculates the time for sending the next periodic - * HID Report. - */ -void HidCalcNextReportTime( void ); - -/** - * \brief Capture the time of sending the current HID Report. - * - * If the USB Host has previously sent a valid HID Set_Idle request with - * a duration of zero or greater than the default reporting interval, - * the device sends HID Reports periodically or when the value of the - * payload has changed. - * - * This function captures the time when the HID Report was sent so that - * a subsequent call to HidCalNextReportTime() can calculate the time - * to send the next periodic HID Report. - */ -void HidCaptureReportTime( void ); - XUD_Result_t HidInterfaceClassRequests( XUD_ep c_ep0_out, XUD_ep c_ep0_in, @@ -53,10 +32,15 @@ XUD_Result_t HidInterfaceClassRequests( * whether or not the time to send the next periodic HID Report has * elapsed. * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * * \return A Boolean value indicating whether or not to send the HID Report. * \retval 1 -- Do not send the HID Report * \retval 0 -- Send the HID Report */ -unsigned HidIsSetIdleSilenced( void ); +unsigned HidIsSetIdleSilenced( const unsigned id ); #endif // __XUA_HID_H__ diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index 5c37972d..8043d1c3 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -57,6 +57,8 @@ #define HID_STATUS_BAD_PAGE ( 4U ) #define HID_STATUS_IN_USE ( 5U ) +#define MS_IN_TICKS 100000U + /** * @brief USB HID Report Descriptor Short Item * @@ -193,6 +195,57 @@ unsigned hidGetReportItem( unsigned char data[]); #endif +/** + * \brief Calculate the next time to respond with a HID Report. + * + * If the USB Host has previously sent a valid HID Set_Idle request with + * a duration of zero or greater than the default reporting interval, + * the device sends HID Reports periodically or when the value of the + * payload has changed. + * + * This function calculates the time for sending the next periodic + * HID Report. + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + */ +void hidCalcNextReportTime( const unsigned id ); + +/** + * \brief Capture the time of sending the current HID Report. + * + * If the USB Host has previously sent a valid HID Set_Idle request with + * a duration of zero or greater than the default reporting interval, + * the device sends HID Reports periodically or when the value of the + * payload has changed. + * + * This function captures the time when the HID Report was sent so that + * a subsequent call to HidCalNextReportTime() can calculate the time + * to send the next periodic HID Report. + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * + * @param[in] time The time when the HID Report for the given \a id was sent. + */ +void hidCaptureReportTime( const unsigned id, const unsigned time ); + +/** + * @brief Get the time to send the next HID Report time for the given \a id + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * + * @returns The time at which to send the next HID Report for the given \a id + */ +unsigned hidGetNextReportTime( const unsigned id ); + /** * @brief Get the length of the HID Report * @@ -210,6 +263,31 @@ unsigned hidGetReportItem( */ size_t hidGetReportLength( const unsigned id ); +/** + * @brief Get the HID Report period for the given \a id + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * + * @returns The period for the given HID Report \a id in units of ms. + * The value zero means the period is indefinite. + */ +unsigned hidGetReportPeriod( const unsigned id ); + +/** + * @brief Get the HID Report time for the given \a id + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * + * @returns The time of the last call to \c hidCaptureReportTime() + */ +unsigned hidGetReportTime( const unsigned id ); + /** * \brief Indicate if a change to the HID Report data has been received. * @@ -248,6 +326,22 @@ size_t hidGetReportLength( const unsigned id ); */ unsigned hidIsChangePending( const unsigned id ); +/** + * @brief Indicate if the HID report for the given \a id is idle + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero returns the collective Idle state. + * + * \returns A Boolean indicating whether the HID Report for the given \a id is idle. + * \retval True The HID Report is idle. + * For an \a id of zero, all HID Reports are idle. + * \retval False The HID Report is not idle. + * For an \a id of zero, at least one HID Report is not idle. + */ +unsigned hidIsIdleActive( const unsigned id ); + /** * @brief Prepare the USB HID Report descriptor * @@ -296,6 +390,32 @@ void hidResetReportDescriptor( void ); */ void hidSetChangePending( const unsigned id ); +/** + * @brief Set the HID Report Idle state for the given \a id + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * + * @param[in] state A Boolean indicating the Idle state + * If true, the HID Report for the given \a id is Idle, otherwise it + * is not Idle. + */ +void hidSetIdle( const unsigned id, const unsigned state ); + +/** + * @brief Set the time to send the HID Report for the given \a id + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * + * @param[in] time The time to send the HID Report for the given \a id. + */ +void hidSetNextReportTime( const unsigned id, const unsigned time ); + /** * @brief Modify a HID Report descriptor item * @@ -332,4 +452,18 @@ unsigned hidSetReportItem( const unsigned char header, const unsigned char data[]); +/** + * @brief Set the HID Report period for the given \a id + * + * Parameters: + * + * @param[in] id The identifier for the HID Report (see 5.6, 6.2.2.7, 8.1 and 8.2) + * A value of zero means the application does not use Report IDs. + * + * @param[in] period The period for sending the HID Report in units of ms. + * This period must be a multiple of 4 ms. + * Use zero to indicate an indefinite period. + */ +void hidSetReportPeriod( const unsigned id, const unsigned period ); + #endif // _HID_REPORT_DESCRIPTOR_ From 7dfd78deb4799b8901a2f0a111c89434c731b5d2 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 11:01:17 +0000 Subject: [PATCH 23/58] Update unit test header to match new report id api --- .../src/hid_report_descriptor.h | 80 ++++++++++++------- tests/xua_unit_tests/src/test_hid.c | 4 +- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/tests/xua_unit_tests/src/hid_report_descriptor.h b/tests/xua_unit_tests/src/hid_report_descriptor.h index a70075ba..8981846e 100644 --- a/tests/xua_unit_tests/src/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/hid_report_descriptor.h @@ -12,59 +12,78 @@ #define MIN_VALID_BIT ( 0 ) #define MIN_VALID_BYTE ( 0 ) +#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) + /* * Define non-configurable items in the HID Report descriptor. + * (These are short items as the location field isn't relevant for them) */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }}; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; -static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount7 = { .header = 0x95, .data = { 0x07, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount7 = { .header = 0x95, .data = { 0x07, 0x00 }}; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }, .location = 0x00 }; +/* + * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report + * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. + */ +static const USB_HID_Report_Element_t hidReportPageConsumer = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .location = HID_REPORT_SET_LOC( 0, 1, 0, 0 ) +}; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = 0x09, .data = { 0xE2, 0x00 }, .location = 0x00 }; // Mute +static USB_HID_Report_Element_t hidUsageByte0Bit0 = { + .item = { .header = 0x09, .data = { 0xE2, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 0, 0) +}; // Mute -static USB_HID_Short_Item_t hidUsageByte1Bit7 = { .header = 0x09, .data = { 0xEA, 0x00 }, .location = 0x71 }; // Vol- -static USB_HID_Short_Item_t hidUsageByte1Bit0 = { .header = 0x09, .data = { 0xE9, 0x00 }, .location = 0x01 }; // Vol+ +static USB_HID_Report_Element_t hidUsageByte1Bit7 = { + .item = { .header = 0x09, .data = { 0xEA, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 1, 7) +}; // Vol- +static USB_HID_Report_Element_t hidUsageByte1Bit0 = { + .item = { .header = 0x09, .data = { 0xE9, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 1, 0) +}; // Vol+ /* - * List the configurable items in the HID Report descriptor. + * List the configurable elements in the HID Report descriptor. */ -static USB_HID_Short_Item_t* const hidConfigurableItems[] = { +static USB_HID_Report_Element_t* const hidConfigurableElements[] = { &hidUsageByte0Bit0, &hidUsageByte1Bit0, &hidUsageByte1Bit7 }; /* - * List Usage pages in the HID Report descriptor, one per byte. + * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * If not using report IDs - still have one with report ID 0 */ -static const USB_HID_Short_Item_t* const hidUsagePages[] = { - &hidUsagePageConsumer, - &hidUsagePageConsumer +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportPageConsumer }; /* * List all items in the HID Report descriptor. */ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { - &hidUsagePageConsumer, + &(hidReportPageConsumer.item), &hidUsageConsumerControl, &hidCollectionApplication, &hidReportSize1, @@ -72,7 +91,7 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { &hidCollectionLogical, // Byte 0 &hidLogicalMaximum1, &hidReportCount1, - &hidUsageByte0Bit0, + &(hidUsageByte0Bit0.item), &hidInputDataVar, &hidLogicalMaximum0, &hidReportCount7, @@ -81,13 +100,13 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { &hidCollectionLogical, // Byte 1 &hidLogicalMaximum1, &hidReportCount1, - &hidUsageByte1Bit0, + &(hidUsageByte1Bit0.item), &hidInputDataVar, &hidLogicalMaximum0, &hidReportCount6, &hidInputConstArray, &hidLogicalMaximum1, - &hidUsageByte1Bit7, + &(hidUsageByte1Bit7.item), &hidInputDataVar, &hidCollectionEnd, &hidCollectionEnd @@ -99,4 +118,11 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { */ #define HID_REPORT_LENGTH ( 2 ) +/* + * Define the number of HID Reports + * Due to XC not supporting designated initializers, this constant has a hard-coded value. + * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) + */ +#define HID_REPORT_COUNT ( 3 ) + #endif // __hid_report_descriptor_h__ diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_hid.c index 965c7f90..7d473889 100644 --- a/tests/xua_unit_tests/src/test_hid.c +++ b/tests/xua_unit_tests/src/test_hid.c @@ -183,7 +183,7 @@ void test_configurable_item_hidSetReportItem( void ) void test_nonconfigurable_item_hidSetReportItem( void ) { const unsigned bit = MAX_VALID_BIT; // This bit and byte combination should not appear in the - const unsigned byte = MIN_VALID_BYTE; // hidConfigurableItems list in hid_report_descriptors.c. + const unsigned byte = MIN_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; @@ -196,7 +196,7 @@ void test_nonconfigurable_item_hidSetReportItem( void ) void test_max_bit_hidSetReportItem( void ) { const unsigned bit = MAX_VALID_BIT; // Only byte 1 has bit 7 not reserved, See the - const unsigned byte = MAX_VALID_BYTE; // hidConfigurableItems list in hid_report_descriptors.c. + const unsigned byte = MAX_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; From 6dfc934d36c6b009d47b3670d164407a06e6d563 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Wed, 8 Dec 2021 11:14:52 +0000 Subject: [PATCH 24/58] Correct error in hidCaptureReportTime --- lib_xua/src/hid/hid_report_descriptor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index b046a2e5..9de4810a 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -143,7 +143,7 @@ void hidCaptureReportTime( const unsigned id, const unsigned time ) { for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { if( id == hidGetElementReportId( hidReports[ idx ]->location )) { - s_hidNextReportTime[ idx ] = time; + s_hidReportTime[ idx ] = time; } } } From be90779db57ce744efd9c36e0cd20af1afa9f336 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 12:33:37 +0000 Subject: [PATCH 25/58] Temporary workaround for ENDPOINT_INT_INTERVAL_IN_HID definition --- lib_xua/src/core/endpoint0/descriptor_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/src/core/endpoint0/descriptor_defs.h b/lib_xua/src/core/endpoint0/descriptor_defs.h index b4dc692b..42567878 100644 --- a/lib_xua/src/core/endpoint0/descriptor_defs.h +++ b/lib_xua/src/core/endpoint0/descriptor_defs.h @@ -66,7 +66,7 @@ enum USBInterfaceNumber INTERFACE_COUNT /* End marker */ }; -#if( 0 < HID_CONTROLS ) +#ifndef ENDPOINT_INT_INTERVAL_IN_HID #define ENDPOINT_INT_INTERVAL_IN_HID 0x08 #endif From 79e256f8294fb9fe3cb5cefeb5a72d1a7d93335c Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 12:34:14 +0000 Subject: [PATCH 26/58] Update existing unit tests to work with the new API --- .../src/hid_report_descriptor.h | 4 +- tests/xua_unit_tests/src/test_hid.c | 106 ++++++++++++------ 2 files changed, 71 insertions(+), 39 deletions(-) diff --git a/tests/xua_unit_tests/src/hid_report_descriptor.h b/tests/xua_unit_tests/src/hid_report_descriptor.h index 8981846e..aad5bb49 100644 --- a/tests/xua_unit_tests/src/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/hid_report_descriptor.h @@ -42,7 +42,7 @@ static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, */ static const USB_HID_Report_Element_t hidReportPageConsumer = { .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, - .location = HID_REPORT_SET_LOC( 0, 1, 0, 0 ) + .location = HID_REPORT_SET_LOC( 0, 2, 0, 0 ) }; /* @@ -123,6 +123,6 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { * Due to XC not supporting designated initializers, this constant has a hard-coded value. * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) */ -#define HID_REPORT_COUNT ( 3 ) +#define HID_REPORT_COUNT ( 1 ) #endif // __hid_report_descriptor_h__ diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_hid.c index 7d473889..f9a8d6a6 100644 --- a/tests/xua_unit_tests/src/test_hid.c +++ b/tests/xua_unit_tests/src/test_hid.c @@ -36,20 +36,22 @@ void setUp( void ) // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { + const unsigned reportId = 0; unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NULL( reportDescPtr ); - unsigned reportLength = hidGetReportLength(); + unsigned reportLength = hidGetReportLength( reportId ); TEST_ASSERT_EQUAL_UINT( 0, reportLength ); } void test_prepared_hidGetReportDescriptor( void ) { + const unsigned reportId = 0; hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); - unsigned reportLength = hidGetReportLength(); + unsigned reportLength = hidGetReportLength( reportId ); TEST_ASSERT_EQUAL_UINT( HID_REPORT_LENGTH, reportLength ); } @@ -73,13 +75,14 @@ void test_reset_prepared_hidGetReportDescriptor( void ) // Basic item tests void test_max_loc_hidGetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MAX_VALID_BIT; const unsigned byte = MAX_VALID_BYTE; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; unsigned char header; unsigned char page; - unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page ); TEST_ASSERT_EQUAL_UINT( 0x09, header ); @@ -89,13 +92,14 @@ void test_max_loc_hidGetReportItem( void ) void test_min_loc_hidGetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; unsigned char header; unsigned char page; - unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page ); TEST_ASSERT_EQUAL_UINT( 0x09, header ); @@ -105,13 +109,14 @@ void test_min_loc_hidGetReportItem( void ) void test_overflow_bit_hidGetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MAX_VALID_BIT + 1; const unsigned byte = MAX_VALID_BYTE; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char header = 0xAA; unsigned char page = 0x44; - unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0xAA, header ); @@ -121,13 +126,14 @@ void test_overflow_bit_hidGetReportItem( void ) void test_overflow_byte_hidGetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MAX_VALID_BIT; const unsigned byte = MAX_VALID_BYTE + 1; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char header = 0xAA; unsigned char page = 0x44; - unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0xAA, header ); @@ -137,13 +143,14 @@ void test_overflow_byte_hidGetReportItem( void ) void test_underflow_bit_hidGetReportItem( void ) { - const int bit = MIN_VALID_BIT - 1; + const unsigned reportId = 0; + const int bit = MIN_VALID_BIT - 1; const unsigned byte = MIN_VALID_BYTE; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char header = 0xAA; unsigned char page = 0x44; - unsigned retVal = hidGetReportItem( byte, ( unsigned ) bit, &page, &header, data ); + unsigned retVal = hidGetReportItem( reportId, byte, ( unsigned ) bit, &page, &header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0xAA, header ); @@ -153,13 +160,14 @@ void test_underflow_bit_hidGetReportItem( void ) void test_underflow_byte_hidGetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const int byte = MIN_VALID_BYTE - 1; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char header = 0xAA; unsigned char page = 0x44; - unsigned retVal = hidGetReportItem(( unsigned ) byte, bit, &page, &header, data ); + unsigned retVal = hidGetReportItem( reportId, ( unsigned ) byte, bit, &page, &header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0xAA, header ); @@ -170,156 +178,170 @@ void test_underflow_byte_hidGetReportItem( void ) // Configurable and non-configurable item tests void test_configurable_item_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_nonconfigurable_item_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MAX_VALID_BIT; // This bit and byte combination should not appear in the const unsigned byte = MIN_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } // Bit range tests void test_max_bit_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MAX_VALID_BIT; // Only byte 1 has bit 7 not reserved, See the const unsigned byte = MAX_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_min_bit_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_overflow_bit_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MAX_VALID_BIT + 1; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } void test_underflow_bit_hidSetReportItem( void ) { + const unsigned reportId = 0; const int bit = MIN_VALID_BIT - 1; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, ( unsigned ) bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, ( unsigned ) bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } // Byte range tests void test_max_byte_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MAX_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_min_byte_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_overflow_byte_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MAX_VALID_BYTE + 1; const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } void test_underflow_byte_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const int byte = MIN_VALID_BYTE - 1; const unsigned char header = construct_usage_header( 0 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( ( unsigned ) byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, ( unsigned ) byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } // Size range tests void test_max_size_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 }; const unsigned char header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_min_size_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0x00 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_unsupported_size_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0x03 ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } // Header tag and type tests void test_bad_tag_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char good_header = construct_usage_header( 0x00 ); @@ -327,69 +349,74 @@ void test_bad_tag_hidSetReportItem( void ) for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) { unsigned char bad_header = good_header | (( 0x0F << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ); - unsigned retVal = hidSetReportItem( byte, bit, page, bad_header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, bad_header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } } void test_global_type_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | (( HID_REPORT_ITEM_TYPE_GLOBAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } void test_local_type_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | (( HID_REPORT_ITEM_TYPE_LOCAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } void test_main_type_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | (( HID_REPORT_ITEM_TYPE_MAIN << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } void test_reserved_type_hidSetReportItem( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | (( HID_REPORT_ITEM_TYPE_RESERVED << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } // Combined function tests void test_initial_modification_without_subsequent_preparation( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); unsigned char* reportDescPtr = hidGetReportDescriptor(); @@ -398,13 +425,14 @@ void test_initial_modification_without_subsequent_preparation( void ) void test_initial_modification_with_subsequent_preparation( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); hidPrepareReportDescriptor(); @@ -414,6 +442,7 @@ void test_initial_modification_with_subsequent_preparation( void ) void test_initial_modification_with_subsequent_verification_1( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; @@ -425,10 +454,10 @@ void test_initial_modification_with_subsequent_verification_1( void ) const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); const unsigned char set_page = CONSUMER_CONTROL_PAGE; - unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data ); + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); - unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data ); + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); TEST_ASSERT_EQUAL_UINT( set_page, get_page ); TEST_ASSERT_EQUAL_UINT( set_header, get_header ); @@ -438,6 +467,7 @@ void test_initial_modification_with_subsequent_verification_1( void ) void test_initial_modification_with_subsequent_verification_2( void ) { + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; @@ -450,10 +480,10 @@ void test_initial_modification_with_subsequent_verification_2( void ) const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); const unsigned char set_page = CONSUMER_CONTROL_PAGE; - unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data ); + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); - unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data ); + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); TEST_ASSERT_EQUAL_UINT( set_page, get_page ); TEST_ASSERT_EQUAL_UINT( set_header, get_header ); @@ -470,10 +500,10 @@ void test_initial_modification_with_subsequent_verification_2( void ) const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); const unsigned char set_page = CONSUMER_CONTROL_PAGE; - unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data ); + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); - unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data ); + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); TEST_ASSERT_EQUAL_UINT( set_page, get_page ); TEST_ASSERT_EQUAL_UINT( set_header, get_header ); @@ -488,6 +518,7 @@ void test_modification_without_subsequent_preparation( void ) unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; @@ -495,7 +526,7 @@ void test_modification_without_subsequent_preparation( void ) const unsigned char page = CONSUMER_CONTROL_PAGE; hidResetReportDescriptor(); - unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); reportDescPtr = hidGetReportDescriptor(); @@ -508,6 +539,7 @@ void test_modification_with_subsequent_preparation( void ) unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); + const unsigned reportId = 0; const unsigned bit = MIN_VALID_BIT; const unsigned byte = MIN_VALID_BYTE; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; @@ -515,7 +547,7 @@ void test_modification_with_subsequent_preparation( void ) const unsigned char page = CONSUMER_CONTROL_PAGE; hidResetReportDescriptor(); - unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); hidPrepareReportDescriptor(); From 3819f30ad0fb239b9cf1c9452c3302c63f39c981 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 15:47:15 +0000 Subject: [PATCH 27/58] Enable waf building unit tests in different confgurations --- tests/xua_unit_tests/CMakeLists.txt | 10 ++++---- .../{ => test_simple}/hid_report_descriptor.h | 0 .../src/{ => test_simple}/test_hid.c | 0 tests/xua_unit_tests/wscript | 23 +++++++++++++------ 4 files changed, 20 insertions(+), 13 deletions(-) rename tests/xua_unit_tests/src/{ => test_simple}/hid_report_descriptor.h (100%) rename tests/xua_unit_tests/src/{ => test_simple}/test_hid.c (100%) diff --git a/tests/xua_unit_tests/CMakeLists.txt b/tests/xua_unit_tests/CMakeLists.txt index 9e09a11b..9487a471 100644 --- a/tests/xua_unit_tests/CMakeLists.txt +++ b/tests/xua_unit_tests/CMakeLists.txt @@ -79,12 +79,10 @@ foreach( testsourcefile ${APP_SOURCES} ) set_target_properties(${ITEM_NAME} PROPERTIES OUTPUT_NAME ${ITEM_NAME}.xe) target_compile_options(${ITEM_NAME} PRIVATE ${APP_COMPILER_FLAGS}) - - - target_include_directories(${ITEM_NAME} - PRIVATE ${APP_INCLUDES} - PRIVATE ${XUA_INCLUDES_ALL} - ) + target_include_directories(${ITEM_NAME} + PRIVATE ${APP_INCLUDES} + PRIVATE ${XUA_INCLUDES_ALL} + ) target_sources(${ITEM_NAME} PRIVATE ${APP_SRCS} diff --git a/tests/xua_unit_tests/src/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h similarity index 100% rename from tests/xua_unit_tests/src/hid_report_descriptor.h rename to tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c similarity index 100% rename from tests/xua_unit_tests/src/test_hid.c rename to tests/xua_unit_tests/src/test_simple/test_hid.c diff --git a/tests/xua_unit_tests/wscript b/tests/xua_unit_tests/wscript index 0f162c19..da0e1fc2 100644 --- a/tests/xua_unit_tests/wscript +++ b/tests/xua_unit_tests/wscript @@ -95,6 +95,7 @@ def add_unity_runner_build_config(waf_conf, project_root_path, unity_test_path, def prepare_unity_test_for_build(waf_conf, project_root_path, unity_test_path, unity_runner_dir, unity_runner_suffix, target): + print("unity_test_path: " + str(unity_test_path)) generate_unity_runner(project_root_path, unity_test_path, unity_runner_dir, unity_runner_suffix) runner_build_flags = '' # Could extract flags from the test name @@ -107,7 +108,12 @@ def find_unity_test_paths(unity_test_dir, unity_test_prefix): Return a list of all file paths with the unity_test_prefix found in the unity_test_dir. """ - return glob.glob(os.path.join(unity_test_dir, unity_test_prefix+'*')) + file_list = [] + for root, dirs, files in os.walk(unity_test_dir): + for f in files: + if f.startswith(unity_test_prefix): + file_list.append(os.path.join(root,f)) + return file_list def find_unity_tests(unity_test_dir, unity_test_prefix): @@ -116,7 +122,7 @@ def find_unity_tests(unity_test_dir, unity_test_prefix): unity_test_prefix found in the unity_test_dir. """ unity_test_paths = find_unity_test_paths(unity_test_dir, unity_test_prefix) - return {get_test_name(path): get_file_type(path) + return {get_test_name(path): {"language": get_file_type(path), "dir": os.path.dirname(path)} for path in unity_test_paths} @@ -139,8 +145,8 @@ def generate_all_unity_runners(waf_conf, project_root_path, # TODO: can the xwaf boilerplate help here? def create_waf_contexts(configs): for trgt in TARGETS: - for test_name, test_language in configs.items(): - print(f"test_name {test_name}, test_language {test_language}") + for test_name, params in configs.items(): + print(f"test_name {test_name}, test_language {params['language']}") for ctx in (BuildContext, CleanContext): raw_context = ctx.__name__.replace('Context', '').lower() @@ -149,9 +155,10 @@ def create_waf_contexts(configs): variant = test_name + '_' + trgt #cmd = raw_context + '_' + test_name #variant = test_name - language = test_language + language = params["language"] target = trgt runner = test_name + directory = params["dir"] print(f"cmd {cmd}, variant {variant}, language {language}") @@ -161,6 +168,8 @@ UNITY_RUNNER_DIR = 'runners' UNITY_RUNNER_SUFFIX = '_Runner' UNITY_TESTS = find_unity_tests(UNITY_TEST_DIR, UNITY_TEST_PREFIX) +print("UNITY_TESTS: " + str(UNITY_TESTS)) + create_waf_contexts(UNITY_TESTS) def options(opt): @@ -175,7 +184,6 @@ def configure(conf): UNITY_RUNNER_DIR, UNITY_RUNNER_SUFFIX) conf.load('xwaf.xcommon') - def build(bld): if not bld.variant: print('Adding test runners to build queue') @@ -204,7 +212,7 @@ def build(bld): 'Unity'] makefile_opts = {} - makefile_opts['SOURCE_DIRS'] = ['src', os.path.join('runners',bld.runner)] + makefile_opts['SOURCE_DIRS'] = ['src', bld.directory, os.path.join('runners',bld.runner)] if(bld.target == 'xcoreai'): print('TARGET XCOREAI') makefile_opts['TARGET'] = ['XCORE-AI-EXPLORER'] @@ -213,6 +221,7 @@ def build(bld): makefile_opts['TARGET'] = ['XCORE-200-EXPLORER'] makefile_opts['INCLUDE_DIRS'] = ['src', + bld.directory, '../../lib_xua/api', '../../lib_xua/src/core/pdm_mics', '../../lib_xua/src/hid', From 459ce6bd63c3fd2fb4c8b9af12afb9560ba0d4af Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 17:55:33 +0000 Subject: [PATCH 28/58] Begin building up a set of multi-report unit tests This work is starting by expanding the tests written for single report purposes. I have also added a couple of extra simple tests that made sense (under/overflow of report IDs) as I went along. --- .../test_multi_report/hid_report_descriptor.h | 251 ++++++ .../test_multi_report/test_hid_multi_report.c | 728 ++++++++++++++++++ 2 files changed, 979 insertions(+) create mode 100644 tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h create mode 100644 tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h new file mode 100644 index 00000000..f524fcad --- /dev/null +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -0,0 +1,251 @@ +// Copyright 2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef __hid_report_descriptor_h__ +#define __hid_report_descriptor_h__ + +#include "xua_hid_report_descriptor.h" + +#define REPORT1_MAX_VALID_BIT ( 3 ) +#define REPORT1_MAX_VALID_BYTE ( 0 ) +#define REPORT1_MIN_VALID_BIT ( 0 ) +#define REPORT1_MIN_VALID_BYTE ( 0 ) + +#define REPORT2_MAX_VALID_BIT ( 7 ) +#define REPORT2_MAX_VALID_BYTE ( 1 ) +#define REPORT2_MIN_VALID_BIT ( 0 ) +#define REPORT2_MIN_VALID_BYTE ( 0 ) + +#define REPORT3_MAX_VALID_BIT ( 1 ) +#define REPORT3_MAX_VALID_BYTE ( 0 ) +#define REPORT3_MIN_VALID_BIT ( 0 ) +#define REPORT3_MIN_VALID_BYTE ( 0 ) + +#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) +#define USB_HID_REPORT_ID_KEYBOARD ( 0x01 ) +#define USB_HID_REPORT_ID_TELEPHONY ( 0x03 ) + +#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) +#define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 ) +#define USB_HID_USAGE_PAGE_ID_TELEPHONY ( 0x0B ) + +/* + * Define non-configurable items in the HID Report descriptor. + * (These are short items as the location field isn't relevant for them) + */ +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }}; + +static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; + +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; + +static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount4 = { .header = 0x95, .data = { 0x04, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; + +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; + +/* + * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report + * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. + */ +static const USB_HID_Short_Item_t hidReportId1 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId2 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId3 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY, 0x00 }}; + +static const USB_HID_Report_Element_t hidReportKeyboard = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 1, 0, 0 ) +}; + +static const USB_HID_Report_Element_t hidReportConsumer = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 2, 0, 0 ) +}; + +static const USB_HID_Report_Element_t hidReportTelephony = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 1, 0, 0 ) +}; + +static USB_HID_Report_Element_t hidUsageReport1Byte0Bit0 = { + .item = { .header = 0x09, .data = { 0x17, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 0 ) +}; // 't' + +static USB_HID_Report_Element_t hidUsageReport1Byte0Bit2 = { + .item = { .header = 0x09, .data = { 0x72, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 2 ) +}; // F23 + +static USB_HID_Report_Element_t hidUsageReport1Byte0Bit3 = { + .item = { .header = 0x09, .data = { 0x73, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 3 ) +}; // F24 + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit0 = { + .item = { .header = 0x0A, .data = { 0x26, 0x02 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) +}; // AC Stop + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit1 = { + .item = { .header = 0x0A, .data = { 0x21, 0x02 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) +}; // AC Search + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit2 = { + .item = { .header = 0x09, .data = { 0xE2, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) +}; // Mute + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit4 = { + .item = { .header = 0x09, .data = { 0xCF, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) +}; // Voice Command + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit6 = { + .item = { .header = 0x09, .data = { 0xE9, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 6 ) +}; // Vol+ + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit7 = { + .item = { .header = 0x09, .data = { 0xEA, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 7 ) +}; // Vol- + +static USB_HID_Report_Element_t hidUsageReport2Byte1Bit7 = { + .item = { .header = 0x09, .data = { 0xE5, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 1, 7 ) +}; // Bass boost + +static USB_HID_Report_Element_t hidUsageReport3Byte0Bit0 = { + .item = { .header = 0x09, .data = { 0x20, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 0 ) +}; // Hook Switch + +static USB_HID_Report_Element_t hidUsageReport3Byte0Bit1 = { + .item = { .header = 0x09, .data = { 0x2F, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 1 ) +}; // Phone Mute + +/* + * List the configurable elements in the HID Report. + */ +static USB_HID_Report_Element_t* const hidConfigurableElements[] = { + &hidUsageReport1Byte0Bit0, + &hidUsageReport1Byte0Bit2, + &hidUsageReport1Byte0Bit3, + + &hidUsageReport2Byte0Bit0, + &hidUsageReport2Byte0Bit1, + &hidUsageReport2Byte0Bit2, + &hidUsageReport2Byte0Bit4, + &hidUsageReport2Byte0Bit6, + &hidUsageReport2Byte0Bit7, + &hidUsageReport2Byte1Bit7, + + &hidUsageReport3Byte0Bit0, + &hidUsageReport3Byte0Bit1 +}; + +/* + * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * If not using report IDs - still have one with report ID 0 + */ +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportKeyboard, + &hidReportConsumer, + &hidReportTelephony +}; + +/* + * List all items in the HID Report descriptor. + */ +static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { + &(hidReportConsumer.item), + &hidUsageConsumerControl, + &hidCollectionApplication, + &hidReportSize1, + &hidLogicalMinimum0, + &hidCollectionLogical, // Report 1 + &hidReportId1, + &(hidReportKeyboard.item), + &hidLogicalMaximum1, + &hidReportCount1, + &(hidUsageReport1Byte0Bit0.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport1Byte0Bit2.item), + &hidInputDataVar, + &(hidUsageReport1Byte0Bit3.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidReportCount4, + &hidInputConstArray, + &hidCollectionEnd, + &hidCollectionLogical, // Report 2 + &hidReportId2, + &(hidReportConsumer.item), + &hidLogicalMaximum1, + &hidReportCount1, + &(hidUsageReport2Byte0Bit0.item), + &hidInputDataVar, + &(hidUsageReport2Byte0Bit1.item), + &hidInputDataVar, + &(hidUsageReport2Byte0Bit2.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport2Byte0Bit4.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport2Byte0Bit6.item), + &hidInputDataVar, + &(hidUsageReport2Byte0Bit7.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidReportCount6, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport2Byte1Bit7.item), + &hidInputDataVar, + &hidCollectionEnd, + &hidCollectionLogical, // Report 3 + &hidReportId3, + &(hidReportTelephony.item), + &(hidUsageReport3Byte0Bit0.item), + &hidInputDataVar, + &(hidUsageReport3Byte0Bit1.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidReportCount6, + &hidInputConstArray, + &hidCollectionEnd, + &hidCollectionEnd +}; + +/* + * Define the length of the HID Report. + * This value must match the number of Report bytes defined by hidReportDescriptorItems. + */ +#define HID_REPORT_LENGTH ( 3 ) + +/* + * Define the number of HID Reports + * Due to XC not supporting designated initializers, this constant has a hard-coded value. + * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) + */ +#define HID_REPORT_COUNT ( 3 ) + +#endif // __hid_report_descriptor_h__ diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c new file mode 100644 index 00000000..f225a212 --- /dev/null +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -0,0 +1,728 @@ +// Copyright 2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. +#include +#include + +#include "xua_unit_tests.h" +#include "xua_hid_report_descriptor.h" +#include "hid_report_descriptor.h" + +#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) +#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) +#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) +#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) + +#define KEYBOARD_PAGE ( 0x07 ) +#define CONSUMER_PAGE ( 0x0C ) +#define TELEPHONY_DEVICE_PAGE ( 0x0B ) +#define LOUDNESS_CONTROL ( 0xE7 ) +#define AL_CONTROL_PANEL ( 0x019F ) + +static unsigned construct_usage_header( unsigned size ) +{ + unsigned header = 0x00; + + header |= ( HID_REPORT_ITEM_USAGE_TAG << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK; + header |= ( HID_REPORT_ITEM_USAGE_TYPE << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK; + + header |= ( size << HID_REPORT_ITEM_HDR_SIZE_SHIFT ) & HID_REPORT_ITEM_HDR_SIZE_MASK; + + return header; +} + +void setUp( void ) +{ + hidResetReportDescriptor(); +} + +// Basic report descriptor tests +void test_unprepared_hidGetReportDescriptor( void ) +{ + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); + + for (unsigned reportId = 1; reportId <= HID_REPORT_COUNT; reportId++) + { + unsigned reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, reportLength ); + } +} + +void test_prepared_hidGetReportDescriptor( void ) +{ + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); + + unsigned reportId = 1; + unsigned reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, reportLength ); + + reportId = 2; + reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 2, reportLength ); + + reportId = 3; + reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, reportLength ); +} + +void test_reset_unprepared_hidGetReportDescriptor( void ) +{ + hidPrepareReportDescriptor(); + hidResetReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); +} + +void test_reset_prepared_hidGetReportDescriptor( void ) +{ + hidPrepareReportDescriptor(); + hidResetReportDescriptor(); + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); +} + +// Basic item tests +void test_max_loc_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; + unsigned char header; + unsigned char page; + + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT; + unsigned byte = REPORT1_MAX_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x73, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT; + byte = REPORT2_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0xE5, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT; + byte = REPORT3_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( TELEPHONY_DEVICE_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x2F, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); +} + + +void test_min_loc_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; + unsigned char header; + unsigned char page; + + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x17, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT; + byte = REPORT2_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x0A, header ); + TEST_ASSERT_EQUAL_UINT( 0x26, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x02, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT; + byte = REPORT3_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( TELEPHONY_DEVICE_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x20, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); +} + +void test_invalid_report_id( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD2 }; + unsigned char header = 0x33; + unsigned char page = 0x44; + + unsigned reportId = 0; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_ID, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0x33, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD2, data[ 1 ]); +} + +void test_unused_report_id( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD2 }; + unsigned char header = 0x33; + unsigned char page = 0x44; + + unsigned reportId = 8; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_ID, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0x33, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD2, data[ 1 ]); +} + +void test_overflow_bit_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT + 1; + unsigned byte = REPORT1_MAX_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT + 1; + byte = REPORT2_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT + 1; + byte = REPORT3_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +void test_overflow_byte_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT; + unsigned byte = REPORT1_MAX_VALID_BYTE + 1; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT; + byte = REPORT2_MAX_VALID_BYTE + 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT; + byte = REPORT3_MAX_VALID_BYTE + 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +void test_underflow_bit_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT - 1; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT - 1; + byte = REPORT2_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT - 1; + byte = REPORT3_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +void test_underflow_byte_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE - 1; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT; + byte = REPORT2_MIN_VALID_BYTE - 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT; + byte = REPORT3_MIN_VALID_BYTE - 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +#if 0 +//here + +// Configurable and non-configurable item tests +void xtest_configurable_item_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_nonconfigurable_item_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MAX_VALID_BIT; // This bit and byte combination should not appear in the + const unsigned byte = MIN_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +// Bit range tests +void xtest_max_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MAX_VALID_BIT; // Only byte 1 has bit 7 not reserved, See the + const unsigned byte = MAX_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_min_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_overflow_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MAX_VALID_BIT + 1; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +void xtest_underflow_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const int bit = MIN_VALID_BIT - 1; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, ( unsigned ) bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +// Byte range tests +void xtest_max_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MAX_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_min_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_overflow_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MAX_VALID_BYTE + 1; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +void xtest_underflow_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const int byte = MIN_VALID_BYTE - 1; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, ( unsigned ) byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +// Size range tests +void xtest_max_size_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 }; + const unsigned char header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_min_size_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0x00 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_unsupported_size_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0x03 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +// Header tag and type tests +void xtest_bad_tag_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char good_header = construct_usage_header( 0x00 ); + const unsigned char page = CONSUMER_PAGE; + + for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) { + unsigned char bad_header = good_header | (( 0x0F << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, bad_header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); + } +} + +void xtest_global_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_GLOBAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +void xtest_local_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_LOCAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_main_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_MAIN << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +void xtest_reserved_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_RESERVED << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +// Combined function tests +void xtest_initial_modification_without_subsequent_preparation( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); +} + +void xtest_initial_modification_with_subsequent_preparation( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); +} + +void xtest_initial_modification_with_subsequent_verification_1( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + + unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; + unsigned char get_header = 0xFF; + unsigned char get_page = 0xFF; + + const unsigned char set_data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); + const unsigned char set_page = CONSUMER_PAGE; + + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); + + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); + TEST_ASSERT_EQUAL_UINT( set_page, get_page ); + TEST_ASSERT_EQUAL_UINT( set_header, get_header ); + TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // Should be MSB of data from hidUsageByte0Bit0 in hid_report_descriptor.h +} + +void xtest_initial_modification_with_subsequent_verification_2( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + + { + unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; + unsigned char get_header = 0xFF; + unsigned char get_page = 0xFF; + + const unsigned char set_data[ 2 ] = {( AL_CONTROL_PANEL & 0x00FF ), (( AL_CONTROL_PANEL & 0xFF00 ) >> 8 )}; + const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); + const unsigned char set_page = CONSUMER_PAGE; + + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); + + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); + TEST_ASSERT_EQUAL_UINT( set_page, get_page ); + TEST_ASSERT_EQUAL_UINT( set_header, get_header ); + TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( set_data[ 1 ], get_data[ 1 ]); + } + + { + unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; + unsigned char get_header = 0xFF; + unsigned char get_page = 0xFF; + + const unsigned char set_data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); + const unsigned char set_page = CONSUMER_PAGE; + + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); + + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); + TEST_ASSERT_EQUAL_UINT( set_page, get_page ); + TEST_ASSERT_EQUAL_UINT( set_header, get_header ); + TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // The call to hidSetReportItem with size 1 in the header should return the MSB to zero + } +} + +void xtest_modification_without_subsequent_preparation( void ) +{ + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); + + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + hidResetReportDescriptor(); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); +} + +void xtest_modification_with_subsequent_preparation( void ) +{ + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); + + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + hidResetReportDescriptor(); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + hidPrepareReportDescriptor(); + reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); +} + +#endif \ No newline at end of file From ed7a33b40f20ca9a56b08fafdcd9471f622e10dd Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 11:45:03 +0000 Subject: [PATCH 29/58] Write a bunch of unit tests that exercise the HID report IDs --- .../test_multi_report/hid_report_descriptor.h | 8 +- .../test_multi_report/test_hid_multi_report.c | 424 +++++++++--------- .../xua_unit_tests/src/test_simple/test_hid.c | 2 +- 3 files changed, 210 insertions(+), 224 deletions(-) diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h index f524fcad..75721cbf 100644 --- a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -21,8 +21,8 @@ #define REPORT3_MIN_VALID_BIT ( 0 ) #define REPORT3_MIN_VALID_BYTE ( 0 ) -#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) #define USB_HID_REPORT_ID_KEYBOARD ( 0x01 ) +#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) #define USB_HID_REPORT_ID_TELEPHONY ( 0x03 ) #define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) @@ -55,9 +55,9 @@ static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. */ -static const USB_HID_Short_Item_t hidReportId1 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }}; -static const USB_HID_Short_Item_t hidReportId2 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}; -static const USB_HID_Short_Item_t hidReportId3 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId1 = { .header = 0x85, .data = { USB_HID_REPORT_ID_KEYBOARD, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId2 = { .header = 0x85, .data = { USB_HID_REPORT_ID_CONSUMER, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId3 = { .header = 0x85, .data = { USB_HID_REPORT_ID_TELEPHONY, 0x00 }}; static const USB_HID_Report_Element_t hidReportKeyboard = { .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }}, diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index f225a212..cc5a2371 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -16,7 +16,9 @@ #define CONSUMER_PAGE ( 0x0C ) #define TELEPHONY_DEVICE_PAGE ( 0x0B ) #define LOUDNESS_CONTROL ( 0xE7 ) -#define AL_CONTROL_PANEL ( 0x019F ) +#define PHONE_KEY_9 ( 0xB9 ) +#define KEYBOARD_X ( 0x1B ) +#define PHONE_HOST_HOLD ( 0x010A ) static unsigned construct_usage_header( unsigned size ) { @@ -35,6 +37,19 @@ void setUp( void ) hidResetReportDescriptor(); } +void test_print_report( void ) +{ + hidPrepareReportDescriptor(); + unsigned char* report = hidGetReportDescriptor(); + size_t reportLen = hidGetReportDescriptorLength(); + + printf("ReportDescriptor:"); + for (size_t i = 0; i < reportLen; i++) { + printf(" %02x", report[i]); + } + printf("\n"); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { @@ -342,246 +357,262 @@ void test_underflow_byte_hidGetReportItem( void ) TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); } -#if 0 -//here - // Configurable and non-configurable item tests -void xtest_configurable_item_hidSetReportItem( void ) +void test_configurable_item_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; - const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); - const unsigned char page = CONSUMER_PAGE; + const unsigned reportId = 1; + const unsigned bit = REPORT1_MIN_VALID_BIT; + const unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned char data[ 1 ] = { KEYBOARD_X }; + unsigned char header = construct_usage_header( sizeof( data ) / sizeof( unsigned char )); + unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( KEYBOARD_X, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); } -void xtest_nonconfigurable_item_hidSetReportItem( void ) +// Testing that the high byte of the report gets correctly cleared +void test_configurable_item_hidSetReportItem_multibyte_orig( void ) { - const unsigned reportId = 0; - const unsigned bit = MAX_VALID_BIT; // This bit and byte combination should not appear in the - const unsigned byte = MIN_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. - const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned reportId = 2; + const unsigned bit = 1; // This byte&bit combo is originally set be 2 bytes long in the header + const unsigned byte = 0; + unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + unsigned char header = construct_usage_header( sizeof( data ) / sizeof( unsigned char )); + unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( LOUDNESS_CONTROL, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); +} + +void test_nonconfigurable_item_hidSetReportItem( void ) +{ + const unsigned reportId = 1; + const unsigned bit = 1; // This bit and byte combination should not appear in the + const unsigned byte = 0; // hidConfigurableElements list in hid_report_descriptors.c. + const unsigned char data[ 1 ] = { KEYBOARD_X }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); - const unsigned char page = CONSUMER_PAGE; + const unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } // Bit range tests -void xtest_max_bit_hidSetReportItem( void ) +void test_max_bit_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MAX_VALID_BIT; // Only byte 1 has bit 7 not reserved, See the - const unsigned byte = MAX_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c. + unsigned byte = REPORT1_MAX_VALID_BYTE; + unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT; + byte = REPORT2_MAX_VALID_BYTE; + page = CONSUMER_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT; + byte = REPORT3_MAX_VALID_BYTE; + page = TELEPHONY_DEVICE_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } -void xtest_min_bit_hidSetReportItem( void ) +void test_min_bit_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c. + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT; + byte = REPORT2_MIN_VALID_BYTE; + page = CONSUMER_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT; + byte = REPORT3_MIN_VALID_BYTE; + page = TELEPHONY_DEVICE_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } -void xtest_overflow_bit_hidSetReportItem( void ) +void test_overflow_bit_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MAX_VALID_BIT + 1; - const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT + 1; // See the hidConfigurableElements list in hid_report_descriptors.c. + unsigned byte = REPORT1_MAX_VALID_BYTE; + unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT + 1; + byte = REPORT2_MAX_VALID_BYTE; + page = CONSUMER_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT + 1; + byte = REPORT3_MAX_VALID_BYTE; + page = TELEPHONY_DEVICE_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } -void xtest_underflow_bit_hidSetReportItem( void ) +void test_underflow_bit_hidSetReportItem( void ) { - const unsigned reportId = 0; - const int bit = MIN_VALID_BIT - 1; - const unsigned byte = MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; - unsigned retVal = hidSetReportItem( reportId, byte, ( unsigned ) bit, page, header, NULL ); + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT - 1; // See the hidConfigurableElements list in hid_report_descriptors.c. + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned char page = KEYBOARD_PAGE; + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT - 1; + byte = REPORT2_MIN_VALID_BYTE; + page = CONSUMER_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT - 1; + byte = REPORT3_MIN_VALID_BYTE; + page = TELEPHONY_DEVICE_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } -// Byte range tests -void xtest_max_byte_hidSetReportItem( void ) +void test_overflow_byte_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MAX_VALID_BYTE; const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c. + unsigned byte = REPORT1_MAX_VALID_BYTE + 1; + unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); -} + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); -void xtest_min_byte_hidSetReportItem( void ) -{ - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; + reportId = 2; + bit = REPORT2_MAX_VALID_BIT; + byte = REPORT2_MAX_VALID_BYTE + 1; + page = CONSUMER_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); -} - -void xtest_overflow_byte_hidSetReportItem( void ) -{ - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MAX_VALID_BYTE + 1; - const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; - - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + reportId = 3; + bit = REPORT3_MAX_VALID_BIT; + byte = REPORT3_MAX_VALID_BYTE + 1; + page = TELEPHONY_DEVICE_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } -void xtest_underflow_byte_hidSetReportItem( void ) +void test_underflow_byte_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const int byte = MIN_VALID_BYTE - 1; const unsigned char header = construct_usage_header( 0 ); - const unsigned char page = CONSUMER_PAGE; - unsigned retVal = hidSetReportItem( reportId, ( unsigned ) byte, bit, page, header, NULL ); + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c. + unsigned byte = REPORT1_MIN_VALID_BYTE - 1; + unsigned char page = KEYBOARD_PAGE; + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT; + byte = REPORT2_MIN_VALID_BYTE - 1; + page = CONSUMER_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT; + byte = REPORT3_MIN_VALID_BYTE - 1; + page = TELEPHONY_DEVICE_PAGE; + retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } // Size range tests -void xtest_max_size_hidSetReportItem( void ) +void test_max_size_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; + const unsigned reportId = 1; + const unsigned bit = REPORT1_MIN_VALID_BIT; + const unsigned byte = REPORT1_MIN_VALID_BYTE; const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 }; const unsigned char header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE ); - const unsigned char page = CONSUMER_PAGE; + const unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } -void xtest_min_size_hidSetReportItem( void ) +void test_min_size_hidSetReportItem( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; + const unsigned reportId = 1; + const unsigned bit = REPORT1_MIN_VALID_BIT; + const unsigned byte = REPORT1_MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0x00 ); - const unsigned char page = CONSUMER_PAGE; + const unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } -void xtest_unsupported_size_hidSetReportItem( void ) +void test_unsupported_size_hidSetReportItem( void ) { const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; + const unsigned bit = REPORT1_MIN_VALID_BIT; + const unsigned byte = REPORT1_MIN_VALID_BYTE; const unsigned char header = construct_usage_header( 0x03 ); - const unsigned char page = CONSUMER_PAGE; - - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); -} - -// Header tag and type tests -void xtest_bad_tag_hidSetReportItem( void ) -{ - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char good_header = construct_usage_header( 0x00 ); - const unsigned char page = CONSUMER_PAGE; - - for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) { - unsigned char bad_header = good_header | (( 0x0F << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ); - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, bad_header, NULL ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); - } -} - -void xtest_global_type_hidSetReportItem( void ) -{ - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | - (( HID_REPORT_ITEM_TYPE_GLOBAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); - const unsigned char page = CONSUMER_PAGE; - - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); -} - -void xtest_local_type_hidSetReportItem( void ) -{ - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | - (( HID_REPORT_ITEM_TYPE_LOCAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); - const unsigned char page = CONSUMER_PAGE; - - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); -} - -void xtest_main_type_hidSetReportItem( void ) -{ - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | - (( HID_REPORT_ITEM_TYPE_MAIN << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); - const unsigned char page = CONSUMER_PAGE; - - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); -} - -void xtest_reserved_type_hidSetReportItem( void ) -{ - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | - (( HID_REPORT_ITEM_TYPE_RESERVED << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); - const unsigned char page = CONSUMER_PAGE; + const unsigned char page = KEYBOARD_PAGE; unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } // Combined function tests -void xtest_initial_modification_without_subsequent_preparation( void ) +void test_initial_modification_without_subsequent_preparation( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; + const unsigned reportId = 2; + const unsigned bit = REPORT2_MIN_VALID_BIT; + const unsigned byte = REPORT2_MIN_VALID_BYTE; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_PAGE; @@ -593,11 +624,11 @@ void xtest_initial_modification_without_subsequent_preparation( void ) TEST_ASSERT_NULL( reportDescPtr ); } -void xtest_initial_modification_with_subsequent_preparation( void ) +void test_initial_modification_with_subsequent_preparation( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; + const unsigned reportId = 2; + const unsigned bit = REPORT2_MIN_VALID_BIT; + const unsigned byte = REPORT2_MIN_VALID_BYTE; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_PAGE; @@ -610,11 +641,11 @@ void xtest_initial_modification_with_subsequent_preparation( void ) TEST_ASSERT_NOT_NULL( reportDescPtr ); } -void xtest_initial_modification_with_subsequent_verification_1( void ) +void test_initial_modification_with_subsequent_verification_1( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; + const unsigned reportId = 2; + const unsigned bit = REPORT2_MIN_VALID_BIT; + const unsigned byte = REPORT2_MIN_VALID_BYTE; unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; unsigned char get_header = 0xFF; @@ -635,20 +666,20 @@ void xtest_initial_modification_with_subsequent_verification_1( void ) TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // Should be MSB of data from hidUsageByte0Bit0 in hid_report_descriptor.h } -void xtest_initial_modification_with_subsequent_verification_2( void ) +void test_initial_modification_with_subsequent_verification_2( void ) { - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; + const unsigned reportId = 3; + const unsigned bit = REPORT3_MIN_VALID_BIT; + const unsigned byte = REPORT3_MIN_VALID_BYTE; { unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; unsigned char get_header = 0xFF; unsigned char get_page = 0xFF; - const unsigned char set_data[ 2 ] = {( AL_CONTROL_PANEL & 0x00FF ), (( AL_CONTROL_PANEL & 0xFF00 ) >> 8 )}; + const unsigned char set_data[ 2 ] = {( PHONE_HOST_HOLD & 0x00FF ), (( PHONE_HOST_HOLD & 0xFF00 ) >> 8 )}; const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); - const unsigned char set_page = CONSUMER_PAGE; + const unsigned char set_page = TELEPHONY_DEVICE_PAGE; unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); @@ -666,9 +697,9 @@ void xtest_initial_modification_with_subsequent_verification_2( void ) unsigned char get_header = 0xFF; unsigned char get_page = 0xFF; - const unsigned char set_data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char set_data[ 1 ] = { PHONE_KEY_9 }; const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); - const unsigned char set_page = CONSUMER_PAGE; + const unsigned char set_page = TELEPHONY_DEVICE_PAGE; unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); @@ -681,48 +712,3 @@ void xtest_initial_modification_with_subsequent_verification_2( void ) TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // The call to hidSetReportItem with size 1 in the header should return the MSB to zero } } - -void xtest_modification_without_subsequent_preparation( void ) -{ - hidPrepareReportDescriptor(); - unsigned char* reportDescPtr = hidGetReportDescriptor(); - TEST_ASSERT_NOT_NULL( reportDescPtr ); - - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; - const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); - const unsigned char page = CONSUMER_PAGE; - - hidResetReportDescriptor(); - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); - - reportDescPtr = hidGetReportDescriptor(); - TEST_ASSERT_NULL( reportDescPtr ); -} - -void xtest_modification_with_subsequent_preparation( void ) -{ - hidPrepareReportDescriptor(); - unsigned char* reportDescPtr = hidGetReportDescriptor(); - TEST_ASSERT_NOT_NULL( reportDescPtr ); - - const unsigned reportId = 0; - const unsigned bit = MIN_VALID_BIT; - const unsigned byte = MIN_VALID_BYTE; - const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; - const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); - const unsigned char page = CONSUMER_PAGE; - - hidResetReportDescriptor(); - unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); - TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); - - hidPrepareReportDescriptor(); - reportDescPtr = hidGetReportDescriptor(); - TEST_ASSERT_NOT_NULL( reportDescPtr ); -} - -#endif \ No newline at end of file diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index f9a8d6a6..4ab9bac0 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -348,7 +348,7 @@ void test_bad_tag_hidSetReportItem( void ) const unsigned char page = CONSUMER_CONTROL_PAGE; for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) { - unsigned char bad_header = good_header | (( 0x0F << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ); + unsigned char bad_header = good_header | (( tag << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, bad_header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } From 1b186a0c2f5fd9767121ce5aef9e4587304c06fa Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 14:55:38 +0000 Subject: [PATCH 30/58] Remove test-specific information from hid_report_descriptor.h --- .../test_multi_report/hid_report_descriptor.h | 23 +----------------- .../test_multi_report/test_hid_multi_report.c | 24 +++++++++++++++---- .../src/test_simple/hid_report_descriptor.h | 12 ---------- .../xua_unit_tests/src/test_simple/test_hid.c | 20 ++++++++++++---- 4 files changed, 35 insertions(+), 44 deletions(-) diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h index 75721cbf..6acefced 100644 --- a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -6,21 +6,6 @@ #include "xua_hid_report_descriptor.h" -#define REPORT1_MAX_VALID_BIT ( 3 ) -#define REPORT1_MAX_VALID_BYTE ( 0 ) -#define REPORT1_MIN_VALID_BIT ( 0 ) -#define REPORT1_MIN_VALID_BYTE ( 0 ) - -#define REPORT2_MAX_VALID_BIT ( 7 ) -#define REPORT2_MAX_VALID_BYTE ( 1 ) -#define REPORT2_MIN_VALID_BIT ( 0 ) -#define REPORT2_MIN_VALID_BYTE ( 0 ) - -#define REPORT3_MAX_VALID_BIT ( 1 ) -#define REPORT3_MAX_VALID_BYTE ( 0 ) -#define REPORT3_MIN_VALID_BIT ( 0 ) -#define REPORT3_MIN_VALID_BYTE ( 0 ) - #define USB_HID_REPORT_ID_KEYBOARD ( 0x01 ) #define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) #define USB_HID_REPORT_ID_TELEPHONY ( 0x03 ) @@ -155,7 +140,7 @@ static USB_HID_Report_Element_t* const hidConfigurableElements[] = { }; /* - * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * List HID Reports, one per Report ID. This should be a usage page item with the locator filled out with ID and size * If not using report IDs - still have one with report ID 0 */ static const USB_HID_Report_Element_t* const hidReports[] = { @@ -235,12 +220,6 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { &hidCollectionEnd }; -/* - * Define the length of the HID Report. - * This value must match the number of Report bytes defined by hidReportDescriptorItems. - */ -#define HID_REPORT_LENGTH ( 3 ) - /* * Define the number of HID Reports * Due to XC not supporting designated initializers, this constant has a hard-coded value. diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index cc5a2371..17024e6e 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -5,13 +5,27 @@ #include "xua_unit_tests.h" #include "xua_hid_report_descriptor.h" -#include "hid_report_descriptor.h" -#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) -#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) -#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) -#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) +// Test constants related to the report descriptor defined in hid_report_descriptor.h +#define REPORT1_MAX_VALID_BIT ( 3 ) +#define REPORT1_MAX_VALID_BYTE ( 0 ) +#define REPORT1_MIN_VALID_BIT ( 0 ) +#define REPORT1_MIN_VALID_BYTE ( 0 ) +#define REPORT2_MAX_VALID_BIT ( 7 ) +#define REPORT2_MAX_VALID_BYTE ( 1 ) +#define REPORT2_MIN_VALID_BIT ( 0 ) +#define REPORT2_MIN_VALID_BYTE ( 0 ) + +#define REPORT3_MAX_VALID_BIT ( 1 ) +#define REPORT3_MAX_VALID_BYTE ( 0 ) +#define REPORT3_MIN_VALID_BIT ( 0 ) +#define REPORT3_MIN_VALID_BYTE ( 0 ) + +#define HID_REPORT_LENGTH ( 3 ) +#define HID_REPORT_COUNT ( 3 ) + +// Constants from USB HID Usage Tables #define KEYBOARD_PAGE ( 0x07 ) #define CONSUMER_PAGE ( 0x0C ) #define TELEPHONY_DEVICE_PAGE ( 0x0B ) diff --git a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h index aad5bb49..561c8f28 100644 --- a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h @@ -6,12 +6,6 @@ #include "xua_hid_report_descriptor.h" -#define MAX_VALID_BIT ( 7 ) -#define MAX_VALID_BYTE ( 1 ) - -#define MIN_VALID_BIT ( 0 ) -#define MIN_VALID_BYTE ( 0 ) - #define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) /* @@ -112,12 +106,6 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { &hidCollectionEnd }; -/* - * Define the length of the HID Report. - * This value must match the number of Report bytes defined by hidReportDescriptorItems. - */ -#define HID_REPORT_LENGTH ( 2 ) - /* * Define the number of HID Reports * Due to XC not supporting designated initializers, this constant has a hard-coded value. diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 4ab9bac0..11353744 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -5,17 +5,27 @@ #include "xua_unit_tests.h" #include "xua_hid_report_descriptor.h" -#include "hid_report_descriptor.h" + +// Test constants related to the report descriptor defined in hid_report_descriptor.h +#define MAX_VALID_BIT ( 7 ) +#define MAX_VALID_BYTE ( 1 ) + +#define MIN_VALID_BIT ( 0 ) +#define MIN_VALID_BYTE ( 0 ) + +#define HID_REPORT_LENGTH ( 2 ) +#define HID_REPORT_COUNT ( 1 ) + +// Constants from the USB HID Usage Tables +#define CONSUMER_CONTROL_PAGE ( 0x0C ) +#define LOUDNESS_CONTROL ( 0xE7 ) +#define AL_CONTROL_PANEL ( 0x019F ) #define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) #define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) #define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) #define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) -#define CONSUMER_CONTROL_PAGE ( 0x0C ) -#define LOUDNESS_CONTROL ( 0xE7 ) -#define AL_CONTROL_PANEL ( 0x019F ) - static unsigned construct_usage_header( unsigned size ) { unsigned header = 0x00; From 2b96ea017188e4fbfc233f8ad7a8154f73a7195f Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 9 Dec 2021 15:29:45 +0000 Subject: [PATCH 31/58] Increment major version and add change log entries --- CHANGELOG.rst | 7 +++++++ lib_xua/module_build_info | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7de64616..90f7b6cc 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ lib_xua Change Log ================== +3.0.0 +----- + + * ADDED: Support for HID Report IDs + * REMOVED: Support for HID Reports containing controls from mixed Usage + pages + 2.1.1 ----- diff --git a/lib_xua/module_build_info b/lib_xua/module_build_info index 39b0476e..e566c11b 100644 --- a/lib_xua/module_build_info +++ b/lib_xua/module_build_info @@ -1,4 +1,4 @@ -VERSION = 2.1.1 +VERSION = 3.0.0 DEPENDENT_MODULES = lib_logging(>=3.0.0) \ lib_xassert(>=4.0.0) \ From 08ed5ee668717fc787c03843cea9659d6f536d8c Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 9 Dec 2021 15:44:19 +0000 Subject: [PATCH 32/58] Renamed hid_report_descriptor.c to hid_report.c --- lib_xua/src/hid/{hid_report_descriptor.c => hid_report.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib_xua/src/hid/{hid_report_descriptor.c => hid_report.c} (100%) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report.c similarity index 100% rename from lib_xua/src/hid/hid_report_descriptor.c rename to lib_xua/src/hid/hid_report.c From 03a50245208a14255573221f92842029369cf682 Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 9 Dec 2021 15:45:05 +0000 Subject: [PATCH 33/58] Renamed xua_hid_report_descriptor.h to xua_hid_report.h --- CHANGELOG.rst | 2 ++ examples/AN00246_xua_example/src/hid_report_descriptor.h | 2 +- .../AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h | 2 +- .../AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h | 2 +- legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h | 2 +- .../src/hid/{xua_hid_report_descriptor.h => xua_hid_report.h} | 0 6 files changed, 6 insertions(+), 4 deletions(-) rename lib_xua/src/hid/{xua_hid_report_descriptor.h => xua_hid_report.h} (100%) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 90f7b6cc..518aab7b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,8 @@ lib_xua Change Log * ADDED: Support for HID Report IDs * REMOVED: Support for HID Reports containing controls from mixed Usage pages + * CHANGED: Renamed the HID API file xua_hid_report_descriptor.h to + xua_hid_report.h 2.1.1 ----- diff --git a/examples/AN00246_xua_example/src/hid_report_descriptor.h b/examples/AN00246_xua_example/src/hid_report_descriptor.h index a049576e..ec2c13e5 100644 --- a/examples/AN00246_xua_example/src/hid_report_descriptor.h +++ b/examples/AN00246_xua_example/src/hid_report_descriptor.h @@ -3,7 +3,7 @@ #ifndef __hid_report_descriptor_h__ #define __hid_report_descriptor_h__ -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #if 0 /* Existing static report descriptor kept for reference */ diff --git a/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h b/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h index a049576e..ec2c13e5 100644 --- a/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h +++ b/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h @@ -3,7 +3,7 @@ #ifndef __hid_report_descriptor_h__ #define __hid_report_descriptor_h__ -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #if 0 /* Existing static report descriptor kept for reference */ diff --git a/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h b/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h index a049576e..ec2c13e5 100644 --- a/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h +++ b/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h @@ -3,7 +3,7 @@ #ifndef __hid_report_descriptor_h__ #define __hid_report_descriptor_h__ -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #if 0 /* Existing static report descriptor kept for reference */ diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h index a049576e..ec2c13e5 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -3,7 +3,7 @@ #ifndef __hid_report_descriptor_h__ #define __hid_report_descriptor_h__ -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #if 0 /* Existing static report descriptor kept for reference */ diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report.h similarity index 100% rename from lib_xua/src/hid/xua_hid_report_descriptor.h rename to lib_xua/src/hid/xua_hid_report.h From 26cac1abb1f183c51bc20be2e12337c70813f503 Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 9 Dec 2021 15:58:51 +0000 Subject: [PATCH 34/58] Update includes of xua_hid_report.h --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 2 +- lib_xua/src/core/endpoint0/xua_endpoint0.c | 2 +- lib_xua/src/hid/hid.xc | 2 +- lib_xua/src/hid/hid_report.c | 2 +- tests/xua_unit_tests/src/test_hid.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 27b25751..0324bc0b 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -21,7 +21,7 @@ #include "testct_byref.h" #if( 0 < HID_CONTROLS ) -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #include "user_hid.h" #include "xua_hid.h" unsigned char g_hidData[HID_MAX_DATA_BYTES] = {0}; diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index a89f6330..deceb05c 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -28,7 +28,7 @@ #if( 0 < HID_CONTROLS ) #include "hid.h" #include "xua_hid.h" -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #endif #if DSD_CHANS_DAC > 0 diff --git a/lib_xua/src/hid/hid.xc b/lib_xua/src/hid/hid.xc index 83286bce..fd8f6fab 100644 --- a/lib_xua/src/hid/hid.xc +++ b/lib_xua/src/hid/hid.xc @@ -7,7 +7,7 @@ #include "xud.h" #include "xud_std_requests.h" #include "xua_hid.h" -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #if( 0 < HID_CONTROLS ) static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod ); diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index b046a2e5..f23fc42a 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -4,7 +4,7 @@ #include #include #include "descriptor_defs.h" -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #include "hid_report_descriptor.h" #include diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_hid.c index 965c7f90..b21d0333 100644 --- a/tests/xua_unit_tests/src/test_hid.c +++ b/tests/xua_unit_tests/src/test_hid.c @@ -4,7 +4,7 @@ #include #include "xua_unit_tests.h" -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #include "hid_report_descriptor.h" #define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) From 19be25809b32289c22cbf6eff544dd2e535d84ac Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 16:10:28 +0000 Subject: [PATCH 35/58] Fix implementation of hidGetReportIdLimit to match docs & usage --- lib_xua/src/hid/hid_report_descriptor.c | 10 +++++++++- .../src/test_multi_report/test_hid_multi_report.c | 7 +++++++ tests/xua_unit_tests/src/test_simple/test_hid.c | 14 +++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 9de4810a..cadefca4 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -229,7 +229,15 @@ size_t hidGetReportDescriptorLength( void ) } unsigned hidGetReportIdLimit ( void ) { - return HID_REPORT_COUNT; + unsigned retVal = 0U; + + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + unsigned reportId = hidGetElementReportId( hidReports[ idx ]->location ); + if( reportId >= retVal ) { + retVal = reportId + 1; + } + } + return retVal; } #define HID_CONFIGURABLE_ELEMENT_COUNT ( sizeof hidConfigurableElements / sizeof ( USB_HID_Report_Element_t* )) diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index 17024e6e..0a720ee3 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -24,6 +24,7 @@ #define HID_REPORT_LENGTH ( 3 ) #define HID_REPORT_COUNT ( 3 ) +#define HID_REPORTID_LIMIT ( 4 ) // Constants from USB HID Usage Tables #define KEYBOARD_PAGE ( 0x07 ) @@ -113,6 +114,12 @@ void test_reset_prepared_hidGetReportDescriptor( void ) TEST_ASSERT_NOT_NULL( reportDescPtr ); } +void test_report_id_limit( void ) +{ + unsigned reportIdLimit = hidGetReportIdLimit(); + TEST_ASSERT_EQUAL_UINT( HID_REPORTID_LIMIT, reportIdLimit ); +} + // Basic item tests void test_max_loc_hidGetReportItem( void ) { diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 11353744..2d8a675a 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -13,17 +13,19 @@ #define MIN_VALID_BIT ( 0 ) #define MIN_VALID_BYTE ( 0 ) -#define HID_REPORT_LENGTH ( 2 ) -#define HID_REPORT_COUNT ( 1 ) +#define HID_REPORT_LENGTH ( 2 ) +#define HID_REPORT_COUNT ( 1 ) +#define HID_REPORTID_LIMIT ( 1 ) // Constants from the USB HID Usage Tables #define CONSUMER_CONTROL_PAGE ( 0x0C ) #define LOUDNESS_CONTROL ( 0xE7 ) #define AL_CONTROL_PANEL ( 0x019F ) +// Constants from the USB Device Class Definition for HID +#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) #define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) #define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) -#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) #define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) static unsigned construct_usage_header( unsigned size ) @@ -82,6 +84,12 @@ void test_reset_prepared_hidGetReportDescriptor( void ) TEST_ASSERT_NOT_NULL( reportDescPtr ); } +void test_report_id_limit( void ) +{ + unsigned reportIdLimit = hidGetReportIdLimit(); + TEST_ASSERT_EQUAL_UINT( HID_REPORTID_LIMIT, reportIdLimit ); +} + // Basic item tests void test_max_loc_hidGetReportItem( void ) { From 2b5dab51b5eae8188e6d3c2c049bd92ef4461f87 Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 9 Dec 2021 16:15:29 +0000 Subject: [PATCH 36/58] Add explicit initialization of static variables in hid_report.c --- lib_xua/src/core/endpoint0/xua_endpoint0.c | 1 + lib_xua/src/hid/hid_report.c | 21 ++++++++++++++------- lib_xua/src/hid/xua_hid_report.h | 7 +++++++ tests/xua_unit_tests/src/test_hid.c | 6 ++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index deceb05c..b282319b 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -525,6 +525,7 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c #endif #if( 0 < HID_CONTROLS ) + hidReportInit(); hidPrepareReportDescriptor(); size_t hidReportDescriptorLength = hidGetReportDescriptorLength(); diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index f23fc42a..124e9e35 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -16,15 +16,15 @@ /* * Each element in s_hidChangePending corresponds to an element in hidReports. */ -static unsigned s_hidChangePending[ HID_REPORT_COUNT ] = { 0U }; +static unsigned s_hidChangePending[ HID_REPORT_COUNT ]; static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; -static size_t s_hidReportDescriptorLength = 0U; -static unsigned s_hidReportDescriptorPrepared = 0U; +static size_t s_hidReportDescriptorLength; +static unsigned s_hidReportDescriptorPrepared; -static unsigned s_hidCurrentPeriod[ HID_REPORT_COUNT ] = { ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS }; -static unsigned s_hidIdleActive[ HID_REPORT_COUNT ] = { 0U }; -static unsigned s_hidNextReportTime[ HID_REPORT_COUNT ] = { 0U }; -static unsigned s_hidReportTime[ HID_REPORT_COUNT ] = { 0U }; +static unsigned s_hidCurrentPeriod[ HID_REPORT_COUNT ]; +static unsigned s_hidIdleActive[ HID_REPORT_COUNT ]; +static unsigned s_hidNextReportTime[ HID_REPORT_COUNT ]; +static unsigned s_hidReportTime[ HID_REPORT_COUNT ]; /** * @brief Get the bit position from the location of a report element @@ -362,6 +362,13 @@ void hidPrepareReportDescriptor( void ) } } +void hidReportInit( void ) +{ + for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; + } +} + void hidResetReportDescriptor( void ) { s_hidReportDescriptorPrepared = 0U; diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 8043d1c3..65d51c2c 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -350,6 +350,13 @@ unsigned hidIsIdleActive( const unsigned id ); */ void hidPrepareReportDescriptor( void ); +/** + * @brief Initialise the USB HID Report functionality + * + * Call this function before using any other functions in this API. + */ +void hidReportInit( void ); + /** * @brief Reset the USB HID Report descriptor * diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_hid.c index b21d0333..75e5a6c4 100644 --- a/tests/xua_unit_tests/src/test_hid.c +++ b/tests/xua_unit_tests/src/test_hid.c @@ -45,6 +45,7 @@ void test_unprepared_hidGetReportDescriptor( void ) void test_prepared_hidGetReportDescriptor( void ) { + hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); @@ -55,6 +56,7 @@ void test_prepared_hidGetReportDescriptor( void ) void test_reset_unprepared_hidGetReportDescriptor( void ) { + hidReportInit(); hidPrepareReportDescriptor(); hidResetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); @@ -63,6 +65,7 @@ void test_reset_unprepared_hidGetReportDescriptor( void ) void test_reset_prepared_hidGetReportDescriptor( void ) { + hidReportInit(); hidPrepareReportDescriptor(); hidResetReportDescriptor(); hidPrepareReportDescriptor(); @@ -404,6 +407,7 @@ void test_initial_modification_with_subsequent_preparation( void ) const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; + hidReportInit(); unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); @@ -484,6 +488,7 @@ void test_initial_modification_with_subsequent_verification_2( void ) void test_modification_without_subsequent_preparation( void ) { + hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); @@ -504,6 +509,7 @@ void test_modification_without_subsequent_preparation( void ) void test_modification_with_subsequent_preparation( void ) { + hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); From 353d7c3c8d3b95f03280bdab1431195d5c8eab0e Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 17:28:16 +0000 Subject: [PATCH 37/58] Fix merge issues --- .../src/test_multi_report/hid_report_descriptor.h | 2 +- .../src/test_multi_report/test_hid_multi_report.c | 3 ++- .../src/test_simple/hid_report_descriptor.h | 2 +- tests/xua_unit_tests/src/test_simple/test_hid.c | 8 ++------ 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h index 6acefced..e0549641 100644 --- a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -4,7 +4,7 @@ #ifndef __hid_report_descriptor_h__ #define __hid_report_descriptor_h__ -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #define USB_HID_REPORT_ID_KEYBOARD ( 0x01 ) #define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index 0a720ee3..96345e24 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -4,7 +4,7 @@ #include #include "xua_unit_tests.h" -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" // Test constants related to the report descriptor defined in hid_report_descriptor.h #define REPORT1_MAX_VALID_BIT ( 3 ) @@ -49,6 +49,7 @@ static unsigned construct_usage_header( unsigned size ) void setUp( void ) { + hidReportInit(); hidResetReportDescriptor(); } diff --git a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h index 561c8f28..a466879b 100644 --- a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h @@ -4,7 +4,7 @@ #ifndef __hid_report_descriptor_h__ #define __hid_report_descriptor_h__ -#include "xua_hid_report_descriptor.h" +#include "xua_hid_report.h" #define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 1da6dc7b..d7e3015c 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -42,6 +42,7 @@ static unsigned construct_usage_header( unsigned size ) void setUp( void ) { + hidReportInit(); hidResetReportDescriptor(); } @@ -59,7 +60,7 @@ void test_unprepared_hidGetReportDescriptor( void ) void test_prepared_hidGetReportDescriptor( void ) { const unsigned reportId = 0; - hidReportInit(); + hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); @@ -70,7 +71,6 @@ void test_prepared_hidGetReportDescriptor( void ) void test_reset_unprepared_hidGetReportDescriptor( void ) { - hidReportInit(); hidPrepareReportDescriptor(); hidResetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); @@ -79,7 +79,6 @@ void test_reset_unprepared_hidGetReportDescriptor( void ) void test_reset_prepared_hidGetReportDescriptor( void ) { - hidReportInit(); hidPrepareReportDescriptor(); hidResetReportDescriptor(); hidPrepareReportDescriptor(); @@ -453,7 +452,6 @@ void test_initial_modification_with_subsequent_preparation( void ) const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; - hidReportInit(); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); @@ -536,7 +534,6 @@ void test_initial_modification_with_subsequent_verification_2( void ) void test_modification_without_subsequent_preparation( void ) { - hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); @@ -558,7 +555,6 @@ void test_modification_without_subsequent_preparation( void ) void test_modification_with_subsequent_preparation( void ) { - hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); From f328deb336bf22eca98632c429379468f0a56c21 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 18:02:42 +0000 Subject: [PATCH 38/58] style --- .../app_test_i2s_loopback/hid_report_descriptor.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h index e2b9b4d8..a24c714d 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -29,21 +29,25 @@ unsigned char hidReportDescriptor[] = }; #endif -#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) -#define USB_HID_USAGE_PAGE_ID_CONSUMER (0x02) +#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) +#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x02 ) /* * Define non-configurable items in the HID Report descriptor. */ static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; + static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; + static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; + static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }}; static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; + static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }}; @@ -118,12 +122,6 @@ static const USB_HID_Report_Element_t* const hidReports[] = { &hidReportConsumer }; -/* - * Define the length of the HID Report. - * This value must match the number of Report bytes defined by hidReportDescriptorItems. - */ -#define HID_REPORT_LENGTH ( 1 ) - /* * Define the number of HID Reports * Due to XC not supporting designated initializers, this constant has a hard-coded value. From 3895b486ab96ed13654be3ef73fe7b6daf42eb3c Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Fri, 10 Dec 2021 10:45:54 +0000 Subject: [PATCH 39/58] Add constants header for common constants; helper macro for header --- .../src/hid_report_descriptor.h | 61 ++++++++++++----- .../hid_report_descriptor.h | 1 - lib_xua/src/hid/xua_hid_report.h | 35 +++++++++- .../hid/xua_hid_report_descriptor_constants.h | 65 +++++++++++++++++++ .../test_multi_report/hid_report_descriptor.h | 6 +- .../src/test_simple/hid_report_descriptor.h | 2 - .../xua_unit_tests/src/test_simple/test_hid.c | 6 -- 7 files changed, 141 insertions(+), 35 deletions(-) create mode 100644 lib_xua/src/hid/xua_hid_report_descriptor_constants.h diff --git a/examples/AN00246_xua_example/src/hid_report_descriptor.h b/examples/AN00246_xua_example/src/hid_report_descriptor.h index ec2c13e5..022e6af0 100644 --- a/examples/AN00246_xua_example/src/hid_report_descriptor.h +++ b/examples/AN00246_xua_example/src/hid_report_descriptor.h @@ -32,33 +32,58 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }, .location = 0x00 }; +/* + * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report + * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. + */ +static const USB_HID_Report_Element_t hidReportPageConsumer = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .location = HID_REPORT_SET_LOC( 0, 2, 0, 0 ) +}; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = 0x09, .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute -static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = 0x09, .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- -static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = 0x09, .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ -static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = 0x09, .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev -static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = 0x09, .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next -static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = 0x09, .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play +static USB_HID_Report_Element_t hidUsageByte0Bit5 = { + .item = { .header = 0x09, .data = { 0xE2, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 0, 5) +}; // Mute +static USB_HID_Report_Element_t hidUsageByte0Bit4 = { + .item = { .header = 0x09, .data = { 0xEA, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 0, 4) +}; // Vol- +static USB_HID_Report_Element_t hidUsageByte0Bit3 = { + .item = { .header = 0x09, .data = { 0xE9, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 0, 3) +}; // Vol+ +static USB_HID_Report_Element_t hidUsageByte0Bit2 = { + .item = { .header = 0x09, .data = { 0xB6, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 0, 2) +}; // Scan Prev +static USB_HID_Report_Element_t hidUsageByte0Bit1 = { + .item = { .header = 0x09, .data = { 0xB5, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 0, 1) +}; // Scan Next +static USB_HID_Report_Element_t hidUsageByte0Bit0 = { + .item = { .header = 0x09, .data = { 0xB0, 0x00 }}, + .location = HID_REPORT_SET_LOC(0, 0, 0, 0) +}; // Play /* * List the configurable items in the HID Report descriptor. diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h index a24c714d..b473b0a4 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -30,7 +30,6 @@ unsigned char hidReportDescriptor[] = #endif #define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) -#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x02 ) /* * Define non-configurable items in the HID Report descriptor. diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 65d51c2c..7fa1d846 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -13,11 +13,13 @@ * Document section numbers refer to the HID Device Class Definition, version 1.11. */ -#ifndef _HID_REPORT_DESCRIPTOR_ -#define _HID_REPORT_DESCRIPTOR_ +#ifndef _XUA_HID_REPORT_ +#define _XUA_HID_REPORT_ #include +#include "xua_hid_report_descriptor_constants.h" + #define HID_REPORT_ITEM_HDR_SIZE_MASK ( 0x03 ) #define HID_REPORT_ITEM_HDR_SIZE_SHIFT ( 0U ) @@ -44,12 +46,39 @@ #define HID_REPORT_ITEM_USAGE_TAG ( 0U ) #define HID_REPORT_ITEM_USAGE_TYPE ( 2U ) +// Constants from the USB Device Class Definition for HID +#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) +#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) +#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) +#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) + +/** + * @brief Helper macro to configure the location field of USB_HID_Report_Element_t. + * + * @param id The report ID that this element is within. + * @param len (only relevant for the usage_page elements in hidReports) The length + * of the report under this report ID. + * @param byte The byte location of this element in the report. + * @param bit The bit location (within the byte) of this element in the report. + */ #define HID_REPORT_SET_LOC(id, len, byte, bit) (\ (( id << HID_REPORT_ELEMENT_LOC_ID_SHIFT ) & HID_REPORT_ELEMENT_LOC_ID_MASK ) | \ (( len << HID_REPORT_ELEMENT_LOC_LEN_SHIFT ) & HID_REPORT_ELEMENT_LOC_LEN_MASK ) | \ (( byte << HID_REPORT_ELEMENT_LOC_BYTE_SHIFT ) & HID_REPORT_ELEMENT_LOC_BYTE_MASK ) | \ (( bit << HID_REPORT_ELEMENT_LOC_BIT_SHIFT ) & HID_REPORT_ELEMENT_LOC_BIT_MASK )) +/** + * @brief Helper macro to configure the header field of USB_HID_Short_Item_t + * + * @param size The size of the report descriptor item (valid values: 0, 1, 2) + * @param type The type of the report descriptor item + * @param tag The tag + */ +#define HID_REPORT_SET_HEADER(size, type, tag) (\ + (( size << HID_REPORT_ITEM_HDR_SIZE_SHIFT) & HID_REPORT_ITEM_HDR_SIZE_MASK ) |\ + (( type << HID_REPORT_ITEM_HDR_TYPE_SHIFT) & HID_REPORT_ITEM_HDR_TYPE_MASK ) |\ + (( tag << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_SHIFT ) ) + #define HID_STATUS_GOOD ( 0U ) #define HID_STATUS_BAD_HEADER ( 1U ) #define HID_STATUS_BAD_ID ( 2U ) @@ -473,4 +502,4 @@ unsigned hidSetReportItem( */ void hidSetReportPeriod( const unsigned id, const unsigned period ); -#endif // _HID_REPORT_DESCRIPTOR_ +#endif // _XUA_HID_REPORT_ diff --git a/lib_xua/src/hid/xua_hid_report_descriptor_constants.h b/lib_xua/src/hid/xua_hid_report_descriptor_constants.h new file mode 100644 index 00000000..893c2101 --- /dev/null +++ b/lib_xua/src/hid/xua_hid_report_descriptor_constants.h @@ -0,0 +1,65 @@ +// Copyright 2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +/** + * @brief Human Interface Device (HID) Report descriptor constants + * + * This file defines a collection of constants from the USB HID documents. + * This includes constants from: + * - Device Class Definition for Human Interface Devices, version 1.11 + * - HID Usage Tables for Universal Serial Bus, version 1.22 + * + * This file is incomplete, but can be expanded with new constants as necessary. + */ + +#ifndef _XUA_HID_REPORT_DESCRIPTOR_CONSTANTS_ +#define _XUA_HID_REPORT_DESCRIPTOR_CONSTANTS_ + + +// Constants from the USB Device Class Definition for HID for type +#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) +#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) +#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) +#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) + +// Constants from the USB Device Class Definition for HID for tag +// Main items +#define HID_REPORT_ITEM_TAG_INPUT ( 0x08 ) +#define HID_REPORT_ITEM_TAG_OUTPUT ( 0x09 ) +#define HID_REPORT_ITEM_TAG_FEATURE ( 0x0B ) +#define HID_REPORT_ITEM_TAG_COLLECTION ( 0x0A ) +#define HID_REPORT_ITEM_TAG_END_COLLECTION ( 0x0C ) + +// Global items +#define HID_REPORT_ITEM_TAG_USAGE_PAGE ( 0x00 ) +#define HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM ( 0x01 ) +#define HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM ( 0x02 ) +#define HID_REPORT_ITEM_TAG_PHYSICAL_MINIMUM ( 0x03 ) +#define HID_REPORT_ITEM_TAG_PHYSICAL_MAXIMUM ( 0x04 ) +#define HID_REPORT_ITEM_TAG_UNIT_EXPONENT ( 0x05 ) +#define HID_REPORT_ITEM_TAG_UNIT ( 0x06 ) +#define HID_REPORT_ITEM_TAG_REPORT_SIZE ( 0x07 ) +#define HID_REPORT_ITEM_TAG_REPORT_ID ( 0x08 ) +#define HID_REPORT_ITEM_TAG_REPORT_COUNT ( 0x09 ) +#define HID_REPORT_ITEM_TAG_PUSH ( 0x0A ) +#define HID_REPORT_ITEM_TAG_POP ( 0x0B ) + +// Local items +#define HID_REPORT_ITEM_TAG_USAGE ( 0x00 ) +#define HID_REPORT_ITEM_TAG_USAGE_MINIMUM ( 0x01 ) +#define HID_REPORT_ITEM_TAG_USAGE_MAXIMUM ( 0x02 ) +#define HID_REPORT_ITEM_TAG_DESIGNATOR_INDEX ( 0x03 ) +#define HID_REPORT_ITEM_TAG_DESIGNATOR_MINIMUM ( 0x04 ) +#define HID_REPORT_ITEM_TAG_DESIGNATOR_MAXIMUM ( 0x05 ) +#define HID_REPORT_ITEM_TAG_STRING_INDEX ( 0x07 ) +#define HID_REPORT_ITEM_TAG_STRING_MINIMUM ( 0x08 ) +#define HID_REPORT_ITEM_TAG_STRING_MAXIMUM ( 0x09 ) +#define HID_REPORT_ITEM_TAG_DELIMITER ( 0x0A ) + +// Constants from HID Usage Tables +// Usage page IDs +#define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 ) +#define USB_HID_USAGE_PAGE_ID_TELEPHONY_DEVICE ( 0x0B ) +#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) + +#endif // _XUA_HID_REPORT_DESCRIPTOR_CONSTANTS_ diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h index e0549641..9fe77d05 100644 --- a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -10,10 +10,6 @@ #define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) #define USB_HID_REPORT_ID_TELEPHONY ( 0x03 ) -#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) -#define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 ) -#define USB_HID_USAGE_PAGE_ID_TELEPHONY ( 0x0B ) - /* * Define non-configurable items in the HID Report descriptor. * (These are short items as the location field isn't relevant for them) @@ -55,7 +51,7 @@ static const USB_HID_Report_Element_t hidReportConsumer = { }; static const USB_HID_Report_Element_t hidReportTelephony = { - .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY, 0x00 }}, + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY_DEVICE, 0x00 }}, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 1, 0, 0 ) }; diff --git a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h index a466879b..daf6194e 100644 --- a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h @@ -6,8 +6,6 @@ #include "xua_hid_report.h" -#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) - /* * Define non-configurable items in the HID Report descriptor. * (These are short items as the location field isn't relevant for them) diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index d7e3015c..5857895f 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -22,12 +22,6 @@ #define LOUDNESS_CONTROL ( 0xE7 ) #define AL_CONTROL_PANEL ( 0x019F ) -// Constants from the USB Device Class Definition for HID -#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) -#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) -#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) -#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) - static unsigned construct_usage_header( unsigned size ) { unsigned header = 0x00; From 548ccebb27a29ad53b73af50b257bf4b5f242796 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Fri, 10 Dec 2021 11:25:35 +0000 Subject: [PATCH 40/58] Propegate constants and helper macro around codebase --- .../src/hid_report_descriptor.h | 43 ++++--- .../src/hid_report_descriptor.h | 36 +++--- .../src/hid_report_descriptor.h | 36 +++--- .../hid_report_descriptor.h | 67 +++++++---- lib_xua/src/hid/xua_hid_report.h | 2 +- .../hid/xua_hid_report_descriptor_constants.h | 2 +- .../test_multi_report/hid_report_descriptor.h | 109 +++++++++++++----- .../src/test_simple/hid_report_descriptor.h | 64 +++++++--- 8 files changed, 235 insertions(+), 124 deletions(-) diff --git a/examples/AN00246_xua_example/src/hid_report_descriptor.h b/examples/AN00246_xua_example/src/hid_report_descriptor.h index 022e6af0..c0d2b64f 100644 --- a/examples/AN00246_xua_example/src/hid_report_descriptor.h +++ b/examples/AN00246_xua_example/src/hid_report_descriptor.h @@ -32,28 +32,29 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidInputConstArray = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 } }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0x01, 0x00 } }; /* * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. */ static const USB_HID_Report_Element_t hidReportPageConsumer = { - .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, .location = HID_REPORT_SET_LOC( 0, 2, 0, 0 ) }; @@ -61,27 +62,33 @@ static const USB_HID_Report_Element_t hidReportPageConsumer = { * Define configurable items in the HID Report descriptor. */ static USB_HID_Report_Element_t hidUsageByte0Bit5 = { - .item = { .header = 0x09, .data = { 0xE2, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE2, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 0, 5) }; // Mute static USB_HID_Report_Element_t hidUsageByte0Bit4 = { - .item = { .header = 0x09, .data = { 0xEA, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xEA, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 0, 4) }; // Vol- static USB_HID_Report_Element_t hidUsageByte0Bit3 = { - .item = { .header = 0x09, .data = { 0xE9, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE9, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 0, 3) }; // Vol+ static USB_HID_Report_Element_t hidUsageByte0Bit2 = { - .item = { .header = 0x09, .data = { 0xB6, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB6, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 0, 2) }; // Scan Prev static USB_HID_Report_Element_t hidUsageByte0Bit1 = { - .item = { .header = 0x09, .data = { 0xB5, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB5, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 0, 1) }; // Scan Next static USB_HID_Report_Element_t hidUsageByte0Bit0 = { - .item = { .header = 0x09, .data = { 0xB0, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB0, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 0, 0) }; // Play diff --git a/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h b/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h index ec2c13e5..9ca287c8 100644 --- a/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h +++ b/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h @@ -32,33 +32,33 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputConstArray = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), .data = { 0x0C, 0x00 }, .location = 0x00 }; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = 0x09, .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute -static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = 0x09, .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- -static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = 0x09, .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ -static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = 0x09, .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev -static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = 0x09, .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next -static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = 0x09, .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play +static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute +static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- +static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ +static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev +static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next +static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play /* * List the configurable items in the HID Report descriptor. diff --git a/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h b/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h index ec2c13e5..9ca287c8 100644 --- a/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h +++ b/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h @@ -32,33 +32,33 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputConstArray = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), .data = { 0x0C, 0x00 }, .location = 0x00 }; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = 0x09, .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute -static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = 0x09, .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- -static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = 0x09, .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ -static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = 0x09, .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev -static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = 0x09, .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next -static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = 0x09, .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play +static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute +static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- +static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ +static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev +static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next +static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play /* * List the configurable items in the HID Report descriptor. diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h index b473b0a4..f133eb7e 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -34,42 +34,69 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionApplication = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { + .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; +static const USB_HID_Short_Item_t hidInputConstArray = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }}; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount2 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x06, 0x00 } }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }}; +static const USB_HID_Short_Item_t hidReportSize1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidUsagePageConsumer = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .data = { 0x0C, 0x00 } }; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Report_Element_t hidUsageByte0Bit5 = { .item.header = 0x09, .item.data = { 0xE2, 0x00 }, +static USB_HID_Report_Element_t hidUsageByte0Bit5 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE2, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) }; // Mute -static USB_HID_Report_Element_t hidUsageByte0Bit4 = { .item.header = 0x09, .item.data = { 0xEA, 0x00 }, +static USB_HID_Report_Element_t hidUsageByte0Bit4 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xEA, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) }; // Vol- -static USB_HID_Report_Element_t hidUsageByte0Bit3 = { .item.header = 0x09, .item.data = { 0xE9, 0x00 }, +static USB_HID_Report_Element_t hidUsageByte0Bit3 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE9, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) }; // Vol+ -static USB_HID_Report_Element_t hidUsageByte0Bit2 = { .item.header = 0x09, .item.data = { 0xB6, 0x00 }, +static USB_HID_Report_Element_t hidUsageByte0Bit2 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB6, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) }; // Scan Prev -static USB_HID_Report_Element_t hidUsageByte0Bit1 = { .item.header = 0x09, .item.data = { 0xB5, 0x00 }, +static USB_HID_Report_Element_t hidUsageByte0Bit1 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB5, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) }; // Scan Next -static USB_HID_Report_Element_t hidUsageByte0Bit0 = { .item.header = 0x09, .item.data = { 0xB0, 0x00 }, +static USB_HID_Report_Element_t hidUsageByte0Bit0 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB0, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) }; // Play -static USB_HID_Short_Item_t hidReportID1 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00}}; +static USB_HID_Short_Item_t hidReportID1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_ID), + .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00} }; static const USB_HID_Report_Element_t hidReportConsumer = { - .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 ) }; diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 7fa1d846..218a590b 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -77,7 +77,7 @@ #define HID_REPORT_SET_HEADER(size, type, tag) (\ (( size << HID_REPORT_ITEM_HDR_SIZE_SHIFT) & HID_REPORT_ITEM_HDR_SIZE_MASK ) |\ (( type << HID_REPORT_ITEM_HDR_TYPE_SHIFT) & HID_REPORT_ITEM_HDR_TYPE_MASK ) |\ - (( tag << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_SHIFT ) ) + (( tag << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ) ) #define HID_STATUS_GOOD ( 0U ) #define HID_STATUS_BAD_HEADER ( 1U ) diff --git a/lib_xua/src/hid/xua_hid_report_descriptor_constants.h b/lib_xua/src/hid/xua_hid_report_descriptor_constants.h index 893c2101..0ff1c4de 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor_constants.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor_constants.h @@ -57,7 +57,7 @@ #define HID_REPORT_ITEM_TAG_DELIMITER ( 0x0A ) // Constants from HID Usage Tables -// Usage page IDs +// Usage page IDs (incomplete) #define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 ) #define USB_HID_USAGE_PAGE_ID_TELEPHONY_DEVICE ( 0x0B ) #define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h index 9fe77d05..68e2879d 100644 --- a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -14,104 +14,151 @@ * Define non-configurable items in the HID Report descriptor. * (These are short items as the location field isn't relevant for them) */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; -static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionApplication = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { + .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionLogical = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; +static const USB_HID_Short_Item_t hidInputConstArray = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidReportCount4 = { .header = 0x95, .data = { 0x04, 0x00 }}; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount4 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x04, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportSize1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), + .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .data = { 0x01, 0x00 } }; /* * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. */ -static const USB_HID_Short_Item_t hidReportId1 = { .header = 0x85, .data = { USB_HID_REPORT_ID_KEYBOARD, 0x00 }}; -static const USB_HID_Short_Item_t hidReportId2 = { .header = 0x85, .data = { USB_HID_REPORT_ID_CONSUMER, 0x00 }}; -static const USB_HID_Short_Item_t hidReportId3 = { .header = 0x85, .data = { USB_HID_REPORT_ID_TELEPHONY, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_ID), + .data = { USB_HID_REPORT_ID_KEYBOARD, 0x00 } }; +static const USB_HID_Short_Item_t hidReportId2 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_ID), + .data = { USB_HID_REPORT_ID_CONSUMER, 0x00 } }; +static const USB_HID_Short_Item_t hidReportId3 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_ID), + .data = { USB_HID_REPORT_ID_TELEPHONY, 0x00 } }; static const USB_HID_Report_Element_t hidReportKeyboard = { - .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 1, 0, 0 ) }; static const USB_HID_Report_Element_t hidReportConsumer = { - .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 2, 0, 0 ) }; static const USB_HID_Report_Element_t hidReportTelephony = { - .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY_DEVICE, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_TELEPHONY_DEVICE, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 1, 0, 0 ) }; static USB_HID_Report_Element_t hidUsageReport1Byte0Bit0 = { - .item = { .header = 0x09, .data = { 0x17, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0x17, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 0 ) }; // 't' static USB_HID_Report_Element_t hidUsageReport1Byte0Bit2 = { - .item = { .header = 0x09, .data = { 0x72, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0x72, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 2 ) }; // F23 static USB_HID_Report_Element_t hidUsageReport1Byte0Bit3 = { - .item = { .header = 0x09, .data = { 0x73, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0x73, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 3 ) }; // F24 static USB_HID_Report_Element_t hidUsageReport2Byte0Bit0 = { - .item = { .header = 0x0A, .data = { 0x26, 0x02 }}, + .item.header = HID_REPORT_SET_HEADER(2, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0x26, 0x02 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) }; // AC Stop static USB_HID_Report_Element_t hidUsageReport2Byte0Bit1 = { - .item = { .header = 0x0A, .data = { 0x21, 0x02 }}, + .item.header = HID_REPORT_SET_HEADER(2, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0x21, 0x02 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) }; // AC Search static USB_HID_Report_Element_t hidUsageReport2Byte0Bit2 = { - .item = { .header = 0x09, .data = { 0xE2, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE2, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) }; // Mute static USB_HID_Report_Element_t hidUsageReport2Byte0Bit4 = { - .item = { .header = 0x09, .data = { 0xCF, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xCF, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) }; // Voice Command static USB_HID_Report_Element_t hidUsageReport2Byte0Bit6 = { - .item = { .header = 0x09, .data = { 0xE9, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE9, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 6 ) }; // Vol+ static USB_HID_Report_Element_t hidUsageReport2Byte0Bit7 = { - .item = { .header = 0x09, .data = { 0xEA, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xEA, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 7 ) }; // Vol- static USB_HID_Report_Element_t hidUsageReport2Byte1Bit7 = { - .item = { .header = 0x09, .data = { 0xE5, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE5, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 1, 7 ) }; // Bass boost static USB_HID_Report_Element_t hidUsageReport3Byte0Bit0 = { - .item = { .header = 0x09, .data = { 0x20, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0x20, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 0 ) }; // Hook Switch static USB_HID_Report_Element_t hidUsageReport3Byte0Bit1 = { - .item = { .header = 0x09, .data = { 0x2F, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0x2F, 0x00 }, .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 1 ) }; // Phone Mute diff --git a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h index daf6194e..a0771470 100644 --- a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h @@ -10,30 +10,57 @@ * Define non-configurable items in the HID Report descriptor. * (These are short items as the location field isn't relevant for them) */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; -static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionApplication = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { + .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionLogical = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; +static const USB_HID_Short_Item_t hidInputConstArray = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }}; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; -static const USB_HID_Short_Item_t hidReportCount7 = { .header = 0x95, .data = { 0x07, 0x00 }}; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount7 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x07, 0x00 } }; +static const USB_HID_Short_Item_t hidReportSize1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), + .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .data = { 0x01, 0x00 } }; /* * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. */ static const USB_HID_Report_Element_t hidReportPageConsumer = { - .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, .location = HID_REPORT_SET_LOC( 0, 2, 0, 0 ) }; @@ -41,16 +68,19 @@ static const USB_HID_Report_Element_t hidReportPageConsumer = { * Define configurable items in the HID Report descriptor. */ static USB_HID_Report_Element_t hidUsageByte0Bit0 = { - .item = { .header = 0x09, .data = { 0xE2, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE2, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 0, 0) }; // Mute static USB_HID_Report_Element_t hidUsageByte1Bit7 = { - .item = { .header = 0x09, .data = { 0xEA, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xEA, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 1, 7) }; // Vol- static USB_HID_Report_Element_t hidUsageByte1Bit0 = { - .item = { .header = 0x09, .data = { 0xE9, 0x00 }}, + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE9, 0x00 }, .location = HID_REPORT_SET_LOC(0, 0, 1, 0) }; // Vol+ From e41aed6ffbe0403a0d18872d99436b41d8a64a67 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Fri, 10 Dec 2021 11:43:51 +0000 Subject: [PATCH 41/58] Update examples to work with new API --- .../src/hid_report_descriptor.h | 76 +++++++---- .../src/hid_report_descriptor.h | 122 +++++++++++++----- .../src/hid_report_descriptor.h | 122 +++++++++++++----- 3 files changed, 228 insertions(+), 92 deletions(-) diff --git a/examples/AN00246_xua_example/src/hid_report_descriptor.h b/examples/AN00246_xua_example/src/hid_report_descriptor.h index c0d2b64f..cd789971 100644 --- a/examples/AN00246_xua_example/src/hid_report_descriptor.h +++ b/examples/AN00246_xua_example/src/hid_report_descriptor.h @@ -32,21 +32,43 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionApplication = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { + .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidInputConstArray = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 } }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount2 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportSize1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), + .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .data = { 0x01, 0x00 } }; /* * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report @@ -93,9 +115,9 @@ static USB_HID_Report_Element_t hidUsageByte0Bit0 = { }; // Play /* - * List the configurable items in the HID Report descriptor. + * List the configurable elements in the HID Report descriptor. */ -static USB_HID_Short_Item_t* const hidConfigurableItems[] = { +static USB_HID_Report_Element_t* const hidConfigurableElements[] = { &hidUsageByte0Bit0, &hidUsageByte0Bit1, &hidUsageByte0Bit2, @@ -105,27 +127,28 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { }; /* - * List Usage pages in the HID Report descriptor, one per byte. + * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * If not using report IDs - still have one with report ID 0 */ -static const USB_HID_Short_Item_t* const hidUsagePages[] = { - &hidUsagePageConsumer +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportPageConsumer }; /* * List all items in the HID Report descriptor. */ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { - &hidUsagePageConsumer, + &(hidReportPageConsumer.item), &hidUsageConsumerControl, &hidCollectionApplication, &hidLogicalMinimum0, &hidLogicalMaximum1, - &hidUsageByte0Bit0, - &hidUsageByte0Bit1, - &hidUsageByte0Bit2, - &hidUsageByte0Bit3, - &hidUsageByte0Bit4, - &hidUsageByte0Bit5, + &(hidUsageByte0Bit0.item), + &(hidUsageByte0Bit1.item), + &(hidUsageByte0Bit2.item), + &(hidUsageByte0Bit3.item), + &(hidUsageByte0Bit4.item), + &(hidUsageByte0Bit5.item), &hidReportSize1, &hidReportCount6, &hidInputDataVar, @@ -136,9 +159,10 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { }; /* - * Define the length of the HID Report. - * This value must match the number of Report bytes defined by hidReportDescriptorItems. + * Define the number of HID Reports + * Due to XC not supporting designated initializers, this constant has a hard-coded value. + * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) */ -#define HID_REPORT_LENGTH ( 1 ) +#define HID_REPORT_COUNT ( 1 ) #endif // __hid_report_descriptor_h__ diff --git a/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h b/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h index 9ca287c8..cd789971 100644 --- a/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h +++ b/examples/AN00247_xua_example_spdif_tx/src/hid_report_descriptor.h @@ -32,38 +32,92 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionApplication = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { + .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputConstArray = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount2 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportSize1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), + .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), .data = { 0x0C, 0x00 }, .location = 0x00 }; +/* + * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report + * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. + */ +static const USB_HID_Report_Element_t hidReportPageConsumer = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, + .location = HID_REPORT_SET_LOC( 0, 2, 0, 0 ) +}; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute -static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- -static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ -static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev -static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next -static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play +static USB_HID_Report_Element_t hidUsageByte0Bit5 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE2, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 5) +}; // Mute +static USB_HID_Report_Element_t hidUsageByte0Bit4 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xEA, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 4) +}; // Vol- +static USB_HID_Report_Element_t hidUsageByte0Bit3 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE9, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 3) +}; // Vol+ +static USB_HID_Report_Element_t hidUsageByte0Bit2 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB6, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 2) +}; // Scan Prev +static USB_HID_Report_Element_t hidUsageByte0Bit1 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB5, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 1) +}; // Scan Next +static USB_HID_Report_Element_t hidUsageByte0Bit0 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB0, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 0) +}; // Play /* - * List the configurable items in the HID Report descriptor. + * List the configurable elements in the HID Report descriptor. */ -static USB_HID_Short_Item_t* const hidConfigurableItems[] = { +static USB_HID_Report_Element_t* const hidConfigurableElements[] = { &hidUsageByte0Bit0, &hidUsageByte0Bit1, &hidUsageByte0Bit2, @@ -73,27 +127,28 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { }; /* - * List Usage pages in the HID Report descriptor, one per byte. + * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * If not using report IDs - still have one with report ID 0 */ -static const USB_HID_Short_Item_t* const hidUsagePages[] = { - &hidUsagePageConsumer +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportPageConsumer }; /* * List all items in the HID Report descriptor. */ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { - &hidUsagePageConsumer, + &(hidReportPageConsumer.item), &hidUsageConsumerControl, &hidCollectionApplication, &hidLogicalMinimum0, &hidLogicalMaximum1, - &hidUsageByte0Bit0, - &hidUsageByte0Bit1, - &hidUsageByte0Bit2, - &hidUsageByte0Bit3, - &hidUsageByte0Bit4, - &hidUsageByte0Bit5, + &(hidUsageByte0Bit0.item), + &(hidUsageByte0Bit1.item), + &(hidUsageByte0Bit2.item), + &(hidUsageByte0Bit3.item), + &(hidUsageByte0Bit4.item), + &(hidUsageByte0Bit5.item), &hidReportSize1, &hidReportCount6, &hidInputDataVar, @@ -104,9 +159,10 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { }; /* - * Define the length of the HID Report. - * This value must match the number of Report bytes defined by hidReportDescriptorItems. + * Define the number of HID Reports + * Due to XC not supporting designated initializers, this constant has a hard-coded value. + * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) */ -#define HID_REPORT_LENGTH ( 1 ) +#define HID_REPORT_COUNT ( 1 ) #endif // __hid_report_descriptor_h__ diff --git a/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h b/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h index 9ca287c8..cd789971 100644 --- a/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h +++ b/examples/AN00248_xua_example_pdm_mics/src/hid_report_descriptor.h @@ -32,38 +32,92 @@ unsigned char hidReportDescriptor[] = /* * Define non-configurable items in the HID Report descriptor. */ -static const USB_HID_Short_Item_t hidCollectionApplication = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidCollectionEnd = { .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidCollectionApplication = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidCollectionEnd = { + .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidInputConstArray = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidInputDataVar = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), .data = { 0x02, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidInputConstArray = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidInputDataVar = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), + .data = { 0x02, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), .data = { 0x01, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), .data = { 0x00, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x00, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), + .data = { 0x01, 0x00 } }; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), + .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x02, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 }, .location = 0x00 }; -static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidReportCount2 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x02, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount6 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportSize1 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), + .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0x01, 0x00 }, .location = 0x00 }; +static const USB_HID_Short_Item_t hidUsageConsumerControl = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), .data = { 0x0C, 0x00 }, .location = 0x00 }; +/* + * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report + * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. + */ +static const USB_HID_Report_Element_t hidReportPageConsumer = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, + .location = HID_REPORT_SET_LOC( 0, 2, 0, 0 ) +}; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute -static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol- -static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+ -static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev -static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next -static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play +static USB_HID_Report_Element_t hidUsageByte0Bit5 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE2, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 5) +}; // Mute +static USB_HID_Report_Element_t hidUsageByte0Bit4 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xEA, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 4) +}; // Vol- +static USB_HID_Report_Element_t hidUsageByte0Bit3 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE9, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 3) +}; // Vol+ +static USB_HID_Report_Element_t hidUsageByte0Bit2 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB6, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 2) +}; // Scan Prev +static USB_HID_Report_Element_t hidUsageByte0Bit1 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB5, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 1) +}; // Scan Next +static USB_HID_Report_Element_t hidUsageByte0Bit0 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB0, 0x00 }, + .location = HID_REPORT_SET_LOC(0, 0, 0, 0) +}; // Play /* - * List the configurable items in the HID Report descriptor. + * List the configurable elements in the HID Report descriptor. */ -static USB_HID_Short_Item_t* const hidConfigurableItems[] = { +static USB_HID_Report_Element_t* const hidConfigurableElements[] = { &hidUsageByte0Bit0, &hidUsageByte0Bit1, &hidUsageByte0Bit2, @@ -73,27 +127,28 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { }; /* - * List Usage pages in the HID Report descriptor, one per byte. + * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * If not using report IDs - still have one with report ID 0 */ -static const USB_HID_Short_Item_t* const hidUsagePages[] = { - &hidUsagePageConsumer +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportPageConsumer }; /* * List all items in the HID Report descriptor. */ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { - &hidUsagePageConsumer, + &(hidReportPageConsumer.item), &hidUsageConsumerControl, &hidCollectionApplication, &hidLogicalMinimum0, &hidLogicalMaximum1, - &hidUsageByte0Bit0, - &hidUsageByte0Bit1, - &hidUsageByte0Bit2, - &hidUsageByte0Bit3, - &hidUsageByte0Bit4, - &hidUsageByte0Bit5, + &(hidUsageByte0Bit0.item), + &(hidUsageByte0Bit1.item), + &(hidUsageByte0Bit2.item), + &(hidUsageByte0Bit3.item), + &(hidUsageByte0Bit4.item), + &(hidUsageByte0Bit5.item), &hidReportSize1, &hidReportCount6, &hidInputDataVar, @@ -104,9 +159,10 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { }; /* - * Define the length of the HID Report. - * This value must match the number of Report bytes defined by hidReportDescriptorItems. + * Define the number of HID Reports + * Due to XC not supporting designated initializers, this constant has a hard-coded value. + * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) */ -#define HID_REPORT_LENGTH ( 1 ) +#define HID_REPORT_COUNT ( 1 ) #endif // __hid_report_descriptor_h__ From 71dd8b54093151bfd6a709dfd6261495f9d08861 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Fri, 10 Dec 2021 18:00:04 +0000 Subject: [PATCH 42/58] Add descriptor validation function & fix issues it found Note this is in progress, I either want to move the check function somewhere else, or convert the printf calls to something else (I imagine some kind of log function exists?) --- Jenkinsfile | 2 +- lib_xua/src/hid/hid_report.c | 162 ++++++++++++++++++ lib_xua/src/hid/xua_hid_report.h | 22 ++- .../test_multi_report/hid_report_descriptor.h | 6 +- .../test_multi_report/test_hid_multi_report.c | 5 + .../src/test_simple/hid_report_descriptor.h | 1 + .../xua_unit_tests/src/test_simple/test_hid.c | 5 + 7 files changed, 189 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 905b2301..9cb45038 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,7 +45,7 @@ pipeline { // runWaf('.', "configure clean build --target=xcoreai") // stash name: 'xua_unit_tests', includes: 'bin/*xcoreai.xe, ' viewEnv() { - runPython("TARGET=XCORE200 pytest -n 1") + runPython("TARGET=XCORE200 pytest -n1 -s") } } } diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index 1695976b..c04763e1 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -494,3 +494,165 @@ static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char return count; } + +struct HID_validation_info { + int collectionOpenedCount; + int reportCount; + + int currentReportIdx; + int currentConfigurableElementIdx; + + unsigned char reportIds[HID_REPORT_COUNT]; + unsigned char reportUsagePage[HID_REPORT_COUNT]; + + unsigned current_bit_size; + unsigned current_bit_count; + unsigned current_bit_offset; +}; + +static unsigned hidValidateInfoStructReportIDs( struct HID_validation_info *info ) { + if ( info->reportCount != HID_REPORT_COUNT) { + if ( !( info->reportCount == 0 && HID_REPORT_COUNT == 1 ) ) { + // (Only if report IDs are being used) + printf("Error: The number of actual reports does not match HID_REPORT_COUNT.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + } + for ( size_t idx1 = 0; idx1 < HID_REPORT_COUNT; ++idx1 ) { + for ( size_t idx2 = idx1 + 1; idx2 < HID_REPORT_COUNT; ++idx2 ) { + if ( info->reportIds[idx1] == info->reportIds[idx2] ) { + printf("Error: Duplicate report ID 0x%02x.\n", info->reportIds[idx1]); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + } + } + for ( size_t idx = 0; idx < HID_REPORT_COUNT; ++idx ) { + if ( info->reportIds[idx] != hidGetElementReportId( hidReports[idx]->location ) ) { + printf("Error: Report ID in descriptor does not match report ID in hidReports.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + if ( info->reportCount && info->reportIds[idx] == 0 ) { + printf("Error: Report ID 0 is invalid.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + } + return HID_STATUS_GOOD; +} + +static unsigned hidValidateInfoStructReportLength( struct HID_validation_info *info ) { + if ( info->current_bit_offset % 8 ) { + printf("Error: HID Report not byte aligned (%d bits).\n", info->current_bit_offset); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + if ( ( info->current_bit_offset / 8 ) != hidGetElementReportLength( hidReports[info->currentReportIdx]->location ) ) { + printf("Error: Actual report length does not match value in location field %d != %d.\n", + ( info->current_bit_offset / 8 ), + hidGetElementReportLength( hidReports[info->currentReportIdx]->location )); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + return HID_STATUS_GOOD; +} + +static unsigned hidValidateInfoStructCollections( struct HID_validation_info *info ) { + if ( info->collectionOpenedCount ) { + printf("Error: Collections not equally opened and closed.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + return HID_STATUS_GOOD; +} + +static unsigned hidValidateInfoStruct( struct HID_validation_info *info ) { + unsigned status = hidValidateInfoStructCollections( info ); + if( status == HID_STATUS_GOOD ) { + status = hidValidateInfoStructReportIDs( info ); + } + if( status == HID_STATUS_GOOD ) { + status = hidValidateInfoStructReportLength( info ); + } + return status; +} + + +unsigned hidReportValidate( void ) +{ + struct HID_validation_info info = {}; + unsigned status = HID_STATUS_GOOD; + + // Fill in the validation info struct + for ( size_t idx = 0; idx < HID_REPORT_DESCRIPTOR_ITEM_COUNT; ++idx ) { + const USB_HID_Short_Item_t *item = hidReportDescriptorItems[idx]; + unsigned bTag = hidGetItemTag ( item->header ); + unsigned bType = hidGetItemType( item->header ); + + if ( bTag == HID_REPORT_ITEM_TAG_COLLECTION && bType == HID_REPORT_ITEM_TYPE_MAIN ) { + info.collectionOpenedCount += 1; + } + if ( bTag == HID_REPORT_ITEM_TAG_END_COLLECTION && bType == HID_REPORT_ITEM_TYPE_MAIN ) { + info.collectionOpenedCount -= 1; + if ( info.collectionOpenedCount < 0 ) { + break; + } + } + if ( bTag == HID_REPORT_ITEM_TAG_REPORT_ID && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + if ( info.reportCount == 0 ) { + if ( info.current_bit_offset ) { + printf("Error: Some elements not associated with report ID.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + info.reportUsagePage[0] = 0; + } else { + status = hidValidateInfoStructReportLength( &info ); + if(status) { + return status; + } + } + + info.reportIds[info.reportCount] = item->data[0]; + info.currentReportIdx = info.reportCount; + info.reportCount += 1; + info.current_bit_offset = 0; + if ( info.reportCount > HID_REPORT_COUNT ) { + break; + } + } + if ( bTag == HID_REPORT_ITEM_TAG_USAGE_PAGE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + if ( info.reportUsagePage[info.currentReportIdx] ) { + printf("Error: Multiple usage pages per report ID not supported by this implementation.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + info.reportUsagePage[info.currentReportIdx] = item->data[0]; + } + if ( bTag == HID_REPORT_ITEM_TAG_USAGE && bType == HID_REPORT_ITEM_TYPE_LOCAL ) { + if ( ( info.currentConfigurableElementIdx < HID_CONFIGURABLE_ELEMENT_COUNT ) && + ( &(hidConfigurableElements[info.currentConfigurableElementIdx]->item) == item ) ) { + USB_HID_Report_Element_t *element = hidConfigurableElements[info.currentConfigurableElementIdx]; + unsigned bBit = hidGetElementBitLocation( element->location ); + unsigned bByte = hidGetElementByteLocation( element->location ); + unsigned bReportId = hidGetElementReportId( element->location ); + + if ( bBit != ( info.current_bit_offset % 8 ) || bByte != ( info.current_bit_offset / 8 ) ) { + printf("Error: Locator bit/byte setting incorrect for configurable element index %d.\n", info.currentConfigurableElementIdx); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + if ( bReportId != info.reportIds[info.currentReportIdx] ) { + printf("Error: Locator report ID setting incorrect for configurable element index %d.\n", info.currentConfigurableElementIdx); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + + info.currentConfigurableElementIdx += 1; + } + } + if ( bTag == HID_REPORT_ITEM_TAG_REPORT_SIZE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + info.current_bit_size = item->data[0]; + } + if ( bTag == HID_REPORT_ITEM_TAG_REPORT_COUNT && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + info.current_bit_count = item->data[0]; + } + if ( bTag == HID_REPORT_ITEM_TAG_INPUT && bType == HID_REPORT_ITEM_TYPE_MAIN ) { + info.current_bit_offset += (info.current_bit_size * info.current_bit_count); + } + } + + status = hidValidateInfoStruct( &info ); + return status; +} \ No newline at end of file diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 218a590b..a550409f 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -46,12 +46,6 @@ #define HID_REPORT_ITEM_USAGE_TAG ( 0U ) #define HID_REPORT_ITEM_USAGE_TYPE ( 2U ) -// Constants from the USB Device Class Definition for HID -#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) -#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) -#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) -#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) - /** * @brief Helper macro to configure the location field of USB_HID_Report_Element_t. * @@ -79,12 +73,13 @@ (( type << HID_REPORT_ITEM_HDR_TYPE_SHIFT) & HID_REPORT_ITEM_HDR_TYPE_MASK ) |\ (( tag << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ) ) -#define HID_STATUS_GOOD ( 0U ) -#define HID_STATUS_BAD_HEADER ( 1U ) -#define HID_STATUS_BAD_ID ( 2U ) -#define HID_STATUS_BAD_LOCATION ( 3U ) -#define HID_STATUS_BAD_PAGE ( 4U ) -#define HID_STATUS_IN_USE ( 5U ) +#define HID_STATUS_GOOD ( 0U ) +#define HID_STATUS_BAD_HEADER ( 1U ) +#define HID_STATUS_BAD_ID ( 2U ) +#define HID_STATUS_BAD_LOCATION ( 3U ) +#define HID_STATUS_BAD_PAGE ( 4U ) +#define HID_STATUS_IN_USE ( 5U ) +#define HID_STATUS_BAD_REPORT_DESCRIPTOR ( 6U ) #define MS_IN_TICKS 100000U @@ -502,4 +497,7 @@ unsigned hidSetReportItem( */ void hidSetReportPeriod( const unsigned id, const unsigned period ); +//TODO: DOcument +unsigned hidReportValidate( void ); + #endif // _XUA_HID_REPORT_ diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h index 68e2879d..9b7ab937 100644 --- a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -50,6 +50,9 @@ static const USB_HID_Short_Item_t hidReportCount4 = { static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 } }; +static const USB_HID_Short_Item_t hidReportCount7 = { + .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), + .data = { 0x07, 0x00 } }; static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 } }; @@ -243,9 +246,10 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { &(hidUsageReport2Byte0Bit7.item), &hidInputDataVar, &hidLogicalMaximum0, - &hidReportCount6, + &hidReportCount7, &hidInputConstArray, &hidLogicalMaximum1, + &hidReportCount1, &(hidUsageReport2Byte1Bit7.item), &hidInputDataVar, &hidCollectionEnd, diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index 96345e24..5a260472 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -66,6 +66,11 @@ void test_print_report( void ) printf("\n"); } +void test_validate_report( void ) { + unsigned retVal = hidReportValidate(); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { diff --git a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h index a0771470..330d95e6 100644 --- a/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h @@ -127,6 +127,7 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { &hidLogicalMaximum0, &hidReportCount6, &hidInputConstArray, + &hidReportCount1, &hidLogicalMaximum1, &(hidUsageByte1Bit7.item), &hidInputDataVar, diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 5857895f..e8cf3f9d 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -40,6 +40,11 @@ void setUp( void ) hidResetReportDescriptor(); } +void test_validate_report( void ) { + unsigned retVal = hidReportValidate(); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { From 8799f5f36ebffa0183f75cc81ff484dfa510d0bf Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Mon, 13 Dec 2021 12:51:40 +0000 Subject: [PATCH 43/58] Refactor HID report descriptor validation function --- Jenkinsfile | 2 +- lib_xua/src/hid/hid_report.c | 214 ++++++++++++++++++++++--------- lib_xua/src/hid/xua_hid_report.h | 15 ++- 3 files changed, 169 insertions(+), 62 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9cb45038..61fd5394 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,7 +45,7 @@ pipeline { // runWaf('.', "configure clean build --target=xcoreai") // stash name: 'xua_unit_tests', includes: 'bin/*xcoreai.xe, ' viewEnv() { - runPython("TARGET=XCORE200 pytest -n1 -s") + runPython("TARGET=XCORE200 pytest -s") } } } diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index c04763e1..b857c00b 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -495,6 +495,8 @@ static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char return count; } +// hid_report_descriptor.h validation functions for development purposes + struct HID_validation_info { int collectionOpenedCount; int reportCount; @@ -503,14 +505,20 @@ struct HID_validation_info { int currentConfigurableElementIdx; unsigned char reportIds[HID_REPORT_COUNT]; - unsigned char reportUsagePage[HID_REPORT_COUNT]; + unsigned reportUsagePage[HID_REPORT_COUNT]; unsigned current_bit_size; unsigned current_bit_count; unsigned current_bit_offset; }; -static unsigned hidValidateInfoStructReportIDs( struct HID_validation_info *info ) { +/** + * @brief Validation step for hidReportValidate, checking the info struct to ensure correctness of Report IDs + * + * @param info The info struct that has been built by hidReportValidate to check + * @return unsigned HID_STATUS value + */ +static unsigned hidReportValidateInfoStructReportIDs( struct HID_validation_info *info ) { if ( info->reportCount != HID_REPORT_COUNT) { if ( !( info->reportCount == 0 && HID_REPORT_COUNT == 1 ) ) { // (Only if report IDs are being used) @@ -539,7 +547,13 @@ static unsigned hidValidateInfoStructReportIDs( struct HID_validation_info *info return HID_STATUS_GOOD; } -static unsigned hidValidateInfoStructReportLength( struct HID_validation_info *info ) { +/** + * @brief Validation step for hidReportValidate, checking reports are the correct length specified in their location field + * + * @param info The info struct that has been built by hidReportValidate to check + * @return unsigned HID_STATUS value + */ +static unsigned hidReportValidateInfoStructReportLength( struct HID_validation_info *info ) { if ( info->current_bit_offset % 8 ) { printf("Error: HID Report not byte aligned (%d bits).\n", info->current_bit_offset); return HID_STATUS_BAD_REPORT_DESCRIPTOR; @@ -553,7 +567,13 @@ static unsigned hidValidateInfoStructReportLength( struct HID_validation_info *i return HID_STATUS_GOOD; } -static unsigned hidValidateInfoStructCollections( struct HID_validation_info *info ) { +/** + * @brief Validation step for hidReportValidate, collections are correctly opened and closed + * + * @param info The info struct that has been built by hidReportValidate to check + * @return unsigned HID_STATUS value + */ +static unsigned hidReportValidateInfoStructCollections( struct HID_validation_info *info ) { if ( info->collectionOpenedCount ) { printf("Error: Collections not equally opened and closed.\n"); return HID_STATUS_BAD_REPORT_DESCRIPTOR; @@ -561,24 +581,126 @@ static unsigned hidValidateInfoStructCollections( struct HID_validation_info *in return HID_STATUS_GOOD; } -static unsigned hidValidateInfoStruct( struct HID_validation_info *info ) { - unsigned status = hidValidateInfoStructCollections( info ); +/** + * @brief Validation step for hidReportValidate, High level - Checks the summarised information in the info struct by calling + * the subroutines for checking. + * + * @param info The info struct that has been built by hidReportValidate to check + * @return unsigned HID_STATUS value + */ +static unsigned hidReportValidateInfoStruct( struct HID_validation_info *info ) { + unsigned status = hidReportValidateInfoStructCollections( info ); if( status == HID_STATUS_GOOD ) { - status = hidValidateInfoStructReportIDs( info ); + status = hidReportValidateInfoStructReportIDs( info ); } if( status == HID_STATUS_GOOD ) { - status = hidValidateInfoStructReportLength( info ); + status = hidReportValidateInfoStructReportLength( info ); } return status; } +/** + * @brief Preparation step for hidReportValidate, Adds a report ID field into the information struct for validation + * + * @param info The info struct being built by hidReportValidate + * @param item The ReportId item being added + * @return unsigned HID_STATUS value + */ +static unsigned hidReportValidateAddReportId( struct HID_validation_info *info, const USB_HID_Short_Item_t *item ) { + if ( info->reportCount == 0 ) { + if ( info->current_bit_offset ) { + printf("Error: Some elements not associated with report ID.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + info->reportUsagePage[0] = 0; + } else { + unsigned status = hidReportValidateInfoStructReportLength( info ); + if ( status ) { + return status; + } + } + + if ( hidGetItemSize(item->header) != 1 ) { + printf("Error: ReportId field has invalid length %d (expected 1)", hidGetItemSize(item->header)); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + + info->reportIds[info->reportCount] = item->data[0]; + info->currentReportIdx = info->reportCount; + info->reportCount += 1; + info->current_bit_offset = 0; + if ( info->reportCount > HID_REPORT_COUNT ) { + printf("Error: HID_REPORT_COUNT does not match number of report IDs in descriptor.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + + return HID_STATUS_GOOD; +} + +/** + * @brief Preparation step for hidReportValidate, Adds a Usage Page field into the information struct for validation + * + * @param info The info struct being built by hidReportValidate + * @param item The UsagePage item being added + * @return unsigned HID_STATUS value + */ +static unsigned hidReportValidateAddUsagePageItem( struct HID_validation_info *info, const USB_HID_Short_Item_t *item ) { + if ( info->reportUsagePage[info->currentReportIdx] ) { + printf("Error: Multiple usage pages per report ID not supported by this implementation.\n"); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + + switch (hidGetItemSize(item->header)){ + case 1: + info->reportUsagePage[info->currentReportIdx] = item->data[0]; + break; + case 2: + info->reportUsagePage[info->currentReportIdx] = ((unsigned) item->data[1] << 8) + item->data[0]; + break; + default: + printf("Error: Invalid size for UsagePage report descriptor item."); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + + return HID_STATUS_GOOD; +} + +/** + * @brief Preparation step for hidReportValidate, Adds a Usage field into the information struct for validation + * + * @param info The info struct being built by hidReportValidate + * @param item The Usage item being added + * @return unsigned HID_STATUS value + */ +static unsigned hidReportValidateAddUsageItem( struct HID_validation_info *info, const USB_HID_Short_Item_t *item) { + if ( ( info->currentConfigurableElementIdx < HID_CONFIGURABLE_ELEMENT_COUNT ) && + ( &(hidConfigurableElements[info->currentConfigurableElementIdx]->item) == item ) ) { + + USB_HID_Report_Element_t *element = hidConfigurableElements[info->currentConfigurableElementIdx]; + unsigned bBit = hidGetElementBitLocation( element->location ); + unsigned bByte = hidGetElementByteLocation( element->location ); + unsigned bReportId = hidGetElementReportId( element->location ); + + if ( bBit != ( info->current_bit_offset % 8 ) || bByte != ( info->current_bit_offset / 8 ) ) { + printf("Error: Locator bit/byte setting incorrect for configurable element index %d.\n", info->currentConfigurableElementIdx); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + if ( bReportId != info->reportIds[info->currentReportIdx] ) { + printf("Error: Locator report ID setting incorrect for configurable element index %d.\n", info->currentConfigurableElementIdx); + return HID_STATUS_BAD_REPORT_DESCRIPTOR; + } + + info->currentConfigurableElementIdx += 1; + } + return HID_STATUS_GOOD; +} unsigned hidReportValidate( void ) { struct HID_validation_info info = {}; unsigned status = HID_STATUS_GOOD; - // Fill in the validation info struct + // Fill in the validation info struct by iterating through the hid report items for ( size_t idx = 0; idx < HID_REPORT_DESCRIPTOR_ITEM_COUNT; ++idx ) { const USB_HID_Short_Item_t *item = hidReportDescriptorItems[idx]; unsigned bTag = hidGetItemTag ( item->header ); @@ -593,55 +715,6 @@ unsigned hidReportValidate( void ) break; } } - if ( bTag == HID_REPORT_ITEM_TAG_REPORT_ID && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { - if ( info.reportCount == 0 ) { - if ( info.current_bit_offset ) { - printf("Error: Some elements not associated with report ID.\n"); - return HID_STATUS_BAD_REPORT_DESCRIPTOR; - } - info.reportUsagePage[0] = 0; - } else { - status = hidValidateInfoStructReportLength( &info ); - if(status) { - return status; - } - } - - info.reportIds[info.reportCount] = item->data[0]; - info.currentReportIdx = info.reportCount; - info.reportCount += 1; - info.current_bit_offset = 0; - if ( info.reportCount > HID_REPORT_COUNT ) { - break; - } - } - if ( bTag == HID_REPORT_ITEM_TAG_USAGE_PAGE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { - if ( info.reportUsagePage[info.currentReportIdx] ) { - printf("Error: Multiple usage pages per report ID not supported by this implementation.\n"); - return HID_STATUS_BAD_REPORT_DESCRIPTOR; - } - info.reportUsagePage[info.currentReportIdx] = item->data[0]; - } - if ( bTag == HID_REPORT_ITEM_TAG_USAGE && bType == HID_REPORT_ITEM_TYPE_LOCAL ) { - if ( ( info.currentConfigurableElementIdx < HID_CONFIGURABLE_ELEMENT_COUNT ) && - ( &(hidConfigurableElements[info.currentConfigurableElementIdx]->item) == item ) ) { - USB_HID_Report_Element_t *element = hidConfigurableElements[info.currentConfigurableElementIdx]; - unsigned bBit = hidGetElementBitLocation( element->location ); - unsigned bByte = hidGetElementByteLocation( element->location ); - unsigned bReportId = hidGetElementReportId( element->location ); - - if ( bBit != ( info.current_bit_offset % 8 ) || bByte != ( info.current_bit_offset / 8 ) ) { - printf("Error: Locator bit/byte setting incorrect for configurable element index %d.\n", info.currentConfigurableElementIdx); - return HID_STATUS_BAD_REPORT_DESCRIPTOR; - } - if ( bReportId != info.reportIds[info.currentReportIdx] ) { - printf("Error: Locator report ID setting incorrect for configurable element index %d.\n", info.currentConfigurableElementIdx); - return HID_STATUS_BAD_REPORT_DESCRIPTOR; - } - - info.currentConfigurableElementIdx += 1; - } - } if ( bTag == HID_REPORT_ITEM_TAG_REPORT_SIZE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { info.current_bit_size = item->data[0]; } @@ -651,8 +724,29 @@ unsigned hidReportValidate( void ) if ( bTag == HID_REPORT_ITEM_TAG_INPUT && bType == HID_REPORT_ITEM_TYPE_MAIN ) { info.current_bit_offset += (info.current_bit_size * info.current_bit_count); } + if ( bTag == HID_REPORT_ITEM_TAG_REPORT_ID && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + status = hidReportValidateAddReportId( &info, item ); + if ( status ) { + break; + } + } + if ( bTag == HID_REPORT_ITEM_TAG_USAGE_PAGE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + status = hidReportValidateAddUsagePageItem( &info, item ); + if ( status ) { + break; + } + } + if ( bTag == HID_REPORT_ITEM_TAG_USAGE && bType == HID_REPORT_ITEM_TYPE_LOCAL ) { + status = hidReportValidateAddUsageItem( &info, item ); + if ( status ) { + break; + } + } } - status = hidValidateInfoStruct( &info ); - return status; + if(status) { + return status; + } else { + return hidReportValidateInfoStruct( &info ); + } } \ No newline at end of file diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index a550409f..2d3539f6 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -497,7 +497,20 @@ unsigned hidSetReportItem( */ void hidSetReportPeriod( const unsigned id, const unsigned period ); -//TODO: DOcument +/** + * @brief Development function: Validate the contents of hid_report_descriptor.h for common errors, printing + * error messages if any issues were found. + * + * This function is intended for use when developing the contents of hid_report_descriptor.h, which is static, + * so shouldn't be required for use in a production application. + * + * @return Validation result + * @retval HID_STATUS_GOOD The validation found no issues with the data structures defined + * in hid_report_descriptor.h + * @retval HID_STATUS_BAD_REPORT_DESCRIPTOR The validation encountered an issue with the data structures + * defined in hid_report_descriptor.h . More information is + * provided in the printed messages. + */ unsigned hidReportValidate( void ); #endif // _XUA_HID_REPORT_ From 5be97ac227032451ce9cee4ad733098d18ca2cb5 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Tue, 14 Dec 2021 14:15:48 +0000 Subject: [PATCH 44/58] Begin work on setidle unit tests --- lib_xua/src/hid/hid_report.c | 64 +++++++++---------- .../test_multi_report/test_hid_multi_report.c | 52 +++++++++++++++ .../xua_unit_tests/src/test_simple/test_hid.c | 13 ++++ 3 files changed, 97 insertions(+), 32 deletions(-) diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index b857c00b..3c5c7db9 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -375,6 +375,7 @@ void hidReportInit( void ) for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; } + memset( s_hidIdleActive, 0, sizeof( s_hidIdleActive ) ); } void hidResetReportDescriptor( void ) @@ -497,19 +498,22 @@ static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char // hid_report_descriptor.h validation functions for development purposes +/** + * @brief Internal HID Report Descriptor validation state + */ struct HID_validation_info { - int collectionOpenedCount; - int reportCount; + int collectionOpenedCount; //!< Current count of open collections (to track that they are all closed) + int reportCount; //!< Current count of defined reports (to count them) - int currentReportIdx; - int currentConfigurableElementIdx; + int currentReportIdx; //!< Index of current report in hidReports array + int currentConfigurableElementIdx; //!< Index of current configurable element in hidConfigurableElements array - unsigned char reportIds[HID_REPORT_COUNT]; - unsigned reportUsagePage[HID_REPORT_COUNT]; + unsigned char reportIds[HID_REPORT_COUNT]; // Array of report IDs (for general validation & duplication detection) + unsigned reportUsagePage[HID_REPORT_COUNT]; // Array of the usage page for each report (for general validation) - unsigned current_bit_size; - unsigned current_bit_count; - unsigned current_bit_offset; + unsigned current_bit_size; // State tracker for the current set report bit width (todo: should technically be a stack) + unsigned current_bit_count; // State tracker for the current set report count (todo: should technically be a stack) + unsigned current_bit_offset; // Current bit offset into this report (for location validation) }; /** @@ -621,7 +625,7 @@ static unsigned hidReportValidateAddReportId( struct HID_validation_info *info, } if ( hidGetItemSize(item->header) != 1 ) { - printf("Error: ReportId field has invalid length %d (expected 1)", hidGetItemSize(item->header)); + printf("Error: ReportId field has invalid length %d (expected 1)\n", hidGetItemSize(item->header)); return HID_STATUS_BAD_REPORT_DESCRIPTOR; } @@ -658,7 +662,7 @@ static unsigned hidReportValidateAddUsagePageItem( struct HID_validation_info *i info->reportUsagePage[info->currentReportIdx] = ((unsigned) item->data[1] << 8) + item->data[0]; break; default: - printf("Error: Invalid size for UsagePage report descriptor item."); + printf("Error: Invalid size for UsagePage report descriptor item.\n"); return HID_STATUS_BAD_REPORT_DESCRIPTOR; } @@ -709,38 +713,34 @@ unsigned hidReportValidate( void ) if ( bTag == HID_REPORT_ITEM_TAG_COLLECTION && bType == HID_REPORT_ITEM_TYPE_MAIN ) { info.collectionOpenedCount += 1; } - if ( bTag == HID_REPORT_ITEM_TAG_END_COLLECTION && bType == HID_REPORT_ITEM_TYPE_MAIN ) { + else if ( bTag == HID_REPORT_ITEM_TAG_END_COLLECTION && bType == HID_REPORT_ITEM_TYPE_MAIN ) { info.collectionOpenedCount -= 1; if ( info.collectionOpenedCount < 0 ) { - break; + printf("Error: Collection closed while there is no collection open.\n"); + status = HID_STATUS_BAD_REPORT_DESCRIPTOR; } } - if ( bTag == HID_REPORT_ITEM_TAG_REPORT_SIZE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { - info.current_bit_size = item->data[0]; - } - if ( bTag == HID_REPORT_ITEM_TAG_REPORT_COUNT && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { - info.current_bit_count = item->data[0]; - } - if ( bTag == HID_REPORT_ITEM_TAG_INPUT && bType == HID_REPORT_ITEM_TYPE_MAIN ) { + else if ( bTag == HID_REPORT_ITEM_TAG_INPUT && bType == HID_REPORT_ITEM_TYPE_MAIN ) { info.current_bit_offset += (info.current_bit_size * info.current_bit_count); } - if ( bTag == HID_REPORT_ITEM_TAG_REPORT_ID && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + else if ( bTag == HID_REPORT_ITEM_TAG_REPORT_SIZE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + info.current_bit_size = item->data[0]; + } + else if ( bTag == HID_REPORT_ITEM_TAG_REPORT_COUNT && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + info.current_bit_count = item->data[0]; + } + else if ( bTag == HID_REPORT_ITEM_TAG_REPORT_ID && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { status = hidReportValidateAddReportId( &info, item ); - if ( status ) { - break; - } } - if ( bTag == HID_REPORT_ITEM_TAG_USAGE_PAGE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { + else if ( bTag == HID_REPORT_ITEM_TAG_USAGE_PAGE && bType == HID_REPORT_ITEM_TYPE_GLOBAL ) { status = hidReportValidateAddUsagePageItem( &info, item ); - if ( status ) { - break; - } } - if ( bTag == HID_REPORT_ITEM_TAG_USAGE && bType == HID_REPORT_ITEM_TYPE_LOCAL ) { + else if ( bTag == HID_REPORT_ITEM_TAG_USAGE && bType == HID_REPORT_ITEM_TYPE_LOCAL ) { status = hidReportValidateAddUsageItem( &info, item ); - if ( status ) { - break; - } + } + + if ( status ) { + break; } } diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index 5a260472..fe639f0f 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -739,3 +739,55 @@ void test_initial_modification_with_subsequent_verification_2( void ) TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // The call to hidSetReportItem with size 1 in the header should return the MSB to zero } } + +//setIdle functionality tests +void test_set_idle( void ) +{ + unsigned reportIdAll = 0; + unsigned reportId = 1; + unsigned reportId2 = 2; + + unsigned setIdle = hidIsIdleActive( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + setIdle = hidIsIdleActive( reportId2 ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + setIdle = hidIsIdleActive( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + hidSetIdle( reportId, 1 ); + setIdle = hidIsIdleActive( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, setIdle ); + + setIdle = hidIsIdleActive( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + setIdle = hidIsIdleActive( reportId2 ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); +} + +void test_set_all_idle( void ) +{ + unsigned reportIdAll = 0; + unsigned reportId = 1; + unsigned reportId2 = 2; + + unsigned setIdle = hidIsIdleActive( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + setIdle = hidIsIdleActive( reportId2 ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + setIdle = hidIsIdleActive( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + for ( reportId = 1; reportId <= HID_REPORT_COUNT; ++reportId ) { + hidSetIdle( reportId, 1 ); + setIdle = hidIsIdleActive( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, setIdle ); + } + + setIdle = hidIsIdleActive( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 1, setIdle ); +} \ No newline at end of file diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index e8cf3f9d..5eb6f033 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -573,3 +573,16 @@ void test_modification_with_subsequent_preparation( void ) reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); } + +//setIdle functionality tests +void test_set_idle( void ) +{ + unsigned reportId = 0; + + unsigned setIdle = hidIsIdleActive( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, setIdle ); + + hidSetIdle( reportId, 1 ); + setIdle = hidIsIdleActive( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, setIdle ); +} From c3e95a379f95fc909e72d8bdd47eccb7da58511d Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 15 Dec 2021 12:44:39 +0000 Subject: [PATCH 45/58] Add some report time tests & fix comments] --- lib_xua/src/hid/hid_report.c | 5 +- lib_xua/src/hid/xua_hid_report.h | 21 ++-- .../test_multi_report/test_hid_multi_report.c | 109 +++++++++++++++--- .../xua_unit_tests/src/test_simple/test_hid.c | 35 ++++++ 4 files changed, 139 insertions(+), 31 deletions(-) diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index 3c5c7db9..fbbceb70 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -2,12 +2,14 @@ // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include +#include +#include #include + #include "descriptor_defs.h" #include "xua_hid_report.h" #include "hid_report_descriptor.h" -#include #define HID_REPORT_ITEM_LOCATION_SIZE ( 1 ) #define HID_REPORT_DESCRIPTOR_ITEM_COUNT ( sizeof hidReportDescriptorItems / sizeof ( USB_HID_Short_Item_t* )) @@ -376,6 +378,7 @@ void hidReportInit( void ) s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; } memset( s_hidIdleActive, 0, sizeof( s_hidIdleActive ) ); + memset( s_hidChangePending, 0, sizeof( s_hidChangePending ) ); } void hidResetReportDescriptor( void ) diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 2d3539f6..16de92eb 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -133,9 +133,8 @@ typedef struct * Calling this function for a given Report ID indicates that the changed * HID data has been reported to the USB Host. * - * \warning This function will fail silently if given a Report ID outside of - * the supported range. - * The supported range runs from zero inclusive to HID_REPORT_COUNT exclusive. + * \warning This function will fail silently if given an id that is not + * either the value zero, or a Report ID that is in use. * * \param[in] id A HID Report ID. * Zero clears the pending status of all Report IDs. @@ -259,7 +258,7 @@ void hidCalcNextReportTime( const unsigned id ); void hidCaptureReportTime( const unsigned id, const unsigned time ); /** - * @brief Get the time to send the next HID Report time for the given \a id + * @brief Get the time to send the next HID Report for the given \a id * * Parameters: * @@ -331,11 +330,8 @@ unsigned hidGetReportTime( const unsigned id ); * Calling this function with a given Report ID returns an indication of * whether unreported HID data exists for that Report ID. * - * \warning This function will return zero if given a Report ID outside of - * the supported range. - * If not using Report IDs, the supported range consists of the value zero only. - * If using Report IDs, the supported range runs from zero inclusive to - * HID_REPORT_COUNT exclusive. + * \warning This function will return zero if given an id that is not + * either the value zero, or a Report ID that is in use. * * \param[in] id A HID Report ID. * Zero reports the pending status of all Report IDs. @@ -410,11 +406,8 @@ void hidResetReportDescriptor( void ); * for that Report ID has changed and has not yet been reported to the USB * Host. * - * \warning This function will fail silently if given a Report ID outside of - * the supported range. - * If not using Report IDs, the supported range consists of the value zero only. - * If using Report IDs, the supported range runs from one inclusive to - * HID_REPORT_COUNT exclusive. + * \warning This function will fail silently if given an id that is not + * either the value zero, or a Report ID that is in use. * * \param[in] id A HID Report ID. * Use zero if the application does not use Report IDs. diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index fe639f0f..f5b86c34 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -53,19 +53,6 @@ void setUp( void ) hidResetReportDescriptor(); } -void test_print_report( void ) -{ - hidPrepareReportDescriptor(); - unsigned char* report = hidGetReportDescriptor(); - size_t reportLen = hidGetReportDescriptorLength(); - - printf("ReportDescriptor:"); - for (size_t i = 0; i < reportLen; i++) { - printf(" %02x", report[i]); - } - printf("\n"); -} - void test_validate_report( void ) { unsigned retVal = hidReportValidate(); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); @@ -740,7 +727,7 @@ void test_initial_modification_with_subsequent_verification_2( void ) } } -//setIdle functionality tests +//setIdle and associated timing functionality tests void test_set_idle( void ) { unsigned reportIdAll = 0; @@ -776,7 +763,7 @@ void test_set_all_idle( void ) unsigned setIdle = hidIsIdleActive( reportId ); TEST_ASSERT_EQUAL_UINT( 0, setIdle ); - setIdle = hidIsIdleActive( reportId2 ); + setIdle = hidIsIdleActive( reportId2 ); TEST_ASSERT_EQUAL_UINT( 0, setIdle ); setIdle = hidIsIdleActive( reportIdAll ); @@ -790,4 +777,94 @@ void test_set_all_idle( void ) setIdle = hidIsIdleActive( reportIdAll ); TEST_ASSERT_EQUAL_UINT( 1, setIdle ); -} \ No newline at end of file +} + +void test_change_pending( void ) +{ + unsigned reportIdAll = 0; + unsigned reportId = 1; + unsigned reportId2 = 2; + + unsigned changePending = hidIsChangePending( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); + + changePending = hidIsChangePending( reportId2 ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); + + changePending = hidIsChangePending( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); + + hidSetChangePending( reportId ); + changePending = hidIsChangePending( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, changePending ); + + changePending = hidIsChangePending( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 1, changePending ); + + changePending = hidIsChangePending( reportId2 ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); +} + +void test_change_pending_all( void ) +{ + unsigned reportIdAll = 0; + unsigned reportId = 1; + + unsigned changePending = hidIsChangePending( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); + + changePending = hidIsChangePending( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); + + for ( reportId = 1; reportId <= HID_REPORT_COUNT; ++reportId ) { + hidSetChangePending( reportId ); + changePending = hidIsChangePending( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, changePending ); + } + + changePending = hidIsChangePending( reportIdAll ); + TEST_ASSERT_EQUAL_UINT( 1, changePending ); +} + +void test_report_time( void ) +{ + unsigned reportTime1 = 123; + unsigned reportTime2 = 456; + + hidCaptureReportTime(1, reportTime1); + hidCaptureReportTime(2, reportTime2); + reportTime1 = hidGetReportTime(1); + reportTime2 = hidGetReportTime(2); + + TEST_ASSERT_EQUAL_UINT(123, reportTime1); + TEST_ASSERT_EQUAL_UINT(456, reportTime2); +} + +void test_report_time_calc( void ) +{ + unsigned reportTime1 = 123; + unsigned reportTime2 = 456; + unsigned reportPeriod1 = 10; + unsigned reportPeriod2 = 5; + + hidCaptureReportTime(1, reportTime1); + hidCaptureReportTime(2, reportTime2); + hidSetReportPeriod(1, reportPeriod1); + hidSetReportPeriod(2, reportPeriod2); + reportTime1 = hidGetReportTime(1); + reportTime2 = hidGetReportTime(2); + reportPeriod1 = hidGetReportPeriod(1); + reportPeriod2 = hidGetReportPeriod(2); + + TEST_ASSERT_EQUAL_UINT(123, reportTime1); + TEST_ASSERT_EQUAL_UINT(456, reportTime2); + TEST_ASSERT_EQUAL_UINT(10, reportPeriod1); + TEST_ASSERT_EQUAL_UINT(5, reportPeriod2); + + hidCalcNextReportTime(1); + hidCalcNextReportTime(2); + unsigned nextReportTime1 = hidGetNextReportTime(1); + unsigned nextReportTime2 = hidGetNextReportTime(2); + TEST_ASSERT_EQUAL_UINT( reportTime1 + reportPeriod1, nextReportTime1 ); + TEST_ASSERT_EQUAL_UINT( reportTime2 + reportPeriod2, nextReportTime2 ); +} diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 5eb6f033..8cc3dfc9 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -586,3 +586,38 @@ void test_set_idle( void ) setIdle = hidIsIdleActive( reportId ); TEST_ASSERT_EQUAL_UINT( 1, setIdle ); } + +void test_change_pending( void ) +{ + unsigned reportId = 0; + + unsigned changePending = hidIsChangePending( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); + + hidSetChangePending( reportId ); + changePending = hidIsChangePending( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, changePending ); + + hidClearChangePending( reportId ); + changePending = hidIsChangePending( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, changePending ); +} + +void test_report_time( void ) +{ + unsigned reportTime = 123; + unsigned reportPeriod = 10; + + hidSetReportPeriod(0, reportPeriod); + hidCaptureReportTime(0, reportTime); + reportTime = hidGetReportTime(0); + reportPeriod = hidGetReportPeriod(0); + + TEST_ASSERT_EQUAL_UINT(123, reportTime); + TEST_ASSERT_EQUAL_UINT(10, reportPeriod); + + hidCalcNextReportTime(0); + + unsigned nextReportTime = hidGetNextReportTime(0); + TEST_ASSERT_EQUAL_UINT(133, nextReportTime); +} From d3d9b5ba2384eb0e497bc8a7ac4bf8185c667fdb Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Fri, 17 Dec 2021 14:34:13 +0000 Subject: [PATCH 46/58] Add hidReportIdInUse command to determine whether report IDs are used --- lib_xua/src/hid/hid_report.c | 7 +++++++ lib_xua/src/hid/xua_hid_report.h | 13 +++++++++++++ .../src/test_multi_report/test_hid_multi_report.c | 5 +++++ tests/xua_unit_tests/src/test_simple/test_hid.c | 5 +++++ 4 files changed, 30 insertions(+) diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index fbbceb70..ab35b63b 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -242,6 +242,13 @@ unsigned hidGetReportIdLimit ( void ) { return retVal; } +unsigned hidIsReportIdInUse ( void ) { + if ( hidGetElementReportId( hidReports[ 0 ]->location ) ) { + return 1; + } + return 0; +} + #define HID_CONFIGURABLE_ELEMENT_COUNT ( sizeof hidConfigurableElements / sizeof ( USB_HID_Report_Element_t* )) unsigned hidGetReportItem( const unsigned id, diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 16de92eb..21bc3aa9 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -181,6 +181,19 @@ size_t hidGetReportDescriptorLength( void ); */ unsigned hidGetReportIdLimit ( void ); +/** + * @brief Does the application use Report IDs? + * + * If the application is not using Report IDs, then the id value that is passed around + * everywhere can just be zero. Otherwise zero is an invalid ID that has a special meaning + * in some cases (read the documentation for each function). + * + * @return Boolean + * @retval 1 Report IDs are in use + * @retval 0 Report IDs are not in use + */ +unsigned hidIsReportIdInUse ( void ); + /** * @brief Get a HID Report descriptor item * diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index f5b86c34..1a4e28c3 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -58,6 +58,11 @@ void test_validate_report( void ) { TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } +void test_reportid_in_use( void ) { + unsigned reportIdInUse = hidIsReportIdInUse(); + TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 8cc3dfc9..21da3f39 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -45,6 +45,11 @@ void test_validate_report( void ) { TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } +void test_reportid_in_use( void ) { + unsigned reportIdInUse = hidIsReportIdInUse(); + TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { From ab96a726d68dda06bc2d41197729f8c744542ef9 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Mon, 20 Dec 2021 12:51:26 +0000 Subject: [PATCH 47/58] Altered format on test report_descriptor.h --- .../hid_report_descriptor.h | 83 +++++++++++-------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h index f133eb7e..6ba8ea01 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -5,6 +5,8 @@ #include "xua_hid_report.h" +#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) + #if 0 /* Existing static report descriptor kept for reference */ unsigned char hidReportDescriptor[] = @@ -29,8 +31,6 @@ unsigned char hidReportDescriptor[] = }; #endif -#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) - /* * Define non-configurable items in the HID Report descriptor. */ @@ -64,41 +64,56 @@ static const USB_HID_Short_Item_t hidReportCount2 = { static const USB_HID_Short_Item_t hidReportCount6 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), .data = { 0x06, 0x00 } }; - static const USB_HID_Short_Item_t hidReportSize1 = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), .data = { 0x01, 0x00 } }; + static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidUsagePageConsumer = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), - .data = { 0x0C, 0x00 } }; + +/* + * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report + * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. + */ +static const USB_HID_Report_Element_t hidReportPageConsumer = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), + .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 ) }; /* * Define configurable items in the HID Report descriptor. */ -static USB_HID_Report_Element_t hidUsageByte0Bit5 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE2, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) }; // Mute -static USB_HID_Report_Element_t hidUsageByte0Bit4 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xEA, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) }; // Vol- -static USB_HID_Report_Element_t hidUsageByte0Bit3 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE9, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) }; // Vol+ -static USB_HID_Report_Element_t hidUsageByte0Bit2 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB6, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) }; // Scan Prev -static USB_HID_Report_Element_t hidUsageByte0Bit1 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB5, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) }; // Scan Next -static USB_HID_Report_Element_t hidUsageByte0Bit0 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB0, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) }; // Play - -static USB_HID_Short_Item_t hidReportID1 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_ID), - .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00} }; -static const USB_HID_Report_Element_t hidReportConsumer = { - .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), - .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 ) -}; +static USB_HID_Report_Element_t hidUsageByte0Bit5 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE2, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) +}; // Mute +static USB_HID_Report_Element_t hidUsageByte0Bit4 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xEA, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) +}; // Vol- +static USB_HID_Report_Element_t hidUsageByte0Bit3 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xE9, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) +}; // Vol+ +static USB_HID_Report_Element_t hidUsageByte0Bit2 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB6, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) +}; // Scan Prev +static USB_HID_Report_Element_t hidUsageByte0Bit1 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB5, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) +}; // Scan Next +static USB_HID_Report_Element_t hidUsageByte0Bit0 = { + .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), + .item.data = { 0xB0, 0x00 }, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) +}; // Play /* * List the configurable items in the HID Report descriptor. @@ -113,18 +128,18 @@ static USB_HID_Report_Element_t* const hidConfigurableElements[] = { }; /* - * List Usage pages in the HID Report descriptor, one per byte. + * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * If not using report IDs - still have one with report ID 0 */ -static const USB_HID_Short_Item_t * const hidUsagePages[] = { - &hidUsagePageConsumer +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportPageConsumer }; /* * List all items in the HID Report descriptor. */ static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = { - &(hidReportConsumer.item), - &hidUsagePageConsumer, + &(hidReportPageConsumer.item), &hidUsageConsumerControl, &hidCollectionApplication, &hidLogicalMinimum0, @@ -144,10 +159,6 @@ static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = { &hidCollectionEnd }; -static const USB_HID_Report_Element_t* const hidReports[] = { - &hidReportConsumer -}; - /* * Define the number of HID Reports * Due to XC not supporting designated initializers, this constant has a hard-coded value. From ccc1ee4021d3234cb4b5359ee0161e4e60d374c8 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Mon, 20 Dec 2021 14:47:20 +0000 Subject: [PATCH 48/58] Fix inverted isSilenced logic, add INVALID_ID constant --- lib_xua/src/core/user/hid/user_hid.h | 3 ++- lib_xua/src/hid/hid.xc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_xua/src/core/user/hid/user_hid.h b/lib_xua/src/core/user/hid/user_hid.h index 0ed07904..b17a4dd5 100644 --- a/lib_xua/src/core/user/hid/user_hid.h +++ b/lib_xua/src/core/user/hid/user_hid.h @@ -31,7 +31,8 @@ typedef struct hidEvent_t { unsigned value; } hidEvent_t; -#define HID_MAX_DATA_BYTES 4 +#define HID_MAX_DATA_BYTES ( 4 ) +#define HID_EVENT_INVALID_ID ( 0x100 ) #if( 0 < HID_CONTROLS ) diff --git a/lib_xua/src/hid/hid.xc b/lib_xua/src/hid/hid.xc index fd8f6fab..d9a0d500 100644 --- a/lib_xua/src/hid/hid.xc +++ b/lib_xua/src/hid/hid.xc @@ -39,7 +39,7 @@ unsigned HidIsSetIdleSilenced( const unsigned id ) { unsigned isSilenced = hidIsIdleActive( id ); - if( isSilenced ) { + if( !isSilenced ) { unsigned currentTime; // Use inline assembly to access the time without creating a side-effect. // The mapper complains if the time comes from an XC timer because this function is called in the guard of a select case. From 548992ab5c46b459e16ece1ef5fc9f4c4a48a17e Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Mon, 20 Dec 2021 15:46:15 +0000 Subject: [PATCH 49/58] Removed USB_HID_REPORT_ID_CONSUMER as per review. --- .../hid_report_descriptor.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h index 6ba8ea01..e0b185f8 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -5,8 +5,6 @@ #include "xua_hid_report.h" -#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) - #if 0 /* Existing static report descriptor kept for reference */ unsigned char hidReportDescriptor[] = @@ -79,7 +77,7 @@ static const USB_HID_Short_Item_t hidUsageConsumerControl = { static const USB_HID_Report_Element_t hidReportPageConsumer = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), .item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 ) }; + .location = HID_REPORT_SET_LOC( 0, 1, 0, 0 ) }; /* * Define configurable items in the HID Report descriptor. @@ -87,32 +85,32 @@ static const USB_HID_Report_Element_t hidReportPageConsumer = { static USB_HID_Report_Element_t hidUsageByte0Bit5 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE2, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) + .location = HID_REPORT_SET_LOC( 0, 0, 0, 5 ) }; // Mute static USB_HID_Report_Element_t hidUsageByte0Bit4 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xEA, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) + .location = HID_REPORT_SET_LOC( 0, 0, 0, 4 ) }; // Vol- static USB_HID_Report_Element_t hidUsageByte0Bit3 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE9, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) + .location = HID_REPORT_SET_LOC( 0, 0, 0, 3 ) }; // Vol+ static USB_HID_Report_Element_t hidUsageByte0Bit2 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB6, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) + .location = HID_REPORT_SET_LOC( 0, 0, 0, 2 ) }; // Scan Prev static USB_HID_Report_Element_t hidUsageByte0Bit1 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB5, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) + .location = HID_REPORT_SET_LOC( 0, 0, 0, 1 ) }; // Scan Next static USB_HID_Report_Element_t hidUsageByte0Bit0 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB0, 0x00 }, - .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) + .location = HID_REPORT_SET_LOC( 0, 0, 0, 0 ) }; // Play /* From 625123e4a63febe025c153d99a8d2dadf494395c Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Mon, 20 Dec 2021 16:45:24 +0000 Subject: [PATCH 50/58] Clarified ep_buffer.xc setup stall Added getter hidIsReportDescriptorPrepared(), allowing more readable logic in the setup phase of ep_buffer.xc --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 18 ++++++------------ lib_xua/src/hid/hid_report.c | 5 +++++ lib_xua/src/hid/xua_hid_report.h | 9 +++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 0324bc0b..2eecb6b7 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -375,19 +375,13 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #if( 0 < HID_CONTROLS ) UserHIDInit(); { - int hidReportLength = 0; - unsigned hidReportId; - while(0 == hidReportLength) { - for( hidReportId = 0U; hidReportId < hidGetReportIdLimit(); ++hidReportId) { - hidReportLength = (int) hidGetReportLength(hidReportId); - if(0 < hidReportLength) { - break; - } - } - } + /* Stall until Report Descriptor has been prepared */ + while (!hidIsReportDescriptorPrepared()); - hidReportLength = (int) UserHIDGetData(hidReportId, g_hidData); - XUD_SetReady_In(ep_hid, g_hidData, hidReportLength); + /* Get the last report - we don't really care which it is, so long as there's some data we can grab. */ + int hidReportLength = (int) UserHIDGetData(hidGetReportIdLimit() - 1, g_hidData); + + XUD_SetReady_In(ep_hid, g_hidData, hidReportLength) } #endif diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index ab35b63b..4f165656 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -213,6 +213,11 @@ unsigned hidGetNextReportTime( const unsigned id ) { return retVal; } +unsigned hidIsReportDescriptorPrepared( void ) +{ + return s_hidReportDescriptorPrepared; +} + unsigned char* hidGetReportDescriptor( void ) { unsigned char* retVal = NULL; diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 21bc3aa9..1b2cb4e9 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -142,6 +142,15 @@ typedef struct */ void hidClearChangePending( const unsigned id ); +/** + * @brief Indicate if the HID Report descriptor has been prepared + * + * \returns A Boolean indicating whether the HID Report descriptor has been prepared. + * \retval True The HID Report descriptor has been prepared. + * \retval False The HID Report has not been prepared. + */ + unsigned hidIsReportDescriptorPrepared( void ); + /** * @brief Get the HID Report descriptor * From e71ffdba00af5b855e12f0a46411f2fca98e9f59 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Mon, 20 Dec 2021 17:10:48 +0000 Subject: [PATCH 51/58] Missed a semicolon... --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 2eecb6b7..605ab119 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -381,7 +381,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, /* Get the last report - we don't really care which it is, so long as there's some data we can grab. */ int hidReportLength = (int) UserHIDGetData(hidGetReportIdLimit() - 1, g_hidData); - XUD_SetReady_In(ep_hid, g_hidData, hidReportLength) + XUD_SetReady_In(ep_hid, g_hidData, hidReportLength); } #endif From 244a7718a1715ff404cc8147c97051e7fee1fea1 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Mon, 20 Dec 2021 17:11:50 +0000 Subject: [PATCH 52/58] Corrected type in documentation --- lib_xua/src/hid/xua_hid_report.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 1b2cb4e9..5bc2cda9 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -147,7 +147,7 @@ void hidClearChangePending( const unsigned id ); * * \returns A Boolean indicating whether the HID Report descriptor has been prepared. * \retval True The HID Report descriptor has been prepared. - * \retval False The HID Report has not been prepared. + * \retval False The HID Report descriptor has not been prepared. */ unsigned hidIsReportDescriptorPrepared( void ); From 77398218b5e69b18e56cda37eefd3ec7868f5993 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Mon, 20 Dec 2021 17:17:34 +0000 Subject: [PATCH 53/58] Apply suggestions from code review Co-authored-by: Ciaran Woodward --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 605ab119..49b96ef5 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -375,10 +375,10 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #if( 0 < HID_CONTROLS ) UserHIDInit(); { - /* Stall until Report Descriptor has been prepared */ - while (!hidIsReportDescriptorPrepared()); + while (!hidIsReportDescriptorPrepared()) + ; - /* Get the last report - we don't really care which it is, so long as there's some data we can grab. */ + /* Get data from the last report, which which we can prep XUD*/ int hidReportLength = (int) UserHIDGetData(hidGetReportIdLimit() - 1, g_hidData); XUD_SetReady_In(ep_hid, g_hidData, hidReportLength); From 6400e146d01c94a58552705476e3d9ddadd140aa Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Mon, 20 Dec 2021 17:24:27 +0000 Subject: [PATCH 54/58] Add an iterator style mechanism for iterating through report IDs --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 2 +- lib_xua/src/hid/hid_report.c | 18 ++++++++++++++++-- lib_xua/src/hid/xua_hid_report.h | 11 +++++++++++ .../test_multi_report/test_hid_multi_report.c | 16 ++++++++++++++++ .../xua_unit_tests/src/test_simple/test_hid.c | 10 ++++++++++ 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 49b96ef5..cfacd9b9 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -378,7 +378,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, while (!hidIsReportDescriptorPrepared()) ; - /* Get data from the last report, which which we can prep XUD*/ + /* Get the last report - we don't really care which it is, so long as there's some data we can grab. */ int hidReportLength = (int) UserHIDGetData(hidGetReportIdLimit() - 1, g_hidData); XUD_SetReady_In(ep_hid, g_hidData, hidReportLength); diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index 4f165656..a514ff08 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -254,6 +254,20 @@ unsigned hidIsReportIdInUse ( void ) { return 0; } +unsigned hidGetNextValidReportId ( unsigned idPrev ) { + size_t retIndex = 0; + + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + unsigned reportId = hidGetElementReportId( hidReports[ idx ]->location ); + if( reportId == idPrev ) { + retIndex = (idx + 1) % HID_REPORT_COUNT; + break; + } + } + + return hidGetElementReportId( hidReports[ retIndex ]->location ); +} + #define HID_CONFIGURABLE_ELEMENT_COUNT ( sizeof hidConfigurableElements / sizeof ( USB_HID_Report_Element_t* )) unsigned hidGetReportItem( const unsigned id, @@ -342,8 +356,8 @@ unsigned hidIsChangePending( const unsigned id ) { unsigned retVal = 0U; for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { - if( id == 0U ) { - retVal |= ( s_hidChangePending[ idx ] != 0U ); + if( id == 0U && s_hidChangePending[ idx ] != 0U ) { + retVal = 1; } else if( id == hidGetElementReportId( hidReports[ idx ]->location )) { retVal = ( s_hidChangePending[ idx ] != 0U ); break; diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 5bc2cda9..c5574441 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -203,6 +203,17 @@ unsigned hidGetReportIdLimit ( void ); */ unsigned hidIsReportIdInUse ( void ); +/** + * @brief Get the next valid report ID - iterator style. + * + * This function will loop around and start returning the first report ID again once it has + * returned all valid report IDs. + * + * @param idPrev The previous returned id, or 0 if this is the first call + * @return unsigned The next valid report ID. + */ +unsigned hidGetNextValidReportId ( unsigned idPrev ); + /** * @brief Get a HID Report descriptor item * diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index 1a4e28c3..ba0df58a 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -63,6 +63,22 @@ void test_reportid_in_use( void ) { TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); } +void test_get_next_valid_report_id( void ) { + unsigned reportId = 0U; + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 2, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 3, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 21da3f39..0dc896e7 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -50,6 +50,16 @@ void test_reportid_in_use( void ) { TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); } +void test_get_next_valid_report_id( void ) { + unsigned reportId = 0U; + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) { From e7f9428731e047d5b0bb0e73b97cfd265a89f99e Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Mon, 20 Dec 2021 17:34:01 +0000 Subject: [PATCH 55/58] Fix typos in unit tests --- .../src/test_multi_report/test_hid_multi_report.c | 8 ++++---- tests/xua_unit_tests/src/test_simple/test_hid.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c index ba0df58a..a78e7fcf 100644 --- a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -67,16 +67,16 @@ void test_get_next_valid_report_id( void ) { unsigned reportId = 0U; reportId = hidGetNextValidReportId(reportId); - TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); + TEST_ASSERT_EQUAL_UINT( 1, reportId ); reportId = hidGetNextValidReportId(reportId); - TEST_ASSERT_EQUAL_UINT( 2, reportIdInUse ); + TEST_ASSERT_EQUAL_UINT( 2, reportId ); reportId = hidGetNextValidReportId(reportId); - TEST_ASSERT_EQUAL_UINT( 3, reportIdInUse ); + TEST_ASSERT_EQUAL_UINT( 3, reportId ); reportId = hidGetNextValidReportId(reportId); - TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); + TEST_ASSERT_EQUAL_UINT( 1, reportId ); } // Basic report descriptor tests diff --git a/tests/xua_unit_tests/src/test_simple/test_hid.c b/tests/xua_unit_tests/src/test_simple/test_hid.c index 0dc896e7..29d96021 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -54,10 +54,10 @@ void test_get_next_valid_report_id( void ) { unsigned reportId = 0U; reportId = hidGetNextValidReportId(reportId); - TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); + TEST_ASSERT_EQUAL_UINT( 0, reportId ); reportId = hidGetNextValidReportId(reportId); - TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); + TEST_ASSERT_EQUAL_UINT( 0, reportId ); } // Basic report descriptor tests From b88342ab2b12fd3dd510fde91fe663089576ff30 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Tue, 21 Dec 2021 11:21:06 +0000 Subject: [PATCH 56/58] Add new hid page ID constant --- lib_xua/src/hid/hid_report.c | 6 ++++++ lib_xua/src/hid/xua_hid_report_descriptor_constants.h | 1 + 2 files changed, 7 insertions(+) diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index a514ff08..90a0d4d4 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -152,12 +152,17 @@ void hidCaptureReportTime( const unsigned id, const unsigned time ) void hidClearChangePending( const unsigned id ) { + printf("ccp%d", id); for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { if(( id == 0U ) || ( id == hidGetElementReportId( hidReports[ idx ]->location ))) { + if( !s_hidChangePending[ idx ] ) + printf(""); s_hidChangePending[ idx ] = 0U; + printf("y"); break; } } + printf("\n"); } static unsigned hidGetElementBitLocation( const unsigned short location ) @@ -416,6 +421,7 @@ void hidSetChangePending( const unsigned id ) { for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { if( id == hidGetElementReportId( hidReports[ idx ]->location )) { + printf("Set cp idx %d\n", idx); s_hidChangePending[ idx ] = 1U; break; } diff --git a/lib_xua/src/hid/xua_hid_report_descriptor_constants.h b/lib_xua/src/hid/xua_hid_report_descriptor_constants.h index 0ff1c4de..f35d7bd3 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor_constants.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor_constants.h @@ -58,6 +58,7 @@ // Constants from HID Usage Tables // Usage page IDs (incomplete) +#define USB_HID_USAGE_PAGE_ID_GENERIC_DESKTOP ( 0x01 ) #define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 ) #define USB_HID_USAGE_PAGE_ID_TELEPHONY_DEVICE ( 0x0B ) #define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) From 703a27705965a52ec1084a7b6e55219026d6dec6 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Tue, 21 Dec 2021 12:18:57 +0000 Subject: [PATCH 57/58] Remove debug printfs --- lib_xua/src/hid/hid_report.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index 90a0d4d4..a514ff08 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -152,17 +152,12 @@ void hidCaptureReportTime( const unsigned id, const unsigned time ) void hidClearChangePending( const unsigned id ) { - printf("ccp%d", id); for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { if(( id == 0U ) || ( id == hidGetElementReportId( hidReports[ idx ]->location ))) { - if( !s_hidChangePending[ idx ] ) - printf(""); s_hidChangePending[ idx ] = 0U; - printf("y"); break; } } - printf("\n"); } static unsigned hidGetElementBitLocation( const unsigned short location ) @@ -421,7 +416,6 @@ void hidSetChangePending( const unsigned id ) { for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { if( id == hidGetElementReportId( hidReports[ idx ]->location )) { - printf("Set cp idx %d\n", idx); s_hidChangePending[ idx ] = 1U; break; } From ee6c22bd376e10506d92b61b5f5c42f51536c5a3 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Tue, 21 Dec 2021 12:43:34 +0000 Subject: [PATCH 58/58] Loosen up usage page check in validate While the implementation can only support one usage per report id, the report collections themselves have usages, which are acceptable. This change allows these usages to pass the validate check. --- lib_xua/src/hid/hid_report.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index a514ff08..97d7f014 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -678,6 +678,10 @@ static unsigned hidReportValidateAddReportId( struct HID_validation_info *info, * @return unsigned HID_STATUS value */ static unsigned hidReportValidateAddUsagePageItem( struct HID_validation_info *info, const USB_HID_Short_Item_t *item ) { + + if ( info->collectionOpenedCount == 0 ) { + return HID_STATUS_GOOD; + } if ( info->reportUsagePage[info->currentReportIdx] ) { printf("Error: Multiple usage pages per report ID not supported by this implementation.\n"); return HID_STATUS_BAD_REPORT_DESCRIPTOR;