From d907f60522ea7ed3ec3449f75799972231fc3483 Mon Sep 17 00:00:00 2001 From: Skyler Mansfield Date: Mon, 21 Aug 2023 08:02:51 +0100 Subject: [PATCH 1/2] Add checks to allow running standalone --- examples/main.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/main.cpp b/examples/main.cpp index 5918660..c8cd113 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -23,7 +23,7 @@ MyButton buttons[4] = { extern "C" bool tud_connected(); -void wait_stdio_usb_connected_timeout(long timeout_ms){ +void wait_stdio_usb_connected_timeout(long timeout_ms, long startup_delay_ms){ if(!tud_connected()) return; absolute_time_t timeout = make_timeout_time_ms(timeout_ms); @@ -31,19 +31,17 @@ void wait_stdio_usb_connected_timeout(long timeout_ms){ while(!stdio_usb_connected() && absolute_time_diff_us(get_absolute_time(), timeout) > 0){ watchdog_update(); } - if(stdio_usb_connected) - sleep_ms(1000); + timeout = make_timeout_time_ms(startup_delay_ms); + while(stdio_usb_connected() && absolute_time_diff_us(get_absolute_time(), timeout) > 0){ + watchdog_update(); + } } int main(){ stdio_init_all(); - wait_stdio_usb_connected_timeout(2500); - - while(!(tud_connected() && stdio_usb_connected())){ - watchdog_update(); - } + wait_stdio_usb_connected_timeout(2500, 500); MyButton::init_all(); auto &controller = ViewController::get(); From cb6ada050dcb3165310ddfa6885e67a83b4ab9ba Mon Sep 17 00:00:00 2001 From: Skyler Mansfield Date: Mon, 21 Aug 2023 08:26:52 +0100 Subject: [PATCH 2/2] Add watchdog reboot --- examples/CMakeLists.txt | 2 +- examples/main.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 048c7f3..f25ce17 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,7 +5,7 @@ function(add_simple_example NAME) target_link_libraries(${filename}_example PRIVATE gui) add_executable(${filename}_example_app main.cpp) target_compile_definitions(${filename}_example_app PRIVATE CLASSNAME=${NAME}View INCLUDE="examples/${filename}_view.hpp") - target_link_libraries(${filename}_example_app PRIVATE gui ${filename}_example) + target_link_libraries(${filename}_example_app PRIVATE gui ${filename}_example pico_bootrom) pico_add_extra_outputs(${filename}_example_app) pico_enable_stdio_uart(${filename}_example_app 0) diff --git a/examples/main.cpp b/examples/main.cpp index c8cd113..cb8e43e 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -4,6 +4,7 @@ #include "pico/stdio.h" #include "hardware/watchdog.h" #include "pico/time.h" +#include "pico/bootrom.h" #include "drivers/button.hpp" #include "buttons.hpp" @@ -41,6 +42,12 @@ int main(){ stdio_init_all(); + if(watchdog_enable_caused_reboot()) { + reset_usb_boot(0,0); + } + + watchdog_enable(200, 1); + wait_stdio_usb_connected_timeout(2500, 500); MyButton::init_all();