S&B Volcano vaporizer remote control with Pi Pico W
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

debug_disk.c 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * debug_disk.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 <string.h>
  19. #include <stdio.h>
  20. #include "pico/stdlib.h"
  21. #include "ff.h"
  22. #include "config.h"
  23. #include "log.h"
  24. #include "debug_disk.h"
  25. static FATFS fs;
  26. static bool mounted = false;
  27. void debug_disk_init_log(void) {
  28. if (debug_disk_mount() != 0) {
  29. debug("error mounting disk");
  30. return;
  31. }
  32. log_dump_to_disk();
  33. if (debug_disk_unmount() != 0) {
  34. debug("error unmounting disk");
  35. }
  36. }
  37. int debug_disk_mount(void) {
  38. if (mounted) {
  39. debug("already mounted");
  40. return 0;
  41. }
  42. FRESULT res = f_mount(&fs, "", 0);
  43. if (res != FR_OK) {
  44. debug("error: f_mount returned %d", res);
  45. mounted = false;
  46. return -1;
  47. }
  48. mounted = true;
  49. return 0;
  50. }
  51. int debug_disk_unmount(void) {
  52. if (!mounted) {
  53. debug("already unmounted");
  54. return 0;
  55. }
  56. FRESULT res = f_mount(0, "", 0);
  57. if (res != FR_OK) {
  58. debug("error: f_mount returned %d", res);
  59. return -1;
  60. }
  61. mounted = false;
  62. return 0;
  63. }