From 5dc18f91a2a0ecbad97338ae2738b3e8e3681eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 4 Apr 2018 17:14:36 +0200 Subject: [PATCH] BV: support full only modes --- application.c | 94 +++++++++++++++++++++++++----------------- lib/busvoodoo_global.c | 58 ++++++++++++++------------ lib/busvoodoo_global.h | 9 +++- lib/busvoodoo_hiz.c | 65 +++++++++++++++-------------- lib/busvoodoo_hiz.h | 2 +- lib/busvoodoo_i2c.c | 63 +++++++++++++++------------- lib/busvoodoo_i2c.h | 2 +- lib/busvoodoo_spi.c | 33 +++++++++------ lib/busvoodoo_spi.h | 2 +- lib/busvoodoo_uart.c | 81 +++++++++++++++++++----------------- 10 files changed, 230 insertions(+), 179 deletions(-) diff --git a/application.c b/application.c index 2957df2..94e7f7b 100644 --- a/application.c +++ b/application.c @@ -43,7 +43,7 @@ #include "busvoodoo_spi.h" // BusVoodoo SPI mode /** all supported BusVoodoo modes */ -static struct busvoodoo_mode_t* busvoodoo_modes[] = { +static const struct busvoodoo_mode_t* busvoodoo_modes[] = { &busvoodoo_hiz_mode, &busvoodoo_uart_mode, &busvoodoo_i2c_mode, @@ -51,7 +51,7 @@ static struct busvoodoo_mode_t* busvoodoo_modes[] = { }; /** current BusVoodoo mode */ -static struct busvoodoo_mode_t* busvoodoo_mode = NULL; +static struct busvoodoo_mode_t const * busvoodoo_mode = NULL; /** is mode setup complete */ static bool busvoodoo_mode_complete = false; @@ -76,7 +76,7 @@ size_t putc(char c) /** switch BusVoddoo mode * @param[in] mode mode to switch to */ -static void switch_mode(struct busvoodoo_mode_t* mode) +static void switch_mode(const struct busvoodoo_mode_t* mode) { if (busvoodoo_mode) { (*busvoodoo_mode->exit)(); // exit current mode @@ -124,36 +124,36 @@ static void command_reset(void* argument); /** list of all supported commands */ static const struct menu_command_t menu_commands[] = { { - 'm', - "mode", - "select mode", - MENU_ARGUMENT_STRING, - "[mode]", - &command_mode, + .shortcut = 'm', + .name = "mode", + .command_description = "select mode", + .argument = MENU_ARGUMENT_STRING, + .argument_description = "[mode]", + .command_handler = &command_mode, }, { - 'q', - "quit", - "quit current mode", - MENU_ARGUMENT_NONE, - NULL, - &command_quit, + .shortcut = 'q', + .name = "quit", + .command_description = "quit current mode", + .argument = MENU_ARGUMENT_NONE, + .argument_description = NULL, + .command_handler = &command_quit, }, { - 'r', - "reset", - "reset board", - MENU_ARGUMENT_NONE, - NULL, - &command_reset, + .shortcut = 'R', + .name = "reset", + .command_description = "reset board", + .argument = MENU_ARGUMENT_NONE, + .argument_description = NULL, + .command_handler = &command_reset, }, { - 'h', - "help", - "display help", - MENU_ARGUMENT_NONE, - NULL, - &command_help, + .shortcut = 'h', + .name = "help", + .command_description = "display help", + .argument = MENU_ARGUMENT_NONE, + .argument_description = NULL, + .command_handler = &command_help, }, }; @@ -163,7 +163,12 @@ static void command_help(void* argument) printf("available commands:\n"); menu_print_commands(menu_commands, LENGTH(menu_commands)); // print global commands menu_print_commands(busvoodoo_global_commands, busvoodoo_global_commands_nb); // print BusVoodoo global commands - menu_print_commands(busvoodoo_mode->commands, busvoodoo_mode->commands_nb); // print BusVoodoo mode commands + if (busvoodoo_full) { + menu_print_commands(busvoodoo_global_full_commands, busvoodoo_global_full_commands_nb); // print BusVoodoo global commands + } + if (!busvoodoo_mode->full_only || busvoodoo_full) { + menu_print_commands(busvoodoo_mode->commands, busvoodoo_mode->commands_nb); // print BusVoodoo mode commands + } } static void command_mode(void* argument) @@ -171,13 +176,19 @@ static void command_mode(void* argument) if (NULL==argument || 0==strlen(argument)) { // no mode provided: list all modes printf("available modes:\n"); for (uint8_t i=0; iname, busvoodoo_modes[i]->description); // display mode information + if (!busvoodoo_modes[i]->full_only || busvoodoo_full) { + printf("%s\t%s\n", busvoodoo_modes[i]->name, busvoodoo_modes[i]->description); // display mode information + } } } else { // mode provided bool mode_found = false; // to know if we found the matching mode for (uint8_t i=0; iname)) { // check for corresponding mode - switch_mode(busvoodoo_modes[i]); // switch to mode + if (!busvoodoo_mode->full_only || busvoodoo_full) { + switch_mode(busvoodoo_modes[i]); // switch to mode + } else { + printf("mode only available for BusVoodoo full\n"); + } mode_found = true; // remember we found the mode break; // stop searching for mode } @@ -217,17 +228,26 @@ static void process_command(char* str) if (!busvoodoo_mode_complete) { // mode setup is not complete busvoodoo_mode_complete = (*busvoodoo_mode->setup)(&terminal_prefix, str); // continue setup terminal_send(0); // update the terminal prompt - } else { + } else { // mode setup is complete // don't handle empty lines if (!str || 0==strlen(str)) { return; } - if (!menu_handle_command(str, busvoodoo_mode->commands, busvoodoo_mode->commands_nb)) { - if (!menu_handle_command(str, busvoodoo_global_commands, busvoodoo_global_commands_nb)) { - if (!menu_handle_command(str, menu_commands, LENGTH(menu_commands))) { - printf("command not recognized. enter help to list commands\n"); - } - } + bool command_handled = false; + if (!busvoodoo_mode->full_only || busvoodoo_full) { + command_handled = menu_handle_command(str, busvoodoo_mode->commands, busvoodoo_mode->commands_nb); // try if the mode can handle this command + } + if (!command_handled && busvoodoo_full) { + command_handled = menu_handle_command(str, busvoodoo_global_full_commands, busvoodoo_global_full_commands_nb); // try if full BusVoodoo can handle this command + } + if (!command_handled) { + command_handled = menu_handle_command(str, busvoodoo_global_commands, busvoodoo_global_commands_nb); // try if the base BusVoodoo can handle this command + } + if (!command_handled) { + command_handled = menu_handle_command(str, menu_commands, LENGTH(menu_commands)); // try if this is not a global command + } + if (!command_handled) { + printf("command not recognized. enter help to list commands\n"); } } } diff --git a/lib/busvoodoo_global.c b/lib/busvoodoo_global.c index e4c8e58..ced6f2a 100644 --- a/lib/busvoodoo_global.c +++ b/lib/busvoodoo_global.c @@ -723,44 +723,48 @@ static void busvoodoo_global_pinout(void* argument) } } -/** list of supported commands */ const struct menu_command_t busvoodoo_global_commands[] = { { - 'P', - "power", - "switch 3V3 and 5V power rails on/off, or read internal voltages", - MENU_ARGUMENT_STRING, - "[on|off]", - &busvoodoo_global_power, + .shortcut = 'p', + .name = "pinout", + .command_description = "show connector pinout", + .argument = MENU_ARGUMENT_NONE, + .argument_description = NULL, + .command_handler = &busvoodoo_global_pinout, }, { - 'L', - "LV", - "set voltage on low voltage power rail (0, 0.3-4.8, 5V), or read voltage on pin", - MENU_ARGUMENT_FLOAT, - "[voltage]", - &busvoodoo_global_lv, + .shortcut = 'P', + .name = "power", + .command_description = "switch 3V3 and 5V power rails on/off, or read internal voltages", + .argument = MENU_ARGUMENT_STRING, + .argument_description = "[on|off]", + .command_handler = &busvoodoo_global_power, }, { - 'H', - "HV", - "set voltage on high voltage power rail (0, 3.3-24V), or read voltage on pin", - MENU_ARGUMENT_FLOAT, - "[voltage]", - &busvoodoo_global_hv, - }, - { - 'p', - "pinout", - "show connector pinout", - MENU_ARGUMENT_NONE, - NULL, - &busvoodoo_global_pinout, + .shortcut = 'L', + .name = "LV", + .command_description = "set voltage on low voltage power rail (0, 0.3-4.8, 5V), or read voltage on pin", + .argument = MENU_ARGUMENT_FLOAT, + .argument_description = "[voltage]", + .command_handler = &busvoodoo_global_lv, }, }; const uint8_t busvoodoo_global_commands_nb = LENGTH(busvoodoo_global_commands); +const struct menu_command_t busvoodoo_global_full_commands[] = { + { + .shortcut = 'H', + .name = "HV", + .command_description = "set voltage on high voltage power rail (0, 3.3-24V), or read voltage on pin", + .argument = MENU_ARGUMENT_FLOAT, + .argument_description = "[voltage]", + .command_handler = &busvoodoo_global_hv, + }, +}; + +const uint8_t busvoodoo_global_full_commands_nb = LENGTH(busvoodoo_global_full_commands); + /** interrupt service routine called on LED timeout */ void TIM_ISR(BUSVOODOO_LED_TIMER)(void) { diff --git a/lib/busvoodoo_global.h b/lib/busvoodoo_global.h index 30aafc3..bf83a4b 100644 --- a/lib/busvoodoo_global.h +++ b/lib/busvoodoo_global.h @@ -111,6 +111,7 @@ struct busvoodoo_mode_t { const char* name; /**< name of the mode (i.e. protocol shortcut for the menu) */ const char* description; /**< human readable description of the mode (i.e. full protocol name) */ + const bool full_only; /**< if this mode is available only for BusVoodoo full flavor */ bool (*setup)(char** prefix, const char* line); /**< function to setup mode (menu prefix can be used to ask parameter, and line will be the user provided response)*/ const struct menu_command_t* commands; /**< list of menu commands provided by mode */ const uint8_t commands_nb; /**< number of menu commands provided by mode */ @@ -130,10 +131,14 @@ extern const uint8_t busvoodoo_io_groups[13]; /**< which I/O pin (group) does th extern bool busvoodoo_full; /** version of the hardware board */ extern char busvoodoo_version; -/** list of supported commands */ +/** list of supported commands for base BusVoodoo */ extern const struct menu_command_t busvoodoo_global_commands[]; -/** number supported commands */ +/** number supported commands for base BusVoodoo */ extern const uint8_t busvoodoo_global_commands_nb; +/** list of supported commands for BusVoodoo full only */ +extern const struct menu_command_t busvoodoo_global_full_commands[]; +/** number supported commands for BusVoodoo full only */ +extern const uint8_t busvoodoo_global_full_commands_nb; /** I/O connector pinout */ extern const char* busvoodoo_global_pinout_io[10]; diff --git a/lib/busvoodoo_hiz.c b/lib/busvoodoo_hiz.c index 28ee46c..5ab195e 100644 --- a/lib/busvoodoo_hiz.c +++ b/lib/busvoodoo_hiz.c @@ -63,7 +63,7 @@ static bool busvoodoo_hiz_setup(char** prefix, const char* line) for (uint8_t i=0; i