From 5a5543ae530c4995a60e672e0b3d6bf22d87f1b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 19 Nov 2019 18:47:00 +0100 Subject: [PATCH] add test action to test USB cables --- application.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/application.c b/application.c index a1e8c2c..4a36cf6 100644 --- a/application.c +++ b/application.c @@ -122,6 +122,36 @@ static void command_reset(void* argument); */ static void command_bootloader(void* argument); +/** test USB cable + * @param[in] argument no argument required + */ +static void command_test(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]); + } + usb_pins_float(); // put all pins back 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)); + + // 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 + 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); + } +} + /** list of all supported commands */ static const struct menu_command_t menu_commands[] = { { @@ -174,6 +204,14 @@ static const struct menu_command_t menu_commands[] = { .argument_description = NULL, .command_handler = &command_bootloader, }, + { + .shortcut = 't', + .name = "test", + .command_description = "test USB cable", + .argument = MENU_ARGUMENT_NONE, + .argument_description = NULL, + .command_handler = &command_test, + }, }; static void command_help(void* argument)