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 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * util.c
  3. */
  4. #include <string.h>
  5. #include "pico/stdlib.h"
  6. #include "pico/bootrom.h"
  7. #include "config.h"
  8. #include "util.h"
  9. #define HEARTBEAT_INTERVAL_MS 500
  10. #ifdef PICO_DEFAULT_LED_PIN
  11. static uint32_t last_heartbeat = 0;
  12. #endif // PICO_DEFAULT_LED_PIN
  13. void heartbeat_init(void) {
  14. #ifdef PICO_DEFAULT_LED_PIN
  15. gpio_init(PICO_DEFAULT_LED_PIN);
  16. gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
  17. gpio_put(PICO_DEFAULT_LED_PIN, 1);
  18. #endif // PICO_DEFAULT_LED_PIN
  19. }
  20. void heartbeat_run(void) {
  21. #ifdef PICO_DEFAULT_LED_PIN
  22. uint32_t now = to_ms_since_boot(get_absolute_time());
  23. if (now >= (last_heartbeat + HEARTBEAT_INTERVAL_MS)) {
  24. last_heartbeat = now;
  25. gpio_xor_mask(1 << PICO_DEFAULT_LED_PIN);
  26. }
  27. #endif // PICO_DEFAULT_LED_PIN
  28. }
  29. bool str_startswith(const char *str, const char *start) {
  30. size_t l = strlen(start);
  31. if (l > strlen(str)) {
  32. return false;
  33. }
  34. return (strncmp(str, start, l) == 0);
  35. }
  36. void reset_to_bootloader(void) {
  37. #ifdef PICO_DEFAULT_LED_PIN
  38. reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
  39. #else // ! PICO_DEFAULT_LED_PIN
  40. reset_usb_boot(0, 0);
  41. #endif // PICO_DEFAULT_LED_PIN
  42. }