Update unit test header to match new report id api

This commit is contained in:
Ciaran Woodward
2021-12-08 11:01:17 +00:00
parent 8c9e8b11b9
commit 7dfd78deb4
2 changed files with 55 additions and 29 deletions

View File

@@ -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__

View File

@@ -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;