No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.c 929B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * util.c
  3. */
  4. #include "pico/stdlib.h"
  5. #include "pico/bootrom.h"
  6. #include "util.h"
  7. #define HEARTBEAT_INTERVAL_MS 500
  8. #ifdef PICO_DEFAULT_LED_PIN
  9. static uint32_t last_heartbeat = 0;
  10. #endif // PICO_DEFAULT_LED_PIN
  11. void heartbeat_init(void) {
  12. #ifdef PICO_DEFAULT_LED_PIN
  13. gpio_init(PICO_DEFAULT_LED_PIN);
  14. gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
  15. gpio_put(PICO_DEFAULT_LED_PIN, 1);
  16. #endif // PICO_DEFAULT_LED_PIN
  17. }
  18. void heartbeat_run(void) {
  19. #ifdef PICO_DEFAULT_LED_PIN
  20. uint32_t now = to_ms_since_boot(get_absolute_time());
  21. if (now >= (last_heartbeat + HEARTBEAT_INTERVAL_MS)) {
  22. last_heartbeat = now;
  23. gpio_xor_mask(1 << PICO_DEFAULT_LED_PIN);
  24. }
  25. #endif // PICO_DEFAULT_LED_PIN
  26. }
  27. void reset_to_bootloader(void) {
  28. #ifdef PICO_DEFAULT_LED_PIN
  29. reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
  30. #else // ! PICO_DEFAULT_LED_PIN
  31. reset_usb_boot(0, 0);
  32. #endif // PICO_DEFAULT_LED_PIN
  33. }