diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 765da1a4..d319216f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,8 @@ lib_xua Change Log 2.0.0 ----- + * ADDED: Function to get a Report item description + * CHANGED: Check HID Usage Page when changing a Report item description * CHANGED: HID event ID from list to bit and byte location in HID Report * CHANGED: Interface to UserHIDRecordEvent() * ADDED: Support for multiple flash specs defined by DFU_FLASH_DEVICE diff --git a/examples/AN00246_xua_example/src/hid_report_descriptor.h b/examples/AN00246_xua_example/src/hid_report_descriptor.h index b183beda..a049576e 100644 --- a/examples/AN00246_xua_example/src/hid_report_descriptor.h +++ b/examples/AN00246_xua_example/src/hid_report_descriptor.h @@ -72,6 +72,13 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { &hidUsageByte0Bit5 }; +/* + * List Usage pages in the HID Report descriptor, one per byte. + */ +static const USB_HID_Short_Item_t* const hidUsagePages[] = { + &hidUsagePageConsumer +}; + /* * List all items in the HID Report descriptor. */ 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 b183beda..a049576e 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 @@ -72,6 +72,13 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { &hidUsageByte0Bit5 }; +/* + * List Usage pages in the HID Report descriptor, one per byte. + */ +static const USB_HID_Short_Item_t* const hidUsagePages[] = { + &hidUsagePageConsumer +}; + /* * List all 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 b183beda..a049576e 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 @@ -72,6 +72,13 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { &hidUsageByte0Bit5 }; +/* + * List Usage pages in the HID Report descriptor, one per byte. + */ +static const USB_HID_Short_Item_t* const hidUsagePages[] = { + &hidUsagePageConsumer +}; + /* * List all 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 b183beda..a049576e 100644 --- a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h +++ b/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h @@ -72,6 +72,13 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { &hidUsageByte0Bit5 }; +/* + * List Usage pages in the HID Report descriptor, one per byte. + */ +static const USB_HID_Short_Item_t* const hidUsagePages[] = { + &hidUsagePageConsumer +}; + /* * List all items in the HID Report descriptor. */ diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index 022085ed..a9cb3bab 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -72,6 +72,17 @@ static unsigned hidGetItemTag( const unsigned char header ); */ static unsigned hidGetItemType( const unsigned char header ); +/** + * @brief Get the Usage Page number for a given byte in the HID Report + * + * Parameters: + * + * @param[in] byte The byte location in the HID Report + * + * @return The USB HID Usage Page code or zero if the \a byte parameter is out-of-range + */ +static unsigned hidGetUsagePage( const unsigned byte ); + /** * @brief Translate an Item from the \c USB_HID_Short_Item format to raw bytes * @@ -134,12 +145,48 @@ size_t hidGetReportDescriptorLength( void ) return retVal; } +#define HID_CONFIGURABLE_ITEM_COUNT ( sizeof hidConfigurableItems / sizeof ( USB_HID_Short_Item_t* )) +unsigned hidGetReportItem( + const unsigned byte, + const unsigned bit, + unsigned char* const page, + unsigned char* const header, + unsigned char data[] +) +{ + 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 ); + + if(( bit == bBit ) && ( byte == bByte )) { + *page = hidGetUsagePage( byte ); + *header = item.header; + + for( unsigned dataIdx = 0; dataIdx < HID_REPORT_ITEM_MAX_SIZE; ++data, ++dataIdx ) { + *data = item.data[ dataIdx ]; + } + + retVal = HID_STATUS_GOOD; + break; + } + } + return retVal; +} + size_t hidGetReportLength( void ) { size_t retVal = ( hidReportDescriptorPrepared ) ? HID_REPORT_LENGTH : 0; return retVal; } +static unsigned hidGetUsagePage( const unsigned byte ) +{ + unsigned retVal = ( byte < HID_REPORT_LENGTH ) ? hidUsagePages[ byte ]->data[ 0 ] : 0; + return retVal; +} + void hidPrepareReportDescriptor( void ) { if( !hidReportDescriptorPrepared ) { @@ -158,8 +205,13 @@ void hidResetReportDescriptor( void ) hidReportDescriptorPrepared = 0; } -#define HID_CONFIGURABLE_ITEM_COUNT ( sizeof hidConfigurableItems / sizeof ( USB_HID_Short_Item_t* )) -unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsigned char header, const unsigned char data[] ) +unsigned hidSetReportItem( + const unsigned byte, + const unsigned bit, + const unsigned char page, + const unsigned char header, + const unsigned char data[] +) { unsigned retVal = HID_STATUS_IN_USE; @@ -180,14 +232,22 @@ unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsign unsigned bByte = hidGetItemByteLocation( item.location ); if(( bit == bBit ) && ( byte == bByte )) { - item.header = header; + unsigned pg = hidGetUsagePage( byte ); - for( unsigned dataIdx = 0; dataIdx < bSize; ++dataIdx ) { - item.data[ dataIdx ] = data[ dataIdx ]; + if( page == pg ) { + item.header = header; + + for( unsigned dataIdx = 0; dataIdx < bSize; ++dataIdx ) { + item.data[ dataIdx ] = data[ dataIdx ]; + } + + *hidConfigurableItems[ itemIdx ] = item; + retVal = HID_STATUS_GOOD; + } else { + retVal = HID_STATUS_BAD_PAGE; } - *hidConfigurableItems[ itemIdx ] = item; - retVal = HID_STATUS_GOOD; + break; } } } diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index c78202a7..34d391a3 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -41,7 +41,8 @@ #define HID_STATUS_GOOD ( 0 ) #define HID_STATUS_BAD_HEADER ( 1 ) #define HID_STATUS_BAD_LOCATION ( 2 ) -#define HID_STATUS_IN_USE ( 3 ) +#define HID_STATUS_BAD_PAGE ( 3 ) +#define HID_STATUS_IN_USE ( 4 ) /** * @brief USB HID Report Descriptor. Short Item @@ -94,6 +95,24 @@ unsigned char* hidGetReportDescriptor( void ); */ size_t hidGetReportDescriptorLength( void ); +/** + * @brief Get a HID Report descriptor item + * + * Parameters: + * + * @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) + * @param[out] header The LSB of the Item containing the bSize, bType and bTag fields (see 6.2.2.2) + * @param[out] data A two element array containing data bytes for the Item + * + * @return A status value + * @retval \c HID_STATUS_GOOD Item successfully returned + * @retval \c HID_STATUS_BAD_LOCATION The \a bit or \a byte arguments specify a location outside + * of the HID Report + */ +unsigned hidGetReportItem( const unsigned byte, const unsigned bit, unsigned char* const page, unsigned char* const header, unsigned char data[]); + /** * @brief Get the length of the HID Report * @@ -133,6 +152,7 @@ void hidResetReportDescriptor( void ); * * @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) * @param[in] header The LSB of the Item containing the bSize, bType and bTag fields (see 6.2.2.2) * @param[in] data An array containing data bytes or NULL for an Item with no data * @@ -142,8 +162,10 @@ void hidResetReportDescriptor( void ); * a Tag or Type inconsistent with a Usage Item * @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 header, const unsigned char data[] ); +unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsigned char page, const unsigned char header, const unsigned char data[]); #endif // _HID_REPORT_DESCRIPTOR_ diff --git a/tests/xua_unit_tests/src/hid_report_descriptor.h b/tests/xua_unit_tests/src/hid_report_descriptor.h index faf3e7f7..a70075ba 100644 --- a/tests/xua_unit_tests/src/hid_report_descriptor.h +++ b/tests/xua_unit_tests/src/hid_report_descriptor.h @@ -52,6 +52,14 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = { &hidUsageByte1Bit7 }; +/* + * List Usage pages in the HID Report descriptor, one per byte. + */ +static const USB_HID_Short_Item_t* const hidUsagePages[] = { + &hidUsagePageConsumer, + &hidUsagePageConsumer +}; + /* * List all items in the HID Report descriptor. */ diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_hid.c index 7c014a2c..079ca654 100644 --- a/tests/xua_unit_tests/src/test_hid.c +++ b/tests/xua_unit_tests/src/test_hid.c @@ -12,7 +12,8 @@ #define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) #define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) -#define LOUDNESS_CONTROL ( 0xE7 ) +#define CONSUMER_CONTROL_PAGE ( 0x0C ) +#define LOUDNESS_CONTROL ( 0xE7 ) static unsigned construct_usage_header( unsigned size ) { @@ -68,6 +69,103 @@ void test_reset_prepared_hidGetReportDescriptor( void ) TEST_ASSERT_NOT_NULL( reportDescPtr ); } +// Basic item tests +void test_max_loc_hidGetReportItem( void ) +{ + 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 ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0xEA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); +} + +void test_min_loc_hidGetReportItem( void ) +{ + 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 ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0xE2, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); +} + +void test_overflow_bit_hidGetReportItem( void ) +{ + 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 ); + 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 ) +{ + 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 ); + 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 ) +{ + 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 ); + 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 ) +{ + 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 ); + 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 ]); +} + // Configurable and non-configurable item tests void test_configurable_item_hidSetReportItem( void ) { @@ -75,8 +173,9 @@ void test_configurable_item_hidSetReportItem( void ) 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, header, data ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -86,8 +185,9 @@ void test_nonconfigurable_item_hidSetReportItem( void ) const unsigned byte = MIN_VALID_BYTE; // hidConfigurableItems 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, header, data ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } @@ -97,8 +197,9 @@ 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 char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_CONTROL_PAGE; - unsigned retVal = hidSetReportItem( byte, bit, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -107,8 +208,9 @@ void test_min_bit_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -117,8 +219,9 @@ void test_overflow_bit_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } @@ -127,8 +230,9 @@ void test_underflow_bit_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, ( unsigned ) bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } @@ -138,8 +242,9 @@ void test_max_byte_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -148,8 +253,9 @@ void test_min_byte_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -158,8 +264,9 @@ void test_overflow_byte_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } @@ -168,8 +275,9 @@ void test_underflow_byte_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( ( unsigned ) byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); } @@ -180,8 +288,9 @@ void test_max_size_hidSetReportItem( void ) 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, header, data ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -190,8 +299,9 @@ void test_min_size_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -200,8 +310,9 @@ void test_unsupported_size_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } @@ -211,10 +322,11 @@ void test_bad_tag_hidSetReportItem( void ) 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_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 retVal = hidSetReportItem( byte, bit, bad_header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, bad_header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } } @@ -225,8 +337,9 @@ void test_global_type_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } @@ -236,8 +349,9 @@ void test_local_type_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); } @@ -247,8 +361,9 @@ void test_main_type_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } @@ -258,8 +373,9 @@ void test_reserved_type_hidSetReportItem( void ) 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, header, NULL ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } @@ -270,8 +386,9 @@ void test_initial_modification_without_subsequent_preparation( void ) 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, header, data ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); unsigned char* reportDescPtr = hidGetReportDescriptor(); @@ -284,8 +401,9 @@ void test_initial_modification_with_subsequent_preparation( void ) 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, header, data ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); hidPrepareReportDescriptor(); @@ -293,6 +411,30 @@ void test_initial_modification_with_subsequent_preparation( void ) TEST_ASSERT_NOT_NULL( reportDescPtr ); } +void test_initial_modification_with_subsequent_verification( void ) +{ + 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_CONTROL_PAGE; + + unsigned setRetVal = hidSetReportItem( 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 ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); + TEST_ASSERT_EQUAL_UINT( get_page, set_page ); + TEST_ASSERT_EQUAL_UINT( get_header, set_header ); + TEST_ASSERT_EQUAL_UINT( get_data[ 0 ], set_data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( get_data[ 1 ], set_data[ 1 ]); +} + void test_modification_without_subsequent_preparation( void ) { hidPrepareReportDescriptor(); @@ -303,9 +445,10 @@ void test_modification_without_subsequent_preparation( void ) 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; hidResetReportDescriptor(); - unsigned retVal = hidSetReportItem( byte, bit, header, data ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); reportDescPtr = hidGetReportDescriptor(); @@ -322,9 +465,10 @@ void test_modification_with_subsequent_preparation( void ) 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; hidResetReportDescriptor(); - unsigned retVal = hidSetReportItem( byte, bit, header, data ); + unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); hidPrepareReportDescriptor();