forked from PAWPAW-Mirror/lib_xua
Add explicit reset
This commit is contained in:
@@ -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 hidSetReportItem( const unsigned byte, const unsigned bit, const unsigned char header, const unsigned char data[] )
|
||||||
{
|
{
|
||||||
unsigned retVal = HID_STATUS_BAD_LOCATION;
|
unsigned retVal = HID_STATUS_IN_USE;
|
||||||
unsigned bSize = hidGetItemSize( header );
|
|
||||||
unsigned bTag = hidGetItemTag ( header );
|
|
||||||
unsigned bType = hidGetItemType( header );
|
|
||||||
|
|
||||||
if(( HID_REPORT_ITEM_MAX_SIZE < bSize ) ||
|
if( !hidReportDescriptorPrepared ) {
|
||||||
( HID_REPORT_ITEM_USAGE_TAG != bTag ) ||
|
retVal = HID_STATUS_BAD_LOCATION;
|
||||||
( HID_REPORT_ITEM_USAGE_TYPE != bType )) {
|
unsigned bSize = hidGetItemSize( header );
|
||||||
retVal = HID_STATUS_BAD_HEADER;
|
unsigned bTag = hidGetItemTag ( header );
|
||||||
} else {
|
unsigned bType = hidGetItemType( header );
|
||||||
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(( bit == bBit ) && ( byte == bByte )) {
|
if(( HID_REPORT_ITEM_MAX_SIZE < bSize ) ||
|
||||||
item.header = header;
|
( 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 ) {
|
if(( bit == bBit ) && ( byte == bByte )) {
|
||||||
item.data[ dataIdx ] = data[ dataIdx ];
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
/**
|
/**
|
||||||
* @brief Human Interface Device (HID) Report descriptor
|
* @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.
|
* 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_GOOD ( 0 )
|
||||||
#define HID_STATUS_BAD_HEADER ( 1 )
|
#define HID_STATUS_BAD_HEADER ( 1 )
|
||||||
#define HID_STATUS_BAD_LOCATION ( 2 )
|
#define HID_STATUS_BAD_LOCATION ( 2 )
|
||||||
|
#define HID_STATUS_IN_USE ( 3 )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USB HID Report Descriptor. Short Item
|
* @brief USB HID Report Descriptor. Short Item
|
||||||
@@ -84,11 +86,19 @@ size_t hidGetReportDescriptorLength( void );
|
|||||||
* @brief Prepare the USB HID Report descriptor
|
* @brief Prepare the USB HID Report descriptor
|
||||||
*
|
*
|
||||||
* After preparation, \c hidGetReportDescriptor() returns a list suitablefor transmission over USB.
|
* After preparation, \c hidGetReportDescriptor() returns a list suitablefor transmission over USB.
|
||||||
*
|
|
||||||
* Call this function after altering one or more Report Items using \c hidSetReportItem().
|
* Call this function after altering one or more Report Items using \c hidSetReportItem().
|
||||||
*/
|
*/
|
||||||
void hidPrepareReportDescriptor( void );
|
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
|
* @brief Modify a HID Report descriptor item
|
||||||
*
|
*
|
||||||
@@ -109,6 +119,7 @@ void hidPrepareReportDescriptor( void );
|
|||||||
* a Tag or Type inconsistent with a Usage Item
|
* 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
|
* @retval \c HID_STATUS_BAD_LOCATION The \a bit or \a byte arguments specify a location outside
|
||||||
* of the HID Report
|
* 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[] );
|
unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsigned char header, const unsigned char data[] );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user