usb_cables: add return to ground check

This commit is contained in:
King Kévin 2019-12-31 11:48:10 +01:00
parent b3aab7616b
commit 3222716361
2 changed files with 18 additions and 9 deletions

View File

@ -4807,16 +4807,19 @@ uint8_t usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_
return connection;
}
void usb_cables_test_ground(const struct usb_connector_t** connectors, uint8_t connectors_nb, bool* connected)
bool 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 || NULL == connected) {
return;
if (NULL == connectors || 0 == connectors_nb) {
return false;
}
// initialize output result
for (uint8_t connector = 0; connector < connectors_nb; connector++) {
connected[connector] = false;
bool connection_found = false;
if (connected) {
for (uint8_t connector = 0; connector < connectors_nb; connector++) {
connected[connector] = false;
}
}
// pull up all ground pins
@ -4858,8 +4861,11 @@ void usb_cables_test_ground(const struct usb_connector_t** connectors, uint8_t c
continue;
}
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;
if (connected) {
connected[connector_from] = true;
connected[connector_to] = true;
}
connection_found = true;
}
}
}
@ -4875,6 +4881,8 @@ void usb_cables_test_ground(const struct usb_connector_t** connectors, uint8_t c
}
}
}
return connection_found;
}
bool usb_cables_test_load(const struct usb_connector_t* connector)

View File

@ -100,12 +100,13 @@ 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
* @param[out] connected which of the connectors are connected (optional)
* @return if at least on ground connection has been found
* @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);
bool 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
* @param[in] connector connector to test
* @return if there is a load on the connector