S&B Volcano vaporizer remote control with Pi Pico W
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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "fat_disk.h"
  28. #include "buttons.h"
  29. #include "ble.h"
  30. #include "lcd.h"
  31. #pragma GCC diagnostic push
  32. #pragma GCC diagnostic ignored "-Wtrigraphs"
  33. #include "logo.h"
  34. #pragma GCC diagnostic pop
  35. static void draw_splash(void) {
  36. char *data = logo_rgb_data;
  37. for (uint x = 0; x < logo_width; x++) {
  38. for (uint y = 0; y < logo_height; y++) {
  39. uint32_t pixel[3];
  40. HEADER_PIXEL(data, pixel);
  41. uint32_t color = (pixel[0] >> 3) << 11;
  42. color |= (pixel[1] >> 2) << 5;
  43. color |= pixel[2] >> 3;
  44. lcd_write_point(240 - x, y, color);
  45. }
  46. }
  47. }
  48. int main(void) {
  49. heartbeat_init();
  50. buttons_init();
  51. cnsl_init();
  52. usb_init();
  53. debug("lcd_init");
  54. lcd_init();
  55. draw_splash();
  56. lcd_set_backlight(0x8000);
  57. if (watchdog_caused_reboot()) {
  58. debug("reset by watchdog");
  59. }
  60. // required for LiPo voltage reading
  61. adc_init();
  62. // required for BLE and LiPo voltage reading
  63. debug("cyw43_arch_init");
  64. if (cyw43_arch_init()) {
  65. debug("cyw43_arch_init failed");
  66. }
  67. debug("ble_init");
  68. ble_init();
  69. debug("fat_disk_init");
  70. fat_disk_init();
  71. // trigger after 1000ms
  72. watchdog_enable(1000, 1);
  73. debug("init done");
  74. while (1) {
  75. watchdog_update();
  76. heartbeat_run();
  77. buttons_run();
  78. usb_run();
  79. cnsl_run();
  80. }
  81. return 0;
  82. }