S&B Volcano vaporizer remote control with Pi Pico W
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

main.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * main.c
  3. *
  4. * Copyright (c) 2022 - 2023 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 "pico/stdlib.h"
  19. #include "pico/cyw43_arch.h"
  20. #include "hardware/watchdog.h"
  21. #include "hardware/adc.h"
  22. #include "config.h"
  23. #include "util.h"
  24. #include "console.h"
  25. #include "log.h"
  26. #include "usb.h"
  27. #include "usb_msc.h"
  28. #include "fat_disk.h"
  29. #include "debug_disk.h"
  30. #include "buttons.h"
  31. #include "ble.h"
  32. #include "lcd.h"
  33. #include "text.h"
  34. #include "image.h"
  35. #include "mem.h"
  36. #include "state.h"
  37. #include "serial.h"
  38. #include "workflow.h"
  39. void main_loop_hw(void) {
  40. watchdog_update();
  41. usb_run();
  42. serial_run();
  43. heartbeat_run();
  44. if (lcd_get_backlight() != mem_data()->backlight) {
  45. lcd_set_backlight(mem_data()->backlight);
  46. }
  47. }
  48. int main(void) {
  49. watchdog_enable(WATCHDOG_PERIOD_MS, 1);
  50. // required for debug console
  51. cnsl_init();
  52. #ifndef NDEBUG
  53. serial_init();
  54. #endif
  55. usb_init();
  56. debug("mem_init");
  57. mem_init();
  58. debug("lcd_init");
  59. lcd_init();
  60. watchdog_update();
  61. debug("draw_splash");
  62. draw_splash();
  63. lcd_set_backlight(mem_data()->backlight);
  64. if (watchdog_caused_reboot()) {
  65. debug("reset by watchdog");
  66. }
  67. debug("buttons_init");
  68. buttons_init();
  69. // required for LiPo voltage reading
  70. debug("adc_init");
  71. adc_init();
  72. // required for BLE and LiPo voltage reading
  73. debug("cyw43_arch_init");
  74. if (cyw43_arch_init()) {
  75. debug("cyw43_arch_init failed");
  76. lcd_set_backlight(0x00FF);
  77. while (1) {}
  78. }
  79. watchdog_update();
  80. debug("heartbeat_init");
  81. heartbeat_init();
  82. debug("ble_init");
  83. ble_init();
  84. debug("fat_disk_init");
  85. fat_disk_init();
  86. debug("debug_disk_init");
  87. debug_disk_init();
  88. #ifdef AUTO_MOUNT_MASS_STORAGE
  89. msc_set_medium_available(true);
  90. #endif // AUTO_MOUNT_MASS_STORAGE
  91. watchdog_update();
  92. debug("init done");
  93. battery_run();
  94. // wait for BLE stack to be ready before using it
  95. debug("wait for bt stack");
  96. while (!ble_is_ready()) {
  97. sleep_ms(1);
  98. }
  99. debug("starting app");
  100. state_switch(STATE_SCAN);
  101. while (1) {
  102. main_loop_hw();
  103. buttons_run();
  104. cnsl_run();
  105. battery_run();
  106. state_run();
  107. wf_run();
  108. }
  109. return 0;
  110. }