forked from PAWPAW-Mirror/lib_xua
Add an iterator style mechanism for iterating through report IDs
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user