usb_cables: add optional pin pars field
This commit is contained in:
parent
f80f30eb1e
commit
b3aab7616b
|
@ -397,14 +397,14 @@ static void cable_issues_nb(struct cable_t* cable)
|
|||
continue;
|
||||
}
|
||||
const struct usb_cable_t* usb_cable = &usb_cables[cable_i];
|
||||
cable->unconnected_nb[cable_i] = usb_cable->pin_pairs_nb;
|
||||
cable->unconnected_nb[cable_i] = usb_cable->mandatory_pairs_nb;
|
||||
cable->unspecified_nb[cable_i] = 0;
|
||||
for (uint16_t i = 0; i < cable->connections_nb; i++) {
|
||||
bool match = false;
|
||||
for (uint8_t j = 0; j < usb_cable->pin_pairs_nb; j++) {
|
||||
if (cable->connections[i][0] == usb_cable->pin_pairs[j][0] && cable->connections[i][1] == usb_cable->pin_pairs[j][1]) {
|
||||
for (uint8_t j = 0; j < usb_cable->mandatory_pairs_nb; j++) {
|
||||
if (cable->connections[i][0] == usb_cable->mandatory_pairs[j][0] && cable->connections[i][1] == usb_cable->mandatory_pairs[j][1]) {
|
||||
match = true;
|
||||
} else if (cable->connections[i][0] == usb_cable->pin_pairs[j][1] && cable->connections[i][1] == usb_cable->pin_pairs[j][0]) {
|
||||
} else if (cable->connections[i][0] == usb_cable->mandatory_pairs[j][1] && cable->connections[i][1] == usb_cable->mandatory_pairs[j][0]) {
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
|
@ -450,12 +450,12 @@ static void cable_issues(struct cable_t* cable)
|
|||
|
||||
// find if cable pairs are actual connection
|
||||
const struct usb_cable_t* usb_cable = &usb_cables[cable->cable_best];
|
||||
for (uint16_t i = 0; i < usb_cable->pin_pairs_nb; i++) {
|
||||
for (uint16_t i = 0; i < usb_cable->mandatory_pairs_nb; i++) {
|
||||
bool match = false;
|
||||
for (uint8_t j = 0; j < cable->connections_nb; j++) {
|
||||
if (cable->connections[j][0] == usb_cable->pin_pairs[i][0] && cable->connections[j][1] == usb_cable->pin_pairs[i][1]) {
|
||||
if (cable->connections[j][0] == usb_cable->mandatory_pairs[i][0] && cable->connections[j][1] == usb_cable->mandatory_pairs[i][1]) {
|
||||
match = true;
|
||||
} else if (cable->connections[j][0] == usb_cable->pin_pairs[i][1] && cable->connections[j][1] == usb_cable->pin_pairs[i][0]) {
|
||||
} else if (cable->connections[j][0] == usb_cable->mandatory_pairs[i][1] && cable->connections[j][1] == usb_cable->mandatory_pairs[i][0]) {
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
|
@ -471,18 +471,18 @@ static void cable_issues(struct cable_t* cable)
|
|||
return; // fail-safe return (without indicating error)
|
||||
}
|
||||
cable->unconnected = new_connections;
|
||||
cable->unconnected[cable->unconnected_nb[cable->cable_best] - 1][0] = usb_cable->pin_pairs[i][0];
|
||||
cable->unconnected[cable->unconnected_nb[cable->cable_best] - 1][1] = usb_cable->pin_pairs[i][1];
|
||||
cable->unconnected[cable->unconnected_nb[cable->cable_best] - 1][0] = usb_cable->mandatory_pairs[i][0];
|
||||
cable->unconnected[cable->unconnected_nb[cable->cable_best] - 1][1] = usb_cable->mandatory_pairs[i][1];
|
||||
}
|
||||
}
|
||||
|
||||
// find if connection is defined in cable
|
||||
for (uint16_t i = 0; i < cable->connections_nb; i++) {
|
||||
bool match = false;
|
||||
for (uint8_t j = 0; j < usb_cable->pin_pairs_nb; j++) {
|
||||
if (cable->connections[i][0] == usb_cable->pin_pairs[j][0] && cable->connections[i][1] == usb_cable->pin_pairs[j][1]) {
|
||||
for (uint8_t j = 0; j < usb_cable->mandatory_pairs_nb; j++) {
|
||||
if (cable->connections[i][0] == usb_cable->mandatory_pairs[j][0] && cable->connections[i][1] == usb_cable->mandatory_pairs[j][1]) {
|
||||
match = true;
|
||||
} else if (cable->connections[i][0] == usb_cable->pin_pairs[j][1] && cable->connections[i][1] == usb_cable->pin_pairs[j][0]) {
|
||||
} else if (cable->connections[i][0] == usb_cable->mandatory_pairs[j][1] && cable->connections[i][1] == usb_cable->mandatory_pairs[j][0]) {
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ static void command_cables(void* argument)
|
|||
if (0xff == cable_i || cable == cable_i) {
|
||||
uint8_t pair_defined, pair_undefined;
|
||||
bool result = usb_cables_test_cable(&usb_cables[cable], &pair_defined, &pair_undefined, false);
|
||||
printf("%02u %s: %s (defined=%u/%u, undefined=%u)\n", cable, result ? "OK" : "KO", usb_cables[cable].name, pair_defined, usb_cables[cable].pin_pairs_nb, pair_undefined);
|
||||
printf("%02u %s: %s (defined=%u/%u, undefined=%u)\n", cable, result ? "OK" : "KO", usb_cables[cable].name, pair_defined, usb_cables[cable].mandatory_pairs_nb, pair_undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -637,7 +637,7 @@ static void command_find(void* argument)
|
|||
continue;
|
||||
}
|
||||
uint16_t issues = cable->unconnected_nb[cable_i] + cable->unspecified_nb[cable_i];
|
||||
printf("- %02u %s: %u (unconnected=%u/%u, undefined=%u)\n", cable_i, usb_cables[cable_i].name, issues, cable->unconnected_nb[cable_i], usb_cables[cable_i].pin_pairs_nb, cable->unspecified_nb[cable_i]);
|
||||
printf("- %02u %s: %u (unconnected=%u/%u, undefined=%u)\n", cable_i, usb_cables[cable_i].name, issues, cable->unconnected_nb[cable_i], usb_cables[cable_i].mandatory_pairs_nb, cable->unspecified_nb[cable_i]);
|
||||
}
|
||||
|
||||
// print connection details
|
||||
|
@ -879,7 +879,7 @@ static void command_test(void* argument)
|
|||
uint8_t defined, undefined; // pair counting variables
|
||||
cable_ok = usb_cables_test_cable(&test_cables[cable], &defined, &undefined, true); // test cable
|
||||
if (!cable_ok && defined > 0) { // not all pairs are connected
|
||||
printf("connection issues: defined=%u/%u, undefined=%u\n", defined, test_cables[cable].pin_pairs_nb, undefined); // show issue summary
|
||||
printf("connection issues: defined=%u/%u, undefined=%u\n", defined, test_cables[cable].mandatory_pairs_nb, undefined); // show issue summary
|
||||
}
|
||||
if (!cable_ok) {
|
||||
if (user_input_available) { // user interruption
|
||||
|
|
527
usb_cables.c
527
usb_cables.c
File diff suppressed because it is too large
Load Diff
|
@ -61,8 +61,10 @@ struct usb_cable_t {
|
|||
const char* name; /*< cable name */
|
||||
uint8_t connectors_nb; /*< number of connectors */
|
||||
const struct usb_connector_t** connectors; /*< list of connectors this cables uses */
|
||||
uint8_t pin_pairs_nb; /* number of connected pin pairs */
|
||||
const uint8_t (*pin_pairs)[2]; /*< list of connected pin index pairs (order does not matter) */
|
||||
uint8_t mandatory_pairs_nb; /* number of connected pin pairs */
|
||||
const uint8_t (*mandatory_pairs)[2]; /*< list of connected pin index pairs (order does not matter) */
|
||||
uint8_t optional_pairs_nb; /* number of connected pin pairs */
|
||||
const uint8_t (*optional_pairs)[2]; /*< list of connected pin index pairs (order does not matter) */
|
||||
};
|
||||
|
||||
/** USB pin definitions */
|
||||
|
|
Loading…
Reference in New Issue