diff --git a/application.c b/application.c
index 861dcca..b9cf751 100644
--- a/application.c
+++ b/application.c
@@ -118,6 +118,80 @@ static void standby(void)
}
+/** print the pin connection details
+ * @param[in] connection connection details to print
+ */
+static void print_connection(struct usb_connection_t* connection)
+{
+ if (NULL == connection) {
+ return;
+ }
+
+ // count number of connections_nb to print between the connections
+ uint8_t connections_nb = 0;
+ if (connection->tx_pull_float) {
+ connections_nb++;
+ }
+ if (connection->tx_drive_float) {
+ connections_nb++;
+ }
+ if (connection->tx_drive_pull) {
+ connections_nb++;
+ }
+ if (connection->rx_pull_float) {
+ connections_nb++;
+ }
+ if (connection->rx_drive_float) {
+ connections_nb++;
+ }
+ if (connection->rx_drive_pull) {
+ connections_nb++;
+ }
+
+ // print connections
+ if (0 == connections_nb) {
+ puts("no connections");
+ return;
+ } else {
+ connections_nb--; // one less separator
+ }
+ if (connection->tx_pull_float) {
+ puts("P>F");
+ if (connections_nb--) {
+ puts(", ");
+ }
+ }
+ if (connection->tx_drive_float) {
+ puts("D>F");
+ if (connections_nb--) {
+ puts(", ");
+ }
+ }
+ if (connection->tx_drive_pull) {
+ puts("D>P");
+ if (connections_nb--) {
+ puts(", ");
+ }
+ }
+ if (connection->rx_pull_float) {
+ puts("F
rx_drive_float) {
+ puts("Frx_drive_pull) {
+ puts("P/< direction\n");
usb_cables_pins_float(); // put all pins to float before making checks
@@ -1167,34 +1242,42 @@ static void command_cplug(void* argument)
vbus_all &= vbus;
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
- 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 ");
- 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 ");
-/*
- if (cc1 >= 0x41) {
- puts("- this is a powered cable (CC1 is VCONN)\n");
- } else if (cc1 >= 0x21) {
- puts("- this cable is to be connected to a sink on the other end (B, mini-B, or micro-B plug)\n");
- } else if (cc2 >= 0x41) {
- puts("- this is a powered cable (CC2 is VCONN)\n");
- } else if (cc2 >= 0x21) {
- puts("- this cable is to be connected to a sink on the other end (B, mini-B, or micro-B plug)\n");
+ struct usb_connection_t cc1_connection;
+ bool cc1 = usb_cables_test_pins(&usb_pins[connector->pins[5]], &usb_pins[connector->pins[12 + 1]], &cc1_connection); // A5 CC1 - A1 GND
+ printf("- CC1 %sconnected to GND (", cc1 ? "" : "not ");
+ print_connection(&cc1_connection);
+ puts(")\n");
+ struct usb_connection_t cc2_connection;
+ bool cc2 = usb_cables_test_pins(&usb_pins[connector->pins[12 + 5]], &usb_pins[connector->pins[12 + 1]], &cc2_connection); // B5 CC1 - A1 GND
+ printf("- CC2 %sconnected to GND (", cc2 ? "" : "not ");
+ print_connection(&cc2_connection);
+ puts(")\n");
+ if (cc1_connection.tx_drive_pull && cc1_connection.rx_pull_float) {
+ puts("> this is a powered cable (CC1 is VCONN)\n");
+ } else if (cc1_connection.tx_drive_float && cc1_connection.rx_pull_float) {
+ puts("> this cable is to be connected to a sink on the other end (B, mini-B, or micro-B plug)\n");
+ } else if (cc2_connection.tx_drive_pull && cc2_connection.rx_pull_float) {
+ puts("> this is a powered cable (CC2 is VCONN)\n");
+ } else if (cc2_connection.tx_drive_float && cc2_connection.rx_pull_float) {
+ puts("> this cable is to be connected to a sink on the other end (B, mini-B, or micro-B plug)\n");
} else if (gnd_all && vbus_all) {
- puts("- this is an unpowered cable\n");
- } else if (gnd_any || vbus_any) {
- puts("- this is a faulty unpowered cable\n");
+ puts("> this is an unpowered cable\n");
+ } else if (gnd_all || vbus_all || gnd_any || vbus_any) {
+ puts("> this is a faulty unpowered cable\n");
} else {
- puts("- there is no plug/cable\n");
+ puts("> there is no plug/cable\n");
}
-*/
// check if it should be connected to a source
- 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 ");
- 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 ");
+ cc1 = usb_cables_test_pins(&usb_pins[connector->pins[5]], &usb_pins[connector->pins[4]], &cc1_connection); // A5 CC1 - A4 VBUS
+ printf("- CC1 %sconnected to VBUS (", cc1 ? "" : "not ");
+ print_connection(&cc1_connection);
+ puts(")\n");
+ cc2 = usb_cables_test_pins(&usb_pins[connector->pins[12 + 5]], &usb_pins[connector->pins[4]], &cc2_connection); // B5 CC1 - A1 VBUS
+ printf("- CC2 %sconnected to VBUS (", cc2 ? "" : "not ");
+ print_connection(&cc2_connection);
+ puts(")\n");
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");
}
}
@@ -1205,15 +1288,24 @@ static void command_cplug(void* argument)
return;
}
puts("cable interconnection\n");
- bool conn;
- 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 ");
- 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 ");
- 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 ");
- 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 ");
+ struct usb_connection_t connection;
+ bool connected;
+ connected = usb_cables_test_pins(&usb_pins[c1->pins[5]], &usb_pins[c2->pins[5]], &connection); // A5 CC1 - A5 CC1
+ printf("- CC1 %sconnected to CC1 (", connected ? "" : "not ");
+ print_connection(&connection);
+ puts(")\n");
+ connected = usb_cables_test_pins(&usb_pins[c1->pins[5]], &usb_pins[c2->pins[12 + 5]], &connection); // A5 CC1 - B5 CC2
+ printf("- CC1 %sconnected to CC2 (", connected ? "" : "not ");
+ print_connection(&connection);
+ puts(")\n");
+ connected = usb_cables_test_pins(&usb_pins[c1->pins[12 + 5]], &usb_pins[c2->pins[5]], &connection); // B5 CC2 - A5 CC1
+ printf("- CC2 %sconnected to CC1 (", connected ? "" : "not ");
+ print_connection(&connection);
+ puts(")\n");
+ connected = usb_cables_test_pins(&usb_pins[c1->pins[12 + 5]], &usb_pins[c2->pins[12 + 5]], &connection); // B5 CC2 - B5 CC2
+ printf("- CC2 %sconnected to CC2 (", connected ? "" : "not ");
+ print_connection(&connection);
+ puts(")\n");
}
// ====================