diff --git a/lib_xua/src/hid/hid_report_descriptor.c b/lib_xua/src/hid/hid_report_descriptor.c index d4d1fb28..14cfd0a4 100644 --- a/lib_xua/src/hid/hid_report_descriptor.c +++ b/lib_xua/src/hid/hid_report_descriptor.c @@ -143,33 +143,41 @@ void hidPrepareReportDescriptor( void ) } } +void hidResetReportDescriptor( void ) +{ + hidReportDescriptorPrepared = 0; +} + unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsigned char header, const unsigned char data[] ) { - unsigned retVal = HID_STATUS_BAD_LOCATION; - unsigned bSize = hidGetItemSize( header ); - unsigned bTag = hidGetItemTag ( header ); - unsigned bType = hidGetItemType( header ); + unsigned retVal = HID_STATUS_IN_USE; - if(( HID_REPORT_ITEM_MAX_SIZE < bSize ) || - ( HID_REPORT_ITEM_USAGE_TAG != bTag ) || - ( HID_REPORT_ITEM_USAGE_TYPE != bType )) { - retVal = HID_STATUS_BAD_HEADER; - } else { - for( unsigned itemIdx = 0; itemIdx < sizeof hidConfigurableItems / sizeof( USB_HID_Short_Item_t ); ++itemIdx ) { - USB_HID_Short_Item_t item = *hidConfigurableItems[ itemIdx ]; - unsigned bBit = hidGetItemBitLocation( item.location ); - unsigned bByte = hidGetItemByteLocation( item.location ); + if( !hidReportDescriptorPrepared ) { + retVal = HID_STATUS_BAD_LOCATION; + unsigned bSize = hidGetItemSize( header ); + unsigned bTag = hidGetItemTag ( header ); + unsigned bType = hidGetItemType( header ); - if(( bit == bBit ) && ( byte == bByte )) { - item.header = header; + if(( HID_REPORT_ITEM_MAX_SIZE < bSize ) || + ( HID_REPORT_ITEM_USAGE_TAG != bTag ) || + ( HID_REPORT_ITEM_USAGE_TYPE != bType )) { + retVal = HID_STATUS_BAD_HEADER; + } else { + for( unsigned itemIdx = 0; itemIdx < sizeof hidConfigurableItems / sizeof( USB_HID_Short_Item_t ); ++itemIdx ) { + USB_HID_Short_Item_t item = *hidConfigurableItems[ itemIdx ]; + unsigned bBit = hidGetItemBitLocation( item.location ); + unsigned bByte = hidGetItemByteLocation( item.location ); - for( unsigned dataIdx = 0; dataIdx < bSize; ++dataIdx ) { - item.data[ dataIdx ] = data[ dataIdx ]; + if(( bit == bBit ) && ( byte == bByte )) { + item.header = header; + + for( unsigned dataIdx = 0; dataIdx < bSize; ++dataIdx ) { + item.data[ dataIdx ] = data[ dataIdx ]; + } + + *hidConfigurableItems[ itemIdx ] = item; + retVal = HID_STATUS_GOOD; } - - *hidConfigurableItems[ itemIdx ] = item; - hidReportDescriptorPrepared = 0; - retVal = HID_STATUS_GOOD; } } } diff --git a/lib_xua/src/hid/xua_hid_report_descriptor.h b/lib_xua/src/hid/xua_hid_report_descriptor.h index 7e1c41ac..91d01e41 100644 --- a/lib_xua/src/hid/xua_hid_report_descriptor.h +++ b/lib_xua/src/hid/xua_hid_report_descriptor.h @@ -4,7 +4,8 @@ /** * @brief Human Interface Device (HID) Report descriptor * - * This file defines the structure and default content of the HID Report descriptor. + * This file defines the structure of the HID Report descriptor and decalres + * functions for manipulating it. * Document section numbers refer to the HID Device Class Definition, version 1.11. */ @@ -34,6 +35,7 @@ #define HID_STATUS_GOOD ( 0 ) #define HID_STATUS_BAD_HEADER ( 1 ) #define HID_STATUS_BAD_LOCATION ( 2 ) +#define HID_STATUS_IN_USE ( 3 ) /** * @brief USB HID Report Descriptor. Short Item @@ -84,11 +86,19 @@ size_t hidGetReportDescriptorLength( void ); * @brief Prepare the USB HID Report descriptor * * After preparation, \c hidGetReportDescriptor() returns a list suitablefor transmission over USB. - * * Call this function after altering one or more Report Items using \c hidSetReportItem(). */ void hidPrepareReportDescriptor( void ); +/** + * @brief Reset the USB HID Report descriptor + * + * After reset, \c hidGetReportDescriptor() returns NULL until a subsequent call to + * \c hidPrepareReportDescriptor() occurs. + * Call this function before altering one or more Report Items using \c hidSetReportItem(). + */ +void hidResetReportDescriptor( void ); + /** * @brief Modify a HID Report descriptor item * @@ -109,6 +119,7 @@ void hidPrepareReportDescriptor( void ); * a Tag or Type inconsistent with a Usage Item * @retval \c HID_STATUS_BAD_LOCATION The \a bit or \a byte arguments specify a location outside * of the HID Report + * @retval \c HID_STATUS_IN_USE The Report descriptor is in use */ unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsigned char header, const unsigned char data[] );