Merge pull request #1 from ACascarino/feature/multiple_hid_reports

Update lib_xua multiple_hid_reports from review
This commit is contained in:
Ciaran Woodward
2021-12-20 17:21:25 +00:00
committed by GitHub
4 changed files with 64 additions and 47 deletions

View File

@@ -29,8 +29,6 @@ unsigned char hidReportDescriptor[] =
};
#endif
#define USB_HID_REPORT_ID_CONSUMER ( 0x02 )
/*
* Define non-configurable items in the HID Report descriptor.
*/
@@ -64,41 +62,56 @@ static const USB_HID_Short_Item_t hidReportCount2 = {
static const USB_HID_Short_Item_t hidReportCount6 = {
.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT),
.data = { 0x06, 0x00 } };
static const USB_HID_Short_Item_t hidReportSize1 = {
.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE),
.data = { 0x01, 0x00 } };
static const USB_HID_Short_Item_t hidUsageConsumerControl = {
.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.data = { 0x01, 0x00 } };
static const USB_HID_Short_Item_t hidUsagePageConsumer = {
.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE),
.data = { 0x0C, 0x00 } };
/*
* Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report
* For internal purposes, a report element with ID of 0 must be included if report IDs are not being used.
*/
static const USB_HID_Report_Element_t hidReportPageConsumer = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE),
.item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 },
.location = HID_REPORT_SET_LOC( 0, 1, 0, 0 ) };
/*
* Define configurable items in the HID Report descriptor.
*/
static USB_HID_Report_Element_t hidUsageByte0Bit5 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE2, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) }; // Mute
static USB_HID_Report_Element_t hidUsageByte0Bit4 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xEA, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) }; // Vol-
static USB_HID_Report_Element_t hidUsageByte0Bit3 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xE9, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) }; // Vol+
static USB_HID_Report_Element_t hidUsageByte0Bit2 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB6, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) }; // Scan Prev
static USB_HID_Report_Element_t hidUsageByte0Bit1 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB5, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) }; // Scan Next
static USB_HID_Report_Element_t hidUsageByte0Bit0 = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .item.data = { 0xB0, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) }; // Play
static USB_HID_Short_Item_t hidReportID1 = {
.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_ID),
.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00} };
static const USB_HID_Report_Element_t hidReportConsumer = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE),
.item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 )
};
static USB_HID_Report_Element_t hidUsageByte0Bit5 = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.data = { 0xE2, 0x00 },
.location = HID_REPORT_SET_LOC( 0, 0, 0, 5 )
}; // Mute
static USB_HID_Report_Element_t hidUsageByte0Bit4 = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.data = { 0xEA, 0x00 },
.location = HID_REPORT_SET_LOC( 0, 0, 0, 4 )
}; // Vol-
static USB_HID_Report_Element_t hidUsageByte0Bit3 = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.data = { 0xE9, 0x00 },
.location = HID_REPORT_SET_LOC( 0, 0, 0, 3 )
}; // Vol+
static USB_HID_Report_Element_t hidUsageByte0Bit2 = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.data = { 0xB6, 0x00 },
.location = HID_REPORT_SET_LOC( 0, 0, 0, 2 )
}; // Scan Prev
static USB_HID_Report_Element_t hidUsageByte0Bit1 = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.data = { 0xB5, 0x00 },
.location = HID_REPORT_SET_LOC( 0, 0, 0, 1 )
}; // Scan Next
static USB_HID_Report_Element_t hidUsageByte0Bit0 = {
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.data = { 0xB0, 0x00 },
.location = HID_REPORT_SET_LOC( 0, 0, 0, 0 )
}; // Play
/*
* List the configurable items in the HID Report descriptor.
@@ -113,18 +126,18 @@ static USB_HID_Report_Element_t* const hidConfigurableElements[] = {
};
/*
* List Usage pages in the HID Report descriptor, one per byte.
* List HID Reports, one per Report ID. This should be a usage page item with the relevant
* If not using report IDs - still have one with report ID 0
*/
static const USB_HID_Short_Item_t * const hidUsagePages[] = {
&hidUsagePageConsumer
static const USB_HID_Report_Element_t* const hidReports[] = {
&hidReportPageConsumer
};
/*
* List all items in the HID Report descriptor.
*/
static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = {
&(hidReportConsumer.item),
&hidUsagePageConsumer,
&(hidReportPageConsumer.item),
&hidUsageConsumerControl,
&hidCollectionApplication,
&hidLogicalMinimum0,
@@ -144,10 +157,6 @@ static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = {
&hidCollectionEnd
};
static const USB_HID_Report_Element_t* const hidReports[] = {
&hidReportConsumer
};
/*
* Define the number of HID Reports
* Due to XC not supporting designated initializers, this constant has a hard-coded value.

View File

@@ -375,18 +375,12 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
#if( 0 < HID_CONTROLS )
UserHIDInit();
{
int hidReportLength = 0;
unsigned hidReportId;
while(0 == hidReportLength) {
for( hidReportId = 0U; hidReportId < hidGetReportIdLimit(); ++hidReportId) {
hidReportLength = (int) hidGetReportLength(hidReportId);
if(0 < hidReportLength) {
break;
}
}
}
while (!hidIsReportDescriptorPrepared())
;
/* Get data from the last report, which which we can prep XUD*/
int hidReportLength = (int) UserHIDGetData(hidGetReportIdLimit() - 1, g_hidData);
hidReportLength = (int) UserHIDGetData(hidReportId, g_hidData);
XUD_SetReady_In(ep_hid, g_hidData, hidReportLength);
}
#endif

View File

@@ -213,6 +213,11 @@ unsigned hidGetNextReportTime( const unsigned id ) {
return retVal;
}
unsigned hidIsReportDescriptorPrepared( void )
{
return s_hidReportDescriptorPrepared;
}
unsigned char* hidGetReportDescriptor( void )
{
unsigned char* retVal = NULL;

View File

@@ -142,6 +142,15 @@ typedef struct
*/
void hidClearChangePending( const unsigned id );
/**
* @brief Indicate if the HID Report descriptor has been prepared
*
* \returns A Boolean indicating whether the HID Report descriptor has been prepared.
* \retval True The HID Report descriptor has been prepared.
* \retval False The HID Report descriptor has not been prepared.
*/
unsigned hidIsReportDescriptorPrepared( void );
/**
* @brief Get the HID Report descriptor
*