Fix implementation of hidGetReportIdLimit to match docs & usage

This commit is contained in:
Ciaran Woodward
2021-12-09 16:10:28 +00:00
parent 1b186a0c2f
commit 19be25809b
3 changed files with 27 additions and 4 deletions

View File

@@ -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* ))

View File

@@ -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 )
{

View File

@@ -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 )
{