From 19be25809b32289c22cbf6eff544dd2e535d84ac Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Thu, 9 Dec 2021 16:10:28 +0000 Subject: [PATCH] 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 ) {