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 #endif
#define USB_HID_REPORT_ID_CONSUMER ( 0x02 )
/* /*
* Define non-configurable items in the HID Report descriptor. * 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 = { 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), .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT),
.data = { 0x06, 0x00 } }; .data = { 0x06, 0x00 } };
static const USB_HID_Short_Item_t hidReportSize1 = { 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), .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE),
.data = { 0x01, 0x00 } }; .data = { 0x01, 0x00 } };
static const USB_HID_Short_Item_t hidUsageConsumerControl = { static const USB_HID_Short_Item_t hidUsageConsumerControl = {
.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.data = { 0x01, 0x00 } }; .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. * 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 }, static USB_HID_Report_Element_t hidUsageByte0Bit5 = {
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) }; // Mute .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
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 }, .item.data = { 0xE2, 0x00 },
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) }; // Vol- .location = HID_REPORT_SET_LOC( 0, 0, 0, 5 )
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 }, }; // Mute
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) }; // Vol+ static USB_HID_Report_Element_t hidUsageByte0Bit4 = {
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 }, .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) }; // Scan Prev .item.data = { 0xEA, 0x00 },
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, 4 )
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) }; // Scan Next }; // Vol-
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 }, static USB_HID_Report_Element_t hidUsageByte0Bit3 = {
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) }; // Play .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.data = { 0xE9, 0x00 },
static USB_HID_Short_Item_t hidReportID1 = { .location = HID_REPORT_SET_LOC( 0, 0, 0, 3 )
.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_ID), }; // Vol+
.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00} }; static USB_HID_Report_Element_t hidUsageByte0Bit2 = {
static const USB_HID_Report_Element_t hidReportConsumer = { .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE),
.item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), .item.data = { 0xB6, 0x00 },
.item.data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }, .location = HID_REPORT_SET_LOC( 0, 0, 0, 2 )
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 ) }; // 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. * 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[] = { static const USB_HID_Report_Element_t* const hidReports[] = {
&hidUsagePageConsumer &hidReportPageConsumer
}; };
/* /*
* List all items in the HID Report descriptor. * List all items in the HID Report descriptor.
*/ */
static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = { static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = {
&(hidReportConsumer.item), &(hidReportPageConsumer.item),
&hidUsagePageConsumer,
&hidUsageConsumerControl, &hidUsageConsumerControl,
&hidCollectionApplication, &hidCollectionApplication,
&hidLogicalMinimum0, &hidLogicalMinimum0,
@@ -144,10 +157,6 @@ static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = {
&hidCollectionEnd &hidCollectionEnd
}; };
static const USB_HID_Report_Element_t* const hidReports[] = {
&hidReportConsumer
};
/* /*
* Define the number of HID Reports * Define the number of HID Reports
* Due to XC not supporting designated initializers, this constant has a hard-coded value. * 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 ) #if( 0 < HID_CONTROLS )
UserHIDInit(); UserHIDInit();
{ {
int hidReportLength = 0; while (!hidIsReportDescriptorPrepared())
unsigned hidReportId; ;
while(0 == hidReportLength) {
for( hidReportId = 0U; hidReportId < hidGetReportIdLimit(); ++hidReportId) { /* Get data from the last report, which which we can prep XUD*/
hidReportLength = (int) hidGetReportLength(hidReportId); int hidReportLength = (int) UserHIDGetData(hidGetReportIdLimit() - 1, g_hidData);
if(0 < hidReportLength) {
break;
}
}
}
hidReportLength = (int) UserHIDGetData(hidReportId, g_hidData);
XUD_SetReady_In(ep_hid, g_hidData, hidReportLength); XUD_SetReady_In(ep_hid, g_hidData, hidReportLength);
} }
#endif #endif

View File

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

View File

@@ -142,6 +142,15 @@ typedef struct
*/ */
void hidClearChangePending( const unsigned id ); 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 * @brief Get the HID Report descriptor
* *