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 12, 2024
1 parent ddd254f commit e766bb6
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 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 Down Expand Up @@ -364,19 +366,22 @@ bool parse_report_descriptor(uint8_t *rep, uint16_t rep_size, hid_report_t *conf

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;
if (skip_report) hidp_extreme_debugf(" -> skip report %d", value);
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;

Expand Down Expand Up @@ -425,23 +430,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,24 +456,24 @@ 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");
// return false;
}

usage_count++;
if (!skip_report) usage_count++;
break;

case 1:
hidp_extreme_debugf("USAGE_MINIMUM(%d)", value);
usage_count -= (value-1);
if (!skip_report) usage_count -= (value-1);
break;

case 2:
hidp_extreme_debugf("USAGE_MAXIMUM(%d)", value);
usage_count += value;
if (!skip_report) usage_count += value;
break;

default:
Expand Down

0 comments on commit e766bb6

Please sign in to comment.