application: add individual USB connector and cable test commands
This commit is contained in:
parent
a5a5b06926
commit
4f4a16b9db
146
application.c
146
application.c
|
@ -122,34 +122,136 @@ static void command_reset(void* argument);
|
|||
*/
|
||||
static void command_bootloader(void* argument);
|
||||
|
||||
/** test USB cable
|
||||
/** test USB connectors intra-connections
|
||||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void command_test(void* argument)
|
||||
static void command_intra(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
|
||||
usb_pins_float(); // start with all pins in safe floating state
|
||||
|
||||
// step 0: check for internal shorts on each connector
|
||||
printf("= intra-connector check =\n");
|
||||
for (uint8_t connector = 0; connector < LENGTH(usb_connectors); connector++) { // test from every connector
|
||||
usb_cables_check_intra(&usb_connectors[connector]);
|
||||
printf("- %s -\n", usb_connectors[connector].name);
|
||||
usb_cables_check_intra(&usb_connectors[connector], NULL);
|
||||
}
|
||||
|
||||
usb_pins_float(); // put all pins back in safe floating state
|
||||
}
|
||||
|
||||
/** test USB connectors inter-connections
|
||||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void command_inter(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
|
||||
usb_pins_float(); // start with all pins in safe floating state
|
||||
|
||||
// step 1: find which connectors are connected
|
||||
printf("= inter-connector check =\n");
|
||||
usb_cables_check_inter(usb_connectors, LENGTH(usb_connectors));
|
||||
usb_cables_check_inter(usb_connectors, LENGTH(usb_connectors), NULL);
|
||||
|
||||
usb_pins_float(); // put all pins back in safe floating state
|
||||
}
|
||||
|
||||
/** test USB cables
|
||||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void command_cables(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
|
||||
usb_pins_float(); // start with all pins in safe floating state
|
||||
|
||||
// step 2: check for known cable configuration
|
||||
printf("= cable check =\n");
|
||||
for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) { // test from every connector
|
||||
for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) { // test every cable
|
||||
uint8_t pair_defined, pair_undefined, pair_disconnected, pair_error;
|
||||
printf("%s:", usb_cables[cable].name);
|
||||
bool result = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected, &pair_error);
|
||||
printf("%s (defined=%u, undefined=%u, disconnected=%u, error=%u)\n", result ? "ok" : "ko", pair_defined, pair_undefined, pair_disconnected, pair_error);
|
||||
}
|
||||
|
||||
usb_pins_float(); // put all pins back in safe floating state
|
||||
}
|
||||
|
||||
/** find out which USB cable is connected
|
||||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void command_find(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
|
||||
usb_pins_float(); // start with all pins in safe floating state
|
||||
|
||||
// figure out which connectors are used
|
||||
bool connected[LENGTH(usb_connectors)];
|
||||
usb_cables_check_inter(usb_connectors, LENGTH(usb_connectors), connected);
|
||||
uint8_t connected_nb = 0;
|
||||
printf("connectors:");
|
||||
for (uint8_t i = 0; i < LENGTH(connected); i++) {
|
||||
if (connected[i]) {
|
||||
printf(" %s", usb_connectors[i].name);
|
||||
connected_nb++;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// find matching cable
|
||||
uint8_t matches = 0; // number of matching cables
|
||||
printf("matching cables:");
|
||||
for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) {
|
||||
// ensure we have the same number of connections as the cable
|
||||
if (usb_cables[cable].connectors_nb != connected_nb) {
|
||||
continue;
|
||||
}
|
||||
// ensure all the connectors we have are also in the cable
|
||||
bool match = true;
|
||||
for (uint8_t i = 0; i < LENGTH(connected) && match; i++) {
|
||||
if (!connected[i]) {
|
||||
continue;
|
||||
}
|
||||
bool found = false;
|
||||
for (uint8_t j = 0; j < usb_cables[cable].connectors_nb; j++) {
|
||||
if (&usb_connectors[i] == &usb_cables[cable].connectors[j]) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
match = false;
|
||||
}
|
||||
}
|
||||
// ensure we also have all the connectors which are in the cable
|
||||
for (uint8_t i = 0; i < usb_cables[cable].connectors_nb && match; i++) {
|
||||
bool found = false;
|
||||
for (uint8_t j = 0; j < LENGTH(connected); j++) {
|
||||
if (!connected[i]) {
|
||||
continue;
|
||||
}
|
||||
if (&usb_connectors[j] == &usb_cables[cable].connectors[i]) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
match = false;
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
// the connector match
|
||||
uint8_t pair_defined, pair_undefined, pair_disconnected, pair_error;
|
||||
match = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected, &pair_error);
|
||||
if (match) {
|
||||
matches++;
|
||||
printf("%s, ", usb_cables[cable].name);
|
||||
}
|
||||
printf("\n%u matching cables found\n");
|
||||
}
|
||||
|
||||
usb_pins_float(); // put all pins back in safe floating state
|
||||
}
|
||||
|
||||
/** list of all supported commands */
|
||||
|
@ -205,12 +307,36 @@ static const struct menu_command_t menu_commands[] = {
|
|||
.command_handler = &command_bootloader,
|
||||
},
|
||||
{
|
||||
.shortcut = 't',
|
||||
.name = "test",
|
||||
.command_description = "test USB cable",
|
||||
.shortcut = 'a',
|
||||
.name = "intra",
|
||||
.command_description = "test connector intra-connection",
|
||||
.argument = MENU_ARGUMENT_NONE,
|
||||
.argument_description = NULL,
|
||||
.command_handler = &command_test,
|
||||
.command_handler = &command_intra,
|
||||
},
|
||||
{
|
||||
.shortcut = 'e',
|
||||
.name = "inter",
|
||||
.command_description = "test connector inter-connection",
|
||||
.argument = MENU_ARGUMENT_NONE,
|
||||
.argument_description = NULL,
|
||||
.command_handler = &command_inter,
|
||||
},
|
||||
{
|
||||
.shortcut = 'c',
|
||||
.name = "cables",
|
||||
.command_description = "test cables",
|
||||
.argument = MENU_ARGUMENT_NONE,
|
||||
.argument_description = NULL,
|
||||
.command_handler = &command_cables,
|
||||
},
|
||||
{
|
||||
.shortcut = 'f',
|
||||
.name = "find",
|
||||
.command_description = "find cable",
|
||||
.argument = MENU_ARGUMENT_NONE,
|
||||
.argument_description = NULL,
|
||||
.command_handler = &command_find,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue