usb_cables: remove print from ground check

This commit is contained in:
King Kévin 2019-12-30 19:56:44 +01:00
parent c66e19f714
commit bdb5b740db
2 changed files with 20 additions and 30 deletions

View File

@ -4647,15 +4647,13 @@ uint8_t usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_
void usb_cables_test_ground(const struct usb_connector_t** connectors, uint8_t connectors_nb, bool* connected)
{
// verify input arguments
if (NULL == connectors || 0 == connectors_nb) {
if (NULL == connectors || 0 == connectors_nb || NULL == connected) {
return;
}
// initialize output result
if (connected) {
for (uint8_t connector = 0; connector < connectors_nb; connector++) {
connected[connector] = false;
}
for (uint8_t connector = 0; connector < connectors_nb; connector++) {
connected[connector] = false;
}
// pull up all ground pins
@ -4669,9 +4667,14 @@ void usb_cables_test_ground(const struct usb_connector_t** connectors, uint8_t c
}
}
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
for (uint8_t connector_from = 0; connector_from < connectors_nb; connector_from++) { // test from every connector
if (connected[connector_from]) { // we already found ground on this connector
continue;
}
for (uint8_t pin_from = 0; pin_from < connectors[connector_from]->pins_nb; pin_from++) { // test from every pin
if (connected[connector_from]) { // we already found ground on this connector
break;
}
const struct usb_pin_t* usb_pin_from = &usb_pins[connectors[connector_from]->pins[pin_from]]; // get from pin
if (USB_PIN_TYPE_GROUND != usb_pin_from->type) { // only consider ground connections
continue;
@ -4680,37 +4683,23 @@ void usb_cables_test_ground(const struct usb_connector_t** connectors, uint8_t c
gpio_set_mode(usb_pin_from->port, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, usb_pin_from->pin);
gpio_clear(usb_pin_from->port, usb_pin_from->pin);
for (uint8_t connector_to = connector_from + 1; connector_to < connectors_nb; connector_to++) { // test every next connector
if (connected && connected[connector_to]) { // we already found a connection to this connector
if (connected[connector_to]) { // we already found a grond connection to this connector
continue;
}
for (uint8_t pin_to = 0; pin_to < connectors[connector_to]->pins_nb; pin_to++) { // test to every pin
if (connected[connector_to]) { // we already found a ground connection to this connector
break;
}
const struct usb_pin_t* usb_pin_to = &usb_pins[connectors[connector_to]->pins[pin_to]]; // get to pin
if (USB_PIN_TYPE_GROUND != usb_pin_to->type) { // only consider ground connections
continue;
}
if (0 == gpio_get(usb_pin_to->port, usb_pin_to->pin)) { // we found a ground interconnection
if (connected) { // remember they are connected
connected[connector_from] = true;
connected[connector_to] = true;
} else {
printf("%s ", connectors[connector_from]->name);
if (connectors[connector_from]->variant) {
printf("(%s) ", connectors[connector_from]->variant);
}
printf(usb_pin_from->name);
printf("%s connected to %s ", usb_pin_from->name, connectors[connector_to]->name);
if (connectors[connector_to]->variant) {
printf("(%s) ", connectors[connector_to]->variant);
}
printf("%s\n", usb_pin_to->name);
}
ground_found = true; // remember we found a ground connection
if (0 == gpio_get(usb_pin_to->port, usb_pin_to->pin)) { // we found a ground connection
connected[connector_from] = true;
connected[connector_to] = true;
}
}
}
// pull pin back up
gpio_set_mode(usb_pin_from->port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, usb_pin_from->pin);
gpio_set(usb_pin_from->port, usb_pin_from->pin);
}
}

View File

@ -98,9 +98,10 @@ uint8_t usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_
/** test connectors for connections between ground pins of the connectors
* @param[in] connectors connectors to test
* @param[in] connectors_nb numbers of connectors
* @param[out] connected which of the connectors are connected (NULL to just print the connections)
* @param[out] connected which of the connectors are connected
* @note connection between pin on the same connector are not tested
* @note it assumes all grounds are connected (e.g. only one cable is connected)
* @note this check is very fast
*/
void usb_cables_test_ground(const struct usb_connector_t** connectors, uint8_t connectors_nb, bool* connected);
/** test if there is a load on the connector