usb_cables: add options to connections check
This commit is contained in:
parent
b0441f40c5
commit
788a36b175
|
@ -529,7 +529,7 @@ static void command_connections(void* argument)
|
||||||
|
|
||||||
printf("= checking all pin connections =\n");
|
printf("= checking all pin connections =\n");
|
||||||
uint16_t connections_nb = 0;
|
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 (NULL == connections) {
|
||||||
if (connections_nb) {
|
if (connections_nb) {
|
||||||
printf("no memory available\n");
|
printf("no memory available\n");
|
||||||
|
|
11
usb_cables.c
11
usb_cables.c
|
@ -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);
|
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
|
*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)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
const struct usb_pin_t* usb_pin_from = &usb_pins[pin_from]; // get from pin
|
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)
|
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
|
const struct usb_connector_t* connector_to = connectors[connector_to_i]; // get connector
|
||||||
if (NULL == connector_to) {
|
if (NULL == connector_to) {
|
||||||
continue;
|
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)) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (ground_only && USB_PIN_TYPE_GROUND != usb_pin_to->type) { // enforce ground only rule
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// test connection
|
// test connection
|
||||||
uint8_t connection = usb_cables_check_pins(usb_pin_from, usb_pin_to);
|
uint8_t connection = usb_cables_check_pins(usb_pin_from, usb_pin_to);
|
||||||
|
|
|
@ -133,8 +133,10 @@ bool usb_cables_check_cable(const struct usb_cable_t* cable, uint8_t* defined, u
|
||||||
/** check connections between connectors
|
/** check connections between connectors
|
||||||
* @param[in] connectors connectors to check
|
* @param[in] connectors connectors to check
|
||||||
* @param[in] connectors_nb numbers of connectors
|
* @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
|
* @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)
|
* @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
|
* @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);
|
||||||
|
|
Loading…
Reference in New Issue