application: make button also trigger reset

This commit is contained in:
King Kévin 2021-03-22 18:48:24 +01:00
parent a0fdce3318
commit 54bf18caa1
1 changed files with 9 additions and 2 deletions

View File

@ -260,6 +260,8 @@ static void command_target_reset(void* argument)
} 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), GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO_PIN(TARGET_RST)); // set output as push-pull
} else {
printf("unknown argument: %s\n", argument);
}
}
@ -857,6 +859,7 @@ void main(void)
#endif
board_setup(); // setup board
exti_set_trigger(GPIO_EXTI(BUTTON_PIN), EXTI_TRIGGER_BOTH); // trigger when button is pressed or released
usb_cdcacm_setup(); // setup USB CDC ACM (for printing)
puts("\nwelcome to the CuVoodoo SWJ finder\n"); // print welcome message
@ -1009,9 +1012,13 @@ void main(void)
}
if (button_flag) { // user pressed button
action = true; // action has been performed
puts("button pressed\n");
sleep_ms(50); // wait a bit to remove noise and double trigger
if (gpio_get(GPIO_PORT(BUTTON_PIN), GPIO_PIN(BUTTON_PIN))) { // button released
command_target_reset("0"); // release reset
} else {
command_target_reset("1"); // assert reset
}
led_toggle(); // toggle LED
sleep_ms(100); // wait a bit to remove noise and double trigger
button_flag = false; // reset flag
}
if (wakeup_flag) { // time to do periodic checks