forked from PAWPAW-Mirror/lib_xua
Add Report descriptor length function. Change the internal Translate function to return the length of each item added to the raw buffer. Fix some out-of-date comments.
This commit is contained in:
@@ -154,6 +154,7 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = {
|
|||||||
( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE ))
|
( sizeof ( USB_HID_Short_Item_t ) - HID_REPORT_ITEM_LOCATION_SIZE ))
|
||||||
|
|
||||||
static unsigned char hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ];
|
static unsigned char hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ];
|
||||||
|
static size_t hidReportDescriptorLength = 0;
|
||||||
static unsigned hidReportDescriptorPrepared = 0;
|
static unsigned hidReportDescriptorPrepared = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -216,12 +217,14 @@ static unsigned hidGetItemType( const unsigned char header );
|
|||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
*
|
*
|
||||||
* @param[in] inPtr A pointer to a \c USB_HID_Short_Item
|
* @param[in] inPtr A pointer to a \c USB_HID_Short_Item
|
||||||
* @param[in,out] outPtr A pointer to the next available space in the raw byte buffer
|
* @param[in,out] outPtrPtr A pointer to a pointer to the next available space in the raw
|
||||||
|
* byte buffer. Passed as a pointer to a pointer to allow this
|
||||||
|
* function to return the updated pointer to the raw byte buffer.
|
||||||
*
|
*
|
||||||
* @return The updated \a outPtr
|
* @return The number of bytes placed in the raw byte buffer
|
||||||
*/
|
*/
|
||||||
static unsigned char* hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char* outPtr );
|
static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr );
|
||||||
|
|
||||||
|
|
||||||
static unsigned hidGetItemBitLocation( const unsigned char location )
|
static unsigned hidGetItemBitLocation( const unsigned char location )
|
||||||
@@ -265,12 +268,18 @@ unsigned char* hidGetReportDescriptor( void )
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t hidGetReportDescriptorLength( void )
|
||||||
|
{
|
||||||
|
return ( hidReportDescriptorPrepared ) ? hidReportDescriptorLength : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void hidPrepareReportDescriptor( void )
|
void hidPrepareReportDescriptor( void )
|
||||||
{
|
{
|
||||||
if( !hidReportDescriptorPrepared ) {
|
if( !hidReportDescriptorPrepared ) {
|
||||||
|
hidReportDescriptorLength = 0;
|
||||||
unsigned char* ptr = hidReportDescriptor;
|
unsigned char* ptr = hidReportDescriptor;
|
||||||
for( unsigned idx = 0; idx < sizeof hidReportDescriptorItems / sizeof( USB_HID_Short_Item_t ); ++idx ) {
|
for( unsigned idx = 0; idx < sizeof hidReportDescriptorItems / sizeof( USB_HID_Short_Item_t ); ++idx ) {
|
||||||
ptr = hidTranslateItem( hidReportDescriptorItems[ idx ], ptr );
|
hidReportDescriptorLength += hidTranslateItem( hidReportDescriptorItems[ idx ], &ptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
hidReportDescriptorPrepared = 1;
|
hidReportDescriptorPrepared = 1;
|
||||||
@@ -311,14 +320,16 @@ unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsign
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char* hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char* outPtr )
|
static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr )
|
||||||
{
|
{
|
||||||
*outPtr++ = inPtr->header;
|
size_t count = 0;
|
||||||
|
*(*outPtrPtr)++ = inPtr->header;
|
||||||
|
|
||||||
unsigned dataLength = hidGetItemSize( inPtr->header );
|
unsigned dataLength = hidGetItemSize( inPtr->header );
|
||||||
for( unsigned idx = 0; idx < dataLength; ++idx ) {
|
for( unsigned idx = 0; idx < dataLength; ++idx ) {
|
||||||
*outPtr++ = inPtr->data[ idx ];
|
*(*outPtrPtr)++ = inPtr->data[ idx ];
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return outPtr;
|
return count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,13 +56,24 @@ typedef struct
|
|||||||
* @brief Get the HID Report descriptor
|
* @brief Get the HID Report descriptor
|
||||||
*
|
*
|
||||||
* This function returns a pointer to the USB HID Report descriptor.
|
* This function returns a pointer to the USB HID Report descriptor.
|
||||||
* It returns NULL if the Report descriptor has not been initialised,
|
* It returns NULL if the Report descriptor has not been prepared,
|
||||||
* i.e., no one has called \c hidInitReportDescriptor().
|
* i.e., no one has called \c hidPrepareReportDescriptor().
|
||||||
*
|
*
|
||||||
* @return A pointer to a list of unsigned char containing the Report descriptor
|
* @return A pointer to a list of unsigned char containing the Report descriptor
|
||||||
*/
|
*/
|
||||||
unsigned char* hidGetReportDescriptor( void );
|
unsigned char* hidGetReportDescriptor( void );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the length of the HID Report descriptor
|
||||||
|
*
|
||||||
|
* This function returns the length of the USB HID Report descriptor.
|
||||||
|
* It returns zero if the Report descriptor has not been prepared,
|
||||||
|
* i.e., no one has called \c hidPrepareReportDescriptor().
|
||||||
|
*
|
||||||
|
* @return The length of the Report descriptor in bytes
|
||||||
|
*/
|
||||||
|
size_t hidGetReportDescriptorLength( void );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prepare the USB HID Report descriptor
|
* @brief Prepare the USB HID Report descriptor
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user