Bladeren bron

tweak debug disk creation

Thomas Buck 1 jaar geleden
bovenliggende
commit
2354f36e7a
8 gewijzigde bestanden met toevoegingen van 148 en 144 verwijderingen
  1. 1
    1
      CMakeLists.txt
  2. 7
    8
      include/debug_disk.h
  3. 2
    0
      pack_data.sh
  4. 1
    1
      src/console.c
  5. 0
    61
      src/debug.c
  6. 132
    0
      src/debug_disk.c
  7. 1
    73
      src/fat_disk.c
  8. 4
    0
      src/main.c

+ 1
- 1
CMakeLists.txt Bestand weergeven

@@ -52,7 +52,7 @@ target_sources(gadget PUBLIC
52 52
     src/usb_descriptors.c
53 53
     src/usb_msc.c
54 54
     src/fat_disk.c
55
-    src/debug.c
55
+    src/debug_disk.c
56 56
     src/buttons.c
57 57
     src/lipo.c
58 58
     src/ble.c

include/debug.h → include/debug_disk.h Bestand weergeven

@@ -1,5 +1,5 @@
1 1
 /*
2
- * debug.h
2
+ * debug_disk.h
3 3
  *
4 4
  * Copyright (c) 2022 - 2023 Thomas Buck (thomas@xythobuz.de)
5 5
  *
@@ -16,13 +16,12 @@
16 16
  * See <http://www.gnu.org/licenses/>.
17 17
  */
18 18
 
19
-#ifndef __DEBUG_H__
20
-#define __DEBUG_H__
19
+#ifndef __DEBUG_DISK_H__
20
+#define __DEBUG_DISK_H__
21 21
 
22
-int debug_msc_mount(void);
23
-int debug_msc_unmount(void);
22
+void debug_disk_init(void);
24 23
 
25
-void debug_msc_stats(void);
26
-void debug_msc_pmw3360(void);
24
+int debug_disk_mount(void);
25
+int debug_disk_unmount(void);
27 26
 
28
-#endif // __DEBUG_H__
27
+#endif // __DEBUG_DISK_H__

+ 2
- 0
pack_data.sh Bestand weergeven

@@ -4,10 +4,12 @@ set -euo pipefail
4 4
 cd "$(dirname "$0")"
5 5
 echo "Packing data"
6 6
 
7
+rm -rf build/src
7 8
 mkdir -p build/src
8 9
 cp COPYING build/src
9 10
 cp README.md build/src
10 11
 cp CMakeLists.txt build/src
12
+cp .gitmodules build/src/gitmodules
11 13
 cp -r include build/src
12 14
 cp -r src build/src
13 15
 

+ 1
- 1
src/console.c Bestand weergeven

@@ -27,7 +27,7 @@
27 27
 #include "util.h"
28 28
 #include "usb_cdc.h"
29 29
 #include "usb_msc.h"
30
-#include "debug.h"
30
+#include "debug_disk.h"
31 31
 #include "console.h"
32 32
 #include "lipo.h"
33 33
 #include "ble.h"

+ 0
- 61
src/debug.c Bestand weergeven

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

+ 132
- 0
src/debug_disk.c Bestand weergeven

@@ -0,0 +1,132 @@
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
+
19
+#include <string.h>
20
+#include <stdio.h>
21
+
22
+#include "pico/stdlib.h"
23
+#include "ff.h"
24
+
25
+#include "config.h"
26
+#include "log.h"
27
+#include "debug_disk.h"
28
+
29
+#include "pack_data.h"
30
+
31
+static FATFS fs;
32
+static bool mounted = false;
33
+
34
+void debug_disk_init(void) {
35
+    if (debug_disk_mount() != 0) {
36
+        debug("error mounting disk");
37
+        return;
38
+    }
39
+
40
+    // maximum length: 11 bytes
41
+    f_setlabel("DEBUG DISK");
42
+
43
+    FIL file;
44
+    FRESULT res = f_open(&file, "README.md", FA_CREATE_ALWAYS | FA_WRITE);
45
+    if (res != FR_OK) {
46
+        debug("error: f_open returned %d", res);
47
+    } else {
48
+        char readme[1024];
49
+        size_t pos = 0;
50
+        pos += snprintf(readme + pos, 1024 - pos, "# Volcano Remote Control Gadget\r\n");
51
+        pos += snprintf(readme + pos, 1024 - pos, "\r\n");
52
+        pos += snprintf(readme + pos, 1024 - pos, "Project by Thomas Buck <thomas@xythobuz.de>\r\n");
53
+        pos += snprintf(readme + pos, 1024 - pos, "Licensed under GPLv3.\r\n");
54
+        pos += snprintf(readme + pos, 1024 - pos, "See included 'src.tar.xz' for sources.\r\n");
55
+        pos += snprintf(readme + pos, 1024 - pos, "Repo at https://git.xythobuz.de/thomas/sb-py\r\n");
56
+
57
+        size_t len = strlen(readme);
58
+        UINT bw;
59
+        res = f_write(&file, readme, len, &bw);
60
+        if ((res != FR_OK) || (bw != len)) {
61
+            debug("error: f_write returned %d", res);
62
+        }
63
+
64
+        res = f_close(&file);
65
+        if (res != FR_OK) {
66
+            debug("error: f_close returned %d", res);
67
+        }
68
+    }
69
+
70
+    res = f_open(&file, "src.tar.xz", FA_CREATE_ALWAYS | FA_WRITE);
71
+    if (res != FR_OK) {
72
+        debug("error: f_open returned %d", res);
73
+    } else {
74
+        UINT bw;
75
+        UINT len = 0;
76
+        while (1) {
77
+            res = f_write(&file, data_tar_xz + len, data_tar_xz_len - len, &bw);
78
+            len += bw;
79
+            if (res != FR_OK) {
80
+                debug("error: f_write returned %d", res);
81
+                break;
82
+            } else if (bw == 0) {
83
+                debug("error: f_write did not write");
84
+                break;
85
+            } else if (bw == data_tar_xz_len) {
86
+                break;
87
+            }
88
+        }
89
+
90
+        res = f_close(&file);
91
+        if (res != FR_OK) {
92
+            debug("error: f_close returned %d", res);
93
+        }
94
+    }
95
+
96
+    if (debug_disk_unmount() != 0) {
97
+        debug("error unmounting disk");
98
+    }
99
+}
100
+
101
+int debug_disk_mount(void) {
102
+    if (mounted) {
103
+        debug("already mounted");
104
+        return 0;
105
+    }
106
+
107
+    FRESULT res = f_mount(&fs, "", 0);
108
+    if (res != FR_OK) {
109
+        debug("error: f_mount returned %d", res);
110
+        mounted = false;
111
+        return -1;
112
+    }
113
+
114
+    mounted = true;
115
+    return 0;
116
+}
117
+
118
+int debug_disk_unmount(void) {
119
+    if (!mounted) {
120
+        debug("already unmounted");
121
+        return 0;
122
+    }
123
+
124
+    FRESULT res = f_mount(0, "", 0);
125
+    if (res != FR_OK) {
126
+        debug("error: f_mount returned %d", res);
127
+        return -1;
128
+    }
129
+
130
+    mounted = false;
131
+    return 0;
132
+}

+ 1
- 73
src/fat_disk.c Bestand weergeven

@@ -18,7 +18,6 @@
18 18
 
19 19
 #include <string.h>
20 20
 #include <stdlib.h>
21
-#include <stdio.h>
22 21
 
23 22
 #include "pico/stdlib.h"
24 23
 #include "ff.h"
@@ -26,11 +25,9 @@
26 25
 
27 26
 #include "config.h"
28 27
 #include "log.h"
29
-#include "debug.h"
28
+#include "debug_disk.h"
30 29
 #include "fat_disk.h"
31 30
 
32
-#include "pack_data.h"
33
-
34 31
 static uint8_t disk[DISK_BLOCK_COUNT * DISK_BLOCK_SIZE];
35 32
 
36 33
 void fat_disk_init(void) {
@@ -38,75 +35,6 @@ void fat_disk_init(void) {
38 35
     FRESULT res = f_mkfs("", 0, work, sizeof(work));
39 36
     if (res != FR_OK) {
40 37
         debug("error: f_mkfs returned %d", res);
41
-        return;
42
-    }
43
-
44
-    if (debug_msc_mount() != 0) {
45
-        debug("error mounting disk");
46
-        return;
47
-    }
48
-
49
-    // maximum length: 11 bytes
50
-    f_setlabel("DEBUG DISK");
51
-
52
-    FIL file;
53
-    res = f_open(&file, "README.md", FA_CREATE_ALWAYS | FA_WRITE);
54
-    if (res != FR_OK) {
55
-        debug("error: f_open returned %d", res);
56
-    } else {
57
-        char readme[1024];
58
-        size_t pos = 0;
59
-        pos += snprintf(readme + pos, 1024 - pos, "# Volcano Remote Control Gadget\r\n");
60
-        pos += snprintf(readme + pos, 1024 - pos, "\r\n");
61
-        pos += snprintf(readme + pos, 1024 - pos, "Project by Thomas Buck <thomas@xythobuz.de>\r\n");
62
-        pos += snprintf(readme + pos, 1024 - pos, "Licensed under GPLv3.\r\n");
63
-        pos += snprintf(readme + pos, 1024 - pos, "See included src.tar.xz for sources.\r\n");
64
-        pos += snprintf(readme + pos, 1024 - pos, "Repo at https://git.xythobuz.de/thomas/sb-py\r\n");
65
-
66
-        size_t len = strlen(readme);
67
-        UINT bw;
68
-        res = f_write(&file, readme, len, &bw);
69
-        if ((res != FR_OK) || (bw != len)) {
70
-            debug("error: f_write returned %d", res);
71
-        }
72
-
73
-        res = f_close(&file);
74
-        if (res != FR_OK) {
75
-            debug("error: f_close returned %d", res);
76
-        }
77
-    }
78
-
79
-    res = f_open(&file, "src.tar.xz", FA_CREATE_ALWAYS | FA_WRITE);
80
-    if (res != FR_OK) {
81
-        debug("error: f_open returned %d", res);
82
-    } else {
83
-        UINT bw;
84
-        UINT len = 0;
85
-        while (1) {
86
-            debug("write %d", len);
87
-            res = f_write(&file, data_tar_xz + len, data_tar_xz_len - len, &bw);
88
-            if (bw == 0) {
89
-                debug("abort");
90
-                break;
91
-            }
92
-            len += bw;
93
-            if (res != FR_OK) {
94
-                debug("error: f_write returned %d", res);
95
-                break;
96
-            }
97
-            if (bw == data_tar_xz_len) {
98
-                break;
99
-            }
100
-        }
101
-
102
-        res = f_close(&file);
103
-        if (res != FR_OK) {
104
-            debug("error: f_close returned %d", res);
105
-        }
106
-    }
107
-
108
-    if (debug_msc_unmount() != 0) {
109
-        debug("error unmounting disk");
110 38
     }
111 39
 }
112 40
 

+ 4
- 0
src/main.c Bestand weergeven

@@ -27,6 +27,7 @@
27 27
 #include "log.h"
28 28
 #include "usb.h"
29 29
 #include "fat_disk.h"
30
+#include "debug_disk.h"
30 31
 #include "buttons.h"
31 32
 #include "ble.h"
32 33
 #include "lcd.h"
@@ -70,6 +71,9 @@ int main(void) {
70 71
     debug("fat_disk_init");
71 72
     fat_disk_init();
72 73
 
74
+    debug("debug_disk_init");
75
+    debug_disk_init();
76
+
73 77
     // trigger after 1000ms
74 78
     watchdog_enable(1000, 1);
75 79
 

Laden…
Annuleren
Opslaan