usb_cables: minor, make more readable

This commit is contained in:
King Kévin 2019-12-09 13:49:30 +01:00
parent 4735911444
commit 76d8a23281
1 changed files with 4 additions and 10 deletions

View File

@ -1530,9 +1530,9 @@ void usb_cables_check_ground(const struct usb_connector_t** connectors, uint8_t
}
}
bool gnd_found = false; // if we found the ground connection
for (uint8_t connector_from = 0; connector_from < connectors_nb; connector_from++) { // test from every connector
for (uint8_t pin_from = 0; pin_from < connectors[connector_from]->pins_nb; pin_from++) { // test from every pin
bool ground_found = false; // if we found the ground connection
for (uint8_t connector_from = 0; connector_from < connectors_nb && !ground_found; connector_from++) { // test from every connector
for (uint8_t pin_from = 0; pin_from < connectors[connector_from]->pins_nb && !ground_found; pin_from++) { // test from every pin
if (!connectors[connector_from]->pins[pin_from].gnd) { // only consider ground connections
continue;
}
@ -1558,19 +1558,13 @@ void usb_cables_check_ground(const struct usb_connector_t** connectors, uint8_t
} else {
printf("%s (%s) %s connected to %s (%s) %s\n", connectors[connector_from]->name, connectors[connector_from]->host ? "host" : "device", connectors[connector_from]->pins[pin_from].name, connectors[connector_to]->name, connectors[connector_to]->host ? "host" : "device", connectors[connector_to]->pins[pin_to].name);
}
gnd_found = true; // remember we found a ground connection
ground_found = true; // remember we found a ground connection
}
}
}
// pull pin back up
gpio_set_mode(pin_from_port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, pin_from_pin);
gpio_set(pin_from_port, pin_from_pin);
if (gnd_found) { // we found all ground connections
break; // search is finished
}
}
if (gnd_found) { // we found all ground connections
break; // search is finished
}
}