From dcf16fe19ed209da354c554275afd11914a03c0f Mon Sep 17 00:00:00 2001 From: Gyorgy Szombathelyi <8644936+gyurco@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:25:42 +0200 Subject: [PATCH] hid: don't stop, just skip a second REPORT ID with a different value --- usb/hidparser.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/usb/hidparser.c b/usb/hidparser.c index 1f8cae4..3b54eb3 100644 --- a/usb/hidparser.c +++ b/usb/hidparser.c @@ -88,6 +88,7 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf uint8_t i; // + int8_t skip_report = 0; uint8_t report_size, report_count; uint16_t bit_count = 0, usage_count = 0; uint16_t logical_minimum=0, logical_maximum=0; @@ -229,7 +230,7 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf hidp_extreme_debugf("INPUT(%d)", value); // reset for next inputs - bit_count += report_count * report_size; + if (!skip_report) bit_count += report_count * report_size; usage_count = 0; btns = 0; for (i=0; i Consumer"); } else if(value == USAGE_PAGE_BUTTON) { hidp_extreme_debugf(" -> Buttons"); - btns = 1; + if (!skip_report) btns = 1; } else if(value == USAGE_PAGE_GENERIC_DESKTOP) { hidp_extreme_debugf(" -> Generic Desktop"); @@ -331,22 +333,22 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf case 1: hidp_extreme_debugf("LOGICAL_MINIMUM(%d/%d)", value, (int16_t)value); - logical_minimum = value; + if (!skip_report) logical_minimum = value; break; case 2: hidp_extreme_debugf("LOGICAL_MAXIMUM(%d)", value); - logical_maximum = value; + if (!skip_report) logical_maximum = value; break; case 3: hidp_extreme_debugf("PHYSICAL_MINIMUM(%d/%d)", value, (int16_t)value); - physical_minimum = value; + if (!skip_report) physical_minimum = value; break; case 4: hidp_extreme_debugf("PHYSICAL_MAXIMUM(%d)", value); - physical_maximum = value; + if (!skip_report) physical_maximum = value; break; case 5: @@ -359,30 +361,32 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf case 7: hidp_extreme_debugf("REPORT_SIZE(%d)", value); - report_size = value; + if (!skip_report) report_size = value; break; case 8: // Next report is beginning from this point - // If we're already got report descriptor and it's satisfies us - stop further parsing + // If we're already got report descriptor and it's satisfies us - skip the report if it has a different ID + hidp_extreme_debugf("REPORT_ID(%d)", value); if (conf->report_id) { if(report_is_usable(bit_count, report_complete, conf)) { - return true; + skip_report = (conf->report_id == value) ? 0 : 1; + break; } - else { + else if (skip_report) { // reset report items and try with next report - memset(conf, 0, sizeof(*conf)); + memset(conf, 0, sizeof(hid_report_t)); + skip_report = 0; bit_count = 0; report_complete = 0; } } - hidp_extreme_debugf("REPORT_ID(%d)", value); conf->report_id = value; break; case 9: hidp_extreme_debugf("REPORT_COUNT(%d)", value); - report_count = value; + if (!skip_report) report_count = value; break; default: @@ -425,23 +429,23 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf if((conf->type == REPORT_TYPE_JOYSTICK) || (conf->type == REPORT_TYPE_MOUSE)) { if(value == USAGE_X) { hidp_extreme_debugf("JOYSTICK/MOUSE: found x axis @ %d", usage_count); - axis[0] = usage_count; + if (!skip_report) axis[0] = usage_count; } if(value == USAGE_Y) { hidp_extreme_debugf("JOYSTICK/MOUSE: found y axis @ %d", usage_count); - axis[1] = usage_count; + if (!skip_report) axis[1] = usage_count; } if(value == USAGE_Z) { hidp_extreme_debugf("JOYSTICK/MOUSE: found z axis @ %d", usage_count); - if (axis[2] == -1) axis[2] = usage_count; // don't override wheel + if (!skip_report) if (axis[2] == -1) axis[2] = usage_count; // don't override wheel } if(value == USAGE_RX || value == USAGE_RY || value == USAGE_RZ) { hidp_extreme_debugf("JOYSTICK/MOUSE: found R%c axis @ %d", 'X'+(value-USAGE_RX), usage_count); - if (axis[3] == -1) axis[3] = usage_count; + if (!skip_report) if (axis[3] == -1) axis[3] = usage_count; } if(value == USAGE_WHEEL) { hidp_extreme_debugf("MOUSE: found wheel @ %d", usage_count); - axis[2] = usage_count; + if (!skip_report) axis[2] = usage_count; } } } else if((value == USAGE_HAT) && app_collection) { @@ -451,7 +455,7 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf // we support hat on joysticks only if(conf->type == REPORT_TYPE_JOYSTICK) { hidp_extreme_debugf("JOYSTICK: found hat @ %d", usage_count); - hat = usage_count; + if (!skip_report) hat = usage_count; } } else { hidp_extreme_debugf(" -> UNSUPPORTED USAGE");