application: add command to control target reset

This commit is contained in:
King Kévin 2021-03-24 00:47:59 +01:00
parent caed09f4db
commit ce9d927a5b
1 changed files with 66 additions and 2 deletions

View File

@ -245,6 +245,62 @@ static void command_target_voltage(void* argument)
putc('\n');
}
/** configure or reset target
* @param[in] argument 1 to assert reset, 0 to release reset, ODL to set reset pin to open-drain active low, ODH to set reset pin to open-drain active high, PPL to set reset pin to push-pull active low, PPH to set reset pin to push-pull active high
*/
static void command_target_reset(void* argument)
{
(void)argument; // we won't use the argument
static bool active_low = true; // if the reset is active low or high
// set reset mode
if (argument) { // if argument is provided
if (0 == strcmp("0", argument)) { // release reset
if (active_low) {
gpio_set(GPIO_PORT(TARGET_RST_PIN), GPIO_PIN(TARGET_RST_PIN));
} else {
gpio_clear(GPIO_PORT(TARGET_RST_PIN), GPIO_PIN(TARGET_RST_PIN));
}
} else if (0 == strcmp("1", argument)) { // assert reset
if (active_low) {
gpio_clear(GPIO_PORT(TARGET_RST_PIN), GPIO_PIN(TARGET_RST_PIN));
} else {
gpio_set(GPIO_PORT(TARGET_RST_PIN), GPIO_PIN(TARGET_RST_PIN));
}
} else if (0 == strcmp("ODL", argument)) { // set reset to open-drain active low
active_low = true; // remember we are active low
gpio_set_output_options(GPIO_PORT(TARGET_RST_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, GPIO_PIN(TARGET_RST_PIN)); // set output as open-drain
} else if (0 == strcmp("ODH", argument)) { // set reset to open-drain active hig
active_low = false; // remember we are active high
gpio_set_output_options(GPIO_PORT(TARGET_RST_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, GPIO_PIN(TARGET_RST_PIN)); // set output as open-drain
} else if (0 == strcmp("PPL", argument)) { // set reset to push-pull active low
active_low = true; // remember we are active low
gpio_set_output_options(GPIO_PORT(TARGET_RST_PIN), GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO_PIN(TARGET_RST_PIN)); // set output as push-pull
} else if (0 == strcmp("PPH", argument)) { // set reset to push-pull active high
active_low = false; // remember we are active high
gpio_set_output_options(GPIO_PORT(TARGET_RST_PIN), GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO_PIN(TARGET_RST_PIN)); // set output as push-pull
} else {
printf("unknown argument: %s\n", argument);
}
}
const bool open_drain = (GPIO_OTYPER(GPIO_PORT(TARGET_RST_PIN)) & GPIO_PIN(TARGET_RST_PIN)); // if the output is configured as open drain (else it's push-pull)
printf("reset pin set to %s active %s\n", open_drain ? "open-drain" : "push-pull", active_low ? "low" : "high");
if (gpio_get(GPIO_PORT(TARGET_RST_PIN), GPIO_PIN(TARGET_RST_PIN))) {
if (active_low) {
puts("reset released\n");
} else {
puts("reset asserted\n");
}
} else {
if (active_low) {
puts("reset asserted\n");
} else {
puts("reset released\n");
}
}
}
/** display available commands
* @param[in] argument no argument required
*/
@ -473,8 +529,8 @@ static const struct menu_command_t menu_commands[] = {
.command_handler = &command_datetime,
},
{
.shortcut = 'r',
.name = "reset",
.shortcut = 'R',
.name = "reset_board",
.command_description = "reset board",
.argument = MENU_ARGUMENT_NONE,
.argument_description = NULL,
@ -504,6 +560,14 @@ static const struct menu_command_t menu_commands[] = {
.argument_description = "[0|3|5]",
.command_handler = &command_target_voltage,
},
{
.shortcut = 'r',
.name = "reset",
.command_description = "configure/reset target board",
.argument = MENU_ARGUMENT_STRING,
.argument_description = "[0|1|ODL|ODH|PPL|PPH]",
.command_handler = &command_target_reset,
},
};
static void command_help(void* argument)