usb_cables: return pin interconnection details
This commit is contained in:
parent
e84a481669
commit
95646cd89b
|
@ -1129,22 +1129,22 @@ static void command_cplug(void* argument)
|
||||||
bool gnd_any = false;
|
bool gnd_any = false;
|
||||||
bool gnd_all = true;
|
bool gnd_all = true;
|
||||||
bool gnd;
|
bool gnd;
|
||||||
gnd = usb_cables_test_pins(&usb_pins[connector->pins[1]], &usb_pins[connector->pins[12]]); // A1- A12 GND
|
gnd = usb_cables_test_pins(&usb_pins[connector->pins[1]], &usb_pins[connector->pins[12]], NULL); // A1- A12 GND
|
||||||
gnd_any |= gnd;
|
gnd_any |= gnd;
|
||||||
gnd_all &= gnd;
|
gnd_all &= gnd;
|
||||||
gnd = usb_cables_test_pins(&usb_pins[connector->pins[1]], &usb_pins[connector->pins[12 + 1]]); // A1- B1 GND
|
gnd = usb_cables_test_pins(&usb_pins[connector->pins[1]], &usb_pins[connector->pins[12 + 1]], NULL); // A1- B1 GND
|
||||||
gnd_any |= gnd;
|
gnd_any |= gnd;
|
||||||
gnd_all &= gnd;
|
gnd_all &= gnd;
|
||||||
gnd = usb_cables_test_pins(&usb_pins[connector->pins[1]], &usb_pins[connector->pins[12 + 12]]); // A1- B12 GND
|
gnd = usb_cables_test_pins(&usb_pins[connector->pins[1]], &usb_pins[connector->pins[12 + 12]], NULL); // A1- B12 GND
|
||||||
gnd_any |= gnd;
|
gnd_any |= gnd;
|
||||||
gnd_all &= gnd;
|
gnd_all &= gnd;
|
||||||
gnd = usb_cables_test_pins(&usb_pins[connector->pins[12]], &usb_pins[connector->pins[12 + 1]]); // A12 - B1 GND
|
gnd = usb_cables_test_pins(&usb_pins[connector->pins[12]], &usb_pins[connector->pins[12 + 1]], NULL); // A12 - B1 GND
|
||||||
gnd_any |= gnd;
|
gnd_any |= gnd;
|
||||||
gnd_all &= gnd;
|
gnd_all &= gnd;
|
||||||
gnd = usb_cables_test_pins(&usb_pins[connector->pins[12]], &usb_pins[connector->pins[12 + 12]]); // A12 - B12 GND
|
gnd = usb_cables_test_pins(&usb_pins[connector->pins[12]], &usb_pins[connector->pins[12 + 12]], NULL); // A12 - B12 GND
|
||||||
gnd_any |= gnd;
|
gnd_any |= gnd;
|
||||||
gnd_all &= gnd;
|
gnd_all &= gnd;
|
||||||
gnd = usb_cables_test_pins(&usb_pins[connector->pins[12 + 1]], &usb_pins[connector->pins[12 + 12]]); // B1- B12 GND
|
gnd = usb_cables_test_pins(&usb_pins[connector->pins[12 + 1]], &usb_pins[connector->pins[12 + 12]], NULL); // B1- B12 GND
|
||||||
gnd_any |= gnd;
|
gnd_any |= gnd;
|
||||||
gnd_all &= gnd;
|
gnd_all &= gnd;
|
||||||
printf("- %s GND pins interconnected\n", gnd_all ? "all" : (gnd_any ? "some" : "no"));
|
printf("- %s GND pins interconnected\n", gnd_all ? "all" : (gnd_any ? "some" : "no"));
|
||||||
|
@ -1152,29 +1152,29 @@ static void command_cplug(void* argument)
|
||||||
bool vbus_any = false;
|
bool vbus_any = false;
|
||||||
bool vbus_all = true;
|
bool vbus_all = true;
|
||||||
bool vbus;
|
bool vbus;
|
||||||
vbus = usb_cables_test_pins(&usb_pins[connector->pins[4]], &usb_pins[connector->pins[9]]); // A4- A9 VBUS
|
vbus = usb_cables_test_pins(&usb_pins[connector->pins[4]], &usb_pins[connector->pins[9]], NULL); // A4- A9 VBUS
|
||||||
vbus_any |= vbus;
|
vbus_any |= vbus;
|
||||||
vbus_all &= vbus;
|
vbus_all &= vbus;
|
||||||
vbus = usb_cables_test_pins(&usb_pins[connector->pins[4]], &usb_pins[connector->pins[12 + 4]]); // A4- B4 VBUS
|
vbus = usb_cables_test_pins(&usb_pins[connector->pins[4]], &usb_pins[connector->pins[12 + 4]], NULL); // A4- B4 VBUS
|
||||||
vbus_any |= vbus;
|
vbus_any |= vbus;
|
||||||
vbus_all &= vbus;
|
vbus_all &= vbus;
|
||||||
vbus = usb_cables_test_pins(&usb_pins[connector->pins[4]], &usb_pins[connector->pins[12 + 9]]); // A4- B9 VBUS
|
vbus = usb_cables_test_pins(&usb_pins[connector->pins[4]], &usb_pins[connector->pins[12 + 9]], NULL); // A4- B9 VBUS
|
||||||
vbus_any |= vbus;
|
vbus_any |= vbus;
|
||||||
vbus_all &= vbus;
|
vbus_all &= vbus;
|
||||||
vbus = usb_cables_test_pins(&usb_pins[connector->pins[9]], &usb_pins[connector->pins[12 + 4]]); // A9 - B4 VBUS
|
vbus = usb_cables_test_pins(&usb_pins[connector->pins[9]], &usb_pins[connector->pins[12 + 4]], NULL); // A9 - B4 VBUS
|
||||||
vbus_any |= vbus;
|
vbus_any |= vbus;
|
||||||
vbus_all &= vbus;
|
vbus_all &= vbus;
|
||||||
vbus = usb_cables_test_pins(&usb_pins[connector->pins[9]], &usb_pins[connector->pins[12 + 9]]); // A9 - B9 VBUS
|
vbus = usb_cables_test_pins(&usb_pins[connector->pins[9]], &usb_pins[connector->pins[12 + 9]], NULL); // A9 - B9 VBUS
|
||||||
vbus_any |= vbus;
|
vbus_any |= vbus;
|
||||||
vbus_all &= vbus;
|
vbus_all &= vbus;
|
||||||
vbus = usb_cables_test_pins(&usb_pins[connector->pins[12 + 4]], &usb_pins[connector->pins[12 + 9]]); // B4- B9 VBUS
|
vbus = usb_cables_test_pins(&usb_pins[connector->pins[12 + 4]], &usb_pins[connector->pins[12 + 9]], NULL); // B4- B9 VBUS
|
||||||
vbus_any |= vbus;
|
vbus_any |= vbus;
|
||||||
vbus_all &= vbus;
|
vbus_all &= vbus;
|
||||||
printf("- %s VBUS pins interconnected\n", vbus_all ? "all" : (vbus_any ? "some" : "no"));
|
printf("- %s VBUS pins interconnected\n", vbus_all ? "all" : (vbus_any ? "some" : "no"));
|
||||||
// check if it is a powered cable (VCONN is connected to ground by Ra), or connected to sink
|
// check if it is a powered cable (VCONN is connected to ground by Ra), or connected to sink
|
||||||
bool cc1 = usb_cables_test_pins(&usb_pins[connector->pins[5]], &usb_pins[connector->pins[12 + 1]]); // A5 CC1 - A1 GND
|
bool cc1 = usb_cables_test_pins(&usb_pins[connector->pins[5]], &usb_pins[connector->pins[12 + 1]], NULL); // A5 CC1 - A1 GND
|
||||||
printf("- CC1 %sconnected to GND\n", cc1 ? "" : "not ");
|
printf("- CC1 %sconnected to GND\n", cc1 ? "" : "not ");
|
||||||
bool cc2 = usb_cables_test_pins(&usb_pins[connector->pins[12 + 5]], &usb_pins[connector->pins[12 + 1]]); // B5 CC1 - A1 GND
|
bool cc2 = usb_cables_test_pins(&usb_pins[connector->pins[12 + 5]], &usb_pins[connector->pins[12 + 1]], NULL); // B5 CC1 - A1 GND
|
||||||
printf("- CC2 %sconnected to GND\n", cc2 ? "" : "not ");
|
printf("- CC2 %sconnected to GND\n", cc2 ? "" : "not ");
|
||||||
/*
|
/*
|
||||||
if (cc1 >= 0x41) {
|
if (cc1 >= 0x41) {
|
||||||
|
@ -1194,9 +1194,9 @@ static void command_cplug(void* argument)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// check if it should be connected to a source
|
// check if it should be connected to a source
|
||||||
cc1 = usb_cables_test_pins(&usb_pins[connector->pins[5]], &usb_pins[connector->pins[4]]); // A5 CC1 - A4 VBUS
|
cc1 = usb_cables_test_pins(&usb_pins[connector->pins[5]], &usb_pins[connector->pins[4]], NULL); // A5 CC1 - A4 VBUS
|
||||||
printf("- CC1 %sconnected to VBUS\n", cc1 ? "" : "not ");
|
printf("- CC1 %sconnected to VBUS\n", cc1 ? "" : "not ");
|
||||||
cc2 = usb_cables_test_pins(&usb_pins[connector->pins[12 + 5]], &usb_pins[connector->pins[4]]); // B5 CC1 - A1 VBUS
|
cc2 = usb_cables_test_pins(&usb_pins[connector->pins[12 + 5]], &usb_pins[connector->pins[4]], NULL); // B5 CC1 - A1 VBUS
|
||||||
printf("- CC2 %sconnected to VBUS\n", cc2 ? "" : "not ");
|
printf("- CC2 %sconnected to VBUS\n", cc2 ? "" : "not ");
|
||||||
if (cc1 || cc2) {
|
if (cc1 || cc2) {
|
||||||
puts("- this cable is to be connected to a source on the other end (A plug)\n");
|
puts("- this cable is to be connected to a source on the other end (A plug)\n");
|
||||||
|
@ -1211,13 +1211,13 @@ static void command_cplug(void* argument)
|
||||||
}
|
}
|
||||||
puts("cable interconnection\n");
|
puts("cable interconnection\n");
|
||||||
bool conn;
|
bool conn;
|
||||||
conn = usb_cables_test_pins(&usb_pins[c1->pins[5]], &usb_pins[c2->pins[5]]); // A5 CC1 - A5 CC1
|
conn = usb_cables_test_pins(&usb_pins[c1->pins[5]], &usb_pins[c2->pins[5]], NULL); // A5 CC1 - A5 CC1
|
||||||
printf("- CC1 %sconnected to CC1\n", conn ? "" : "not ");
|
printf("- CC1 %sconnected to CC1\n", conn ? "" : "not ");
|
||||||
conn = usb_cables_test_pins(&usb_pins[c1->pins[5]], &usb_pins[c2->pins[12 + 5]]); // A5 CC1 - B5 CC2
|
conn = usb_cables_test_pins(&usb_pins[c1->pins[5]], &usb_pins[c2->pins[12 + 5]], NULL); // A5 CC1 - B5 CC2
|
||||||
printf("- CC1 %sconnected to CC2\n", conn ? "" : "not ");
|
printf("- CC1 %sconnected to CC2\n", conn ? "" : "not ");
|
||||||
conn = usb_cables_test_pins(&usb_pins[c1->pins[12 + 5]], &usb_pins[c2->pins[5]]); // B5 CC2 - A5 CC1
|
conn = usb_cables_test_pins(&usb_pins[c1->pins[12 + 5]], &usb_pins[c2->pins[5]], NULL); // B5 CC2 - A5 CC1
|
||||||
printf("- CC2 %sconnected to CC1\n", conn ? "" : "not ");
|
printf("- CC2 %sconnected to CC1\n", conn ? "" : "not ");
|
||||||
conn = usb_cables_test_pins(&usb_pins[c1->pins[12 + 5]], &usb_pins[c2->pins[12 + 5]]); // B5 CC2 - B5 CC2
|
conn = usb_cables_test_pins(&usb_pins[c1->pins[12 + 5]], &usb_pins[c2->pins[12 + 5]], NULL); // B5 CC2 - B5 CC2
|
||||||
printf("- CC2 %sconnected to CC2\n", conn ? "" : "not ");
|
printf("- CC2 %sconnected to CC2\n", conn ? "" : "not ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
usb_cables.c
10
usb_cables.c
|
@ -4994,7 +4994,7 @@ const struct usb_connector_t* usb_cables_get_connector(uint8_t pin)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_t* pin2)
|
bool usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_t* pin2, struct usb_connection_t* connection)
|
||||||
{
|
{
|
||||||
cm3_assert(pin1);
|
cm3_assert(pin1);
|
||||||
cm3_assert(pin2);
|
cm3_assert(pin2);
|
||||||
|
@ -5146,6 +5146,10 @@ bool usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_t*
|
||||||
connected &= _connection.rx_drive_float | _connection.rx_drive_pull;
|
connected &= _connection.rx_drive_float | _connection.rx_drive_pull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return connection details
|
||||||
|
if (connection) {
|
||||||
|
memcpy(connection, &_connection, sizeof(struct usb_connection_t));
|
||||||
|
}
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5317,7 +5321,7 @@ bool usb_cables_test_cable(const struct usb_cable_t* cable, uint8_t* defined, ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool connection = usb_cables_test_pins(usb_pin_from, usb_pin_to);
|
const bool connection = usb_cables_test_pins(usb_pin_from, usb_pin_to, NULL);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
if (pair_defined) {
|
if (pair_defined) {
|
||||||
_defined++;
|
_defined++;
|
||||||
|
@ -5416,7 +5420,7 @@ uint8_t** usb_cables_test_connections(const struct usb_connector_t** connectors,
|
||||||
}
|
}
|
||||||
|
|
||||||
// test connection
|
// test connection
|
||||||
const bool connected = usb_cables_test_pins(usb_pin_from, usb_pin_to);
|
const bool connected = usb_cables_test_pins(usb_pin_from, usb_pin_to, NULL);
|
||||||
if (connected) {
|
if (connected) {
|
||||||
if (UINT16_MAX == (*connections_nb)) { // we already found the maximum of connections
|
if (UINT16_MAX == (*connections_nb)) { // we already found the maximum of connections
|
||||||
return (uint8_t**)connections;
|
return (uint8_t**)connections;
|
||||||
|
|
|
@ -224,9 +224,10 @@ const struct usb_connector_t* usb_cables_get_connector(uint8_t pin);
|
||||||
/** test if two pins are connected
|
/** test if two pins are connected
|
||||||
* @param[in] pin1 first pin
|
* @param[in] pin1 first pin
|
||||||
* @param[in] pin2 second pin
|
* @param[in] pin2 second pin
|
||||||
|
* @param[out] connection pins interconnection details (optional)
|
||||||
* @return if the two pins are connected
|
* @return if the two pins are connected
|
||||||
*/
|
*/
|
||||||
bool usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_t* pin2);
|
bool usb_cables_test_pins(const struct usb_pin_t* pin1, const struct usb_pin_t* pin2, struct usb_connection_t* connection);
|
||||||
/** test connectors for connections between ground pins of the connectors
|
/** test connectors for connections between ground pins of the connectors
|
||||||
* @param[in] connectors connectors to test
|
* @param[in] connectors connectors to test
|
||||||
* @param[in] connectors_nb numbers of connectors
|
* @param[in] connectors_nb numbers of connectors
|
||||||
|
|
Loading…
Reference in New Issue