From 589c16d56caee5477d3a2f0276657d2a90f8ec6a Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Tue, 7 Dec 2021 17:17:14 +0000 Subject: [PATCH 01/13] 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 02/13] 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 7dfd78deb4799b8901a2f0a111c89434c731b5d2 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 11:01:17 +0000 Subject: [PATCH 03/13] 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 04/13] 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 05/13] 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 06/13] 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 07/13] 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 08/13] 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 09/13] 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 10/13] 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 19be25809b32289c22cbf6eff544dd2e535d84ac Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 16:10:28 +0000 Subject: [PATCH 11/13] 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 353d7c3c8d3b95f03280bdab1431195d5c8eab0e Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 17:28:16 +0000 Subject: [PATCH 12/13] 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 13/13] 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.