Geen omschrijving
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.

main.c 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * main.c
  3. *
  4. * Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stdio.h>
  19. #include "pico/stdlib.h"
  20. #include "pico/bootrom.h"
  21. #include "hardware/watchdog.h"
  22. #include "adc.h"
  23. #include "buttons.h"
  24. #include "encoder.h"
  25. #include "lcd.h"
  26. #include "led.h"
  27. #include "pulse.h"
  28. #include "sequence.h"
  29. #include "ui.h"
  30. #include "main.h"
  31. #define WATCHDOG_PERIOD_MS 100
  32. static void reset_to_bootloader(void) {
  33. #ifdef PICO_DEFAULT_LED_PIN
  34. reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
  35. #else // ! PICO_DEFAULT_LED_PIN
  36. reset_usb_boot(0, 0);
  37. #endif // PICO_DEFAULT_LED_PIN
  38. }
  39. int main(void) {
  40. //watchdog_enable(WATCHDOG_PERIOD_MS, 1);
  41. stdio_init_all();
  42. bat_init();
  43. buttons_init();
  44. encoder_init();
  45. lcd_init();
  46. led_init();
  47. sequence_init();
  48. ui_init();
  49. printf("init done\n");
  50. int32_t last_epos = 0;
  51. while (1) {
  52. watchdog_update();
  53. buttons_run();
  54. encoder_run();
  55. sequence_run();
  56. pulse_run();
  57. ui_run();
  58. int32_t epos = encoder_pos();
  59. if (epos != last_epos) {
  60. ui_encoder(epos - last_epos);
  61. last_epos = epos;
  62. }
  63. int c = getchar_timeout_us(0);
  64. if (c == 0x18) {
  65. reset_to_bootloader();
  66. } else if (c != PICO_ERROR_TIMEOUT) {
  67. printf("%c", c);
  68. }
  69. }
  70. return 0;
  71. }