diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b0fd122..e940c85 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) if(NOT ${filename} STREQUAL all) target_link_libraries(all_example PUBLIC ${filename}_example) endif() diff --git a/examples/main.cpp b/examples/main.cpp index 5918660..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" @@ -23,7 +24,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,20 +32,24 @@ 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(); + if(watchdog_enable_caused_reboot()) { + reset_usb_boot(0,0); } + watchdog_enable(200, 1); + + wait_stdio_usb_connected_timeout(2500, 500); + MyButton::init_all(); auto &controller = ViewController::get(); CLASSNAME v{nullptr};