diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index deceb05c..b282319b 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -525,6 +525,7 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c #endif #if( 0 < HID_CONTROLS ) + hidReportInit(); hidPrepareReportDescriptor(); size_t hidReportDescriptorLength = hidGetReportDescriptorLength(); diff --git a/lib_xua/src/hid/hid_report.c b/lib_xua/src/hid/hid_report.c index f23fc42a..124e9e35 100644 --- a/lib_xua/src/hid/hid_report.c +++ b/lib_xua/src/hid/hid_report.c @@ -16,15 +16,15 @@ /* * Each element in s_hidChangePending corresponds to an element in hidReports. */ -static unsigned s_hidChangePending[ HID_REPORT_COUNT ] = { 0U }; +static unsigned s_hidChangePending[ HID_REPORT_COUNT ]; static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ]; -static size_t s_hidReportDescriptorLength = 0U; -static unsigned s_hidReportDescriptorPrepared = 0U; +static size_t s_hidReportDescriptorLength; +static unsigned s_hidReportDescriptorPrepared; -static unsigned s_hidCurrentPeriod[ HID_REPORT_COUNT ] = { ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS }; -static unsigned s_hidIdleActive[ HID_REPORT_COUNT ] = { 0U }; -static unsigned s_hidNextReportTime[ HID_REPORT_COUNT ] = { 0U }; -static unsigned s_hidReportTime[ HID_REPORT_COUNT ] = { 0U }; +static unsigned s_hidCurrentPeriod[ HID_REPORT_COUNT ]; +static unsigned s_hidIdleActive[ HID_REPORT_COUNT ]; +static unsigned s_hidNextReportTime[ HID_REPORT_COUNT ]; +static unsigned s_hidReportTime[ HID_REPORT_COUNT ]; /** * @brief Get the bit position from the location of a report element @@ -362,6 +362,13 @@ void hidPrepareReportDescriptor( void ) } } +void hidReportInit( void ) +{ + for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx ) { + s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; + } +} + void hidResetReportDescriptor( void ) { s_hidReportDescriptorPrepared = 0U; diff --git a/lib_xua/src/hid/xua_hid_report.h b/lib_xua/src/hid/xua_hid_report.h index 8043d1c3..65d51c2c 100644 --- a/lib_xua/src/hid/xua_hid_report.h +++ b/lib_xua/src/hid/xua_hid_report.h @@ -350,6 +350,13 @@ unsigned hidIsIdleActive( const unsigned id ); */ void hidPrepareReportDescriptor( void ); +/** + * @brief Initialise the USB HID Report functionality + * + * Call this function before using any other functions in this API. + */ +void hidReportInit( void ); + /** * @brief Reset the USB HID Report descriptor * diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_hid.c index b21d0333..75e5a6c4 100644 --- a/tests/xua_unit_tests/src/test_hid.c +++ b/tests/xua_unit_tests/src/test_hid.c @@ -45,6 +45,7 @@ void test_unprepared_hidGetReportDescriptor( void ) void test_prepared_hidGetReportDescriptor( void ) { + hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); @@ -55,6 +56,7 @@ void test_prepared_hidGetReportDescriptor( void ) void test_reset_unprepared_hidGetReportDescriptor( void ) { + hidReportInit(); hidPrepareReportDescriptor(); hidResetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); @@ -63,6 +65,7 @@ void test_reset_unprepared_hidGetReportDescriptor( void ) void test_reset_prepared_hidGetReportDescriptor( void ) { + hidReportInit(); hidPrepareReportDescriptor(); hidResetReportDescriptor(); hidPrepareReportDescriptor(); @@ -404,6 +407,7 @@ void test_initial_modification_with_subsequent_preparation( void ) const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char page = CONSUMER_CONTROL_PAGE; + hidReportInit(); unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); @@ -484,6 +488,7 @@ void test_initial_modification_with_subsequent_verification_2( void ) void test_modification_without_subsequent_preparation( void ) { + hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr ); @@ -504,6 +509,7 @@ void test_modification_without_subsequent_preparation( void ) void test_modification_with_subsequent_preparation( void ) { + hidReportInit(); hidPrepareReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor(); TEST_ASSERT_NOT_NULL( reportDescPtr );