From 7dfd78deb4799b8901a2f0a111c89434c731b5d2 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 11:01:17 +0000 Subject: [PATCH] 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;