usb_cables: add options to connections check

This commit is contained in:
King Kévin 2019-12-13 14:58:18 +01:00
parent b0441f40c5
commit 788a36b175
3 changed files with 14 additions and 3 deletions

View File

@ -529,7 +529,7 @@ static void command_connections(void* argument)
printf("= checking all pin connections =\n");
uint16_t connections_nb = 0;
uint8_t (*connections)[2] = (uint8_t (*)[2])usb_cables_check_connections(usb_connectors, LENGTH(usb_connectors), &connections_nb);
uint8_t (*connections)[2] = (uint8_t (*)[2])usb_cables_check_connections(usb_connectors, LENGTH(usb_connectors), true, false, &connections_nb);
if (NULL == connections) {
if (connections_nb) {
printf("no memory available\n");

View File

@ -4938,7 +4938,7 @@ bool usb_cables_check_cable(const struct usb_cable_t* cable, uint8_t* defined, u
return (0 == _undefined && cable->pin_pairs_nb == _defined);
}
uint8_t** usb_cables_check_connections(const struct usb_connector_t** connectors, uint8_t connectors_nb, uint16_t* connections_nb)
uint8_t** usb_cables_check_connections(const struct usb_connector_t** connectors, uint8_t connectors_nb, bool include_intra, bool ground_only, uint16_t* connections_nb)
{
*connections_nb = 0; // number of connections between the connectors we found
uint8_t (*connections)[2] = NULL; // connections between the connectors we found (pairs of pin index)
@ -4959,7 +4959,13 @@ uint8_t** usb_cables_check_connections(const struct usb_connector_t** connectors
continue;
}
const struct usb_pin_t* usb_pin_from = &usb_pins[pin_from]; // get from pin
if (ground_only && USB_PIN_TYPE_GROUND != usb_pin_from->type) { // enforce ground only rule
continue;
}
for (uint8_t connector_to_i = connector_from_i; connector_to_i < connectors_nb; connector_to_i++) { // test to every connector (yet untested)
if (!include_intra && connector_to_i == connector_from_i) { // don't check internal connections
continue;
}
const struct usb_connector_t* connector_to = connectors[connector_to_i]; // get connector
if (NULL == connector_to) {
continue;
@ -4986,6 +4992,9 @@ uint8_t** usb_cables_check_connections(const struct usb_connector_t** connectors
if (USB_PIN_TYPE_POWER == usb_pin_from->type && (USB_PIN_TYPE_GROUND == usb_pin_to->type || USB_PIN_TYPE_SHIELD == usb_pin_to->type)) {
continue;
}
if (ground_only && USB_PIN_TYPE_GROUND != usb_pin_to->type) { // enforce ground only rule
continue;
}
// test connection
uint8_t connection = usb_cables_check_pins(usb_pin_from, usb_pin_to);

View File

@ -133,8 +133,10 @@ bool usb_cables_check_cable(const struct usb_cable_t* cable, uint8_t* defined, u
/** check connections between connectors
* @param[in] connectors connectors to check
* @param[in] connectors_nb numbers of connectors
* @param[in] include_intra if connections between pins within a connector should be checked
* @param[in] ground_only only check connections between ground pins
* @param[out] connections_nb number of connections found
* @return list of pin pairs connections (NULL if 0 connections have been found or no connections have been found but no memory is available)
* @the list of pin pairs connections is allocated memory which should be freed by the caller
*/
uint8_t** usb_cables_check_connections(const struct usb_connector_t** connectors, uint8_t connectors_nb, uint16_t* connections_nb);
uint8_t** usb_cables_check_connections(const struct usb_connector_t** connectors, uint8_t connectors_nb, bool include_intra, bool ground_only, uint16_t* connections_nb);