From 062a850357df5e6bbcd0b0a51dcd474e560bab45 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Fri, 29 Apr 2016 13:12:46 -0700 Subject: [PATCH] [stm32f7] Add 'stgpio' command to reference ST gpios by name --- platform/stm32f7xx/gpio.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/platform/stm32f7xx/gpio.c b/platform/stm32f7xx/gpio.c index ac2a8a3e..7bdbc943 100644 --- a/platform/stm32f7xx/gpio.c +++ b/platform/stm32f7xx/gpio.c @@ -158,3 +158,42 @@ int gpio_get(unsigned nr) return HAL_GPIO_ReadPin(port_to_pointer(GPIO_PORT(nr)), 1 << GPIO_PIN(nr)); } +#ifdef WITH_LIB_CONSOLE +#include +#include +#include +#include +#include + +static int cmd_stgpio(int argc, const cmd_args *argv) +{ + if (argc >= 3) { + char port = toupper(argv[2].str[0]); + int pin = atoi(&argv[2].str[1]); + uint32_t nr = ((port - 'A') << 8) | (pin & 0xff); + + if (argc == 4 && !strcmp(argv[1].str,"set")) { + unsigned int value = argv[3].u; + + gpio_set(nr, value); + return 0; + } else if (argc == 3 && !strcmp(argv[1].str,"get")) { + printf("gpio %c%d: %d\n", port, pin, gpio_get(nr)); + return 0; + } else { + goto print_usage; + } + } + +print_usage: + printf("stgpio set \n"); + printf("stgpio get \n"); + putchar('\n'); + + return 0; +} +STATIC_COMMAND_START +STATIC_COMMAND("stgpio", "wrapper for gpio commands with ST gpio naming conventions of [A-K][1-15]", &cmd_stgpio) +STATIC_COMMAND_END(stgpio); + +#endif