diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 49b96ef5..cfacd9b9 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -378,7 +378,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, while (!hidIsReportDescriptorPrepared()) ; - /* Get data from the last report, which which we can prep XUD*/ + /* Get the last report - we don't really care which it is, so long as there's some data we can grab. */ int hidReportLength = (int) UserHIDGetData(hidGetReportIdLimit() - 1, g_hidData); XUD_SetReady_In(ep_hid, g_hidData, hidReportLength); diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index 4f165656..a514ff08 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -254,6 +254,20 @@ unsigned hidIsReportIdInUse ( void ) { return 0; } +unsigned hidGetNextValidReportId ( unsigned idPrev ) { + size_t retIndex = 0; + + for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + unsigned reportId = hidGetElementReportId( hidReports[ idx ]->location ); + if( reportId == idPrev ) { + retIndex = (idx + 1) % HID_REPORT_COUNT; + break; + } + } + + return hidGetElementReportId( hidReports[ retIndex ]->location ); +} + #define HID_CONFIGURABLE_ELEMENT_COUNT ( sizeof hidConfigurableElements / sizeof ( USB_HID_Report_Element_t* )) unsigned hidGetReportItem( const unsigned id, @@ -342,8 +356,8 @@ unsigned hidIsChangePending( const unsigned id ) { unsigned retVal = 0U; for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) { - if( id == 0U ) { - retVal |= ( s_hidChangePending[ idx ] != 0U ); + if( id == 0U && s_hidChangePending[ idx ] != 0U ) { + retVal = 1; } else if( id == hidGetElementReportId( hidReports[ idx ]->location )) { retVal = ( s_hidChangePending[ idx ] != 0U ); break; diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 5bc2cda9..c5574441 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -203,6 +203,17 @@ unsigned hidGetReportIdLimit ( void ); */ unsigned hidIsReportIdInUse ( void ); +/** + * @brief Get the next valid report ID - iterator style. + * + * This function will loop around and start returning the first report ID again once it has + * returned all valid report IDs. + * + * @param idPrev The previous returned id, or 0 if this is the first call + * @return unsigned The next valid report ID. + */ +unsigned hidGetNextValidReportId ( unsigned idPrev ); + /** * @brief Get a HID Report descriptor item * 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 1a4e28c3..ba0df58a 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 @@ -63,6 +63,22 @@ void test_reportid_in_use( void ) { TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); } +void test_get_next_valid_report_id( void ) { + unsigned reportId = 0U; + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 2, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 3, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 1, reportIdInUse ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( 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 21da3f39..0dc896e7 100644 --- a/tests/xua_unit_tests/src/test_simple/test_hid.c +++ b/tests/xua_unit_tests/src/test_simple/test_hid.c @@ -50,6 +50,16 @@ void test_reportid_in_use( void ) { TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); } +void test_get_next_valid_report_id( void ) { + unsigned reportId = 0U; + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); + + reportId = hidGetNextValidReportId(reportId); + TEST_ASSERT_EQUAL_UINT( 0, reportIdInUse ); +} + // Basic report descriptor tests void test_unprepared_hidGetReportDescriptor( void ) {