Skip to content

Commit

Permalink
hid: don't stop, just skip a second REPORT ID with a different value
Browse files Browse the repository at this point in the history
  • Loading branch information
gyurco committed Oct 5, 2024
1 parent 28821d0 commit dcf16fe
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions usb/hidparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MAX_AXES; i++) axis[i] = -1;
Expand Down Expand Up @@ -284,7 +285,8 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf
return true;
else {
// retry with next report
memset(conf, 0, sizeof(*conf));
memset(conf, 0, sizeof(hid_report_t));
skip_report = 0;
bit_count = 0;
report_complete = 0;
}
Expand Down Expand Up @@ -318,7 +320,7 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf
hidp_extreme_debugf(" -> 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");

Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
Expand Down

0 comments on commit dcf16fe

Please sign in to comment.