Browse Source

make mass storage available by default

Thomas Buck 1 year ago
parent
commit
0390f057a2
6 changed files with 29 additions and 8 deletions
  1. 2
    0
      include/config.h
  2. 8
    0
      include/usb_msc.h
  3. 3
    0
      src/console.c
  4. 1
    1
      src/debug_disk.c
  5. 5
    0
      src/main.c
  6. 10
    7
      src/usb_msc.c

+ 2
- 0
include/config.h View File

@@ -22,6 +22,8 @@
22 22
 #define MENU_PREFER_VOLCANO
23 23
 //#define MENU_PREFER_CRAFTY
24 24
 
25
+#define AUTO_MOUNT_MASS_STORAGE
26
+
25 27
 #define WATCHDOG_PERIOD_MS 1000
26 28
 
27 29
 // ASCII 0x18 = CAN (cancel)

+ 8
- 0
include/usb_msc.h View File

@@ -19,7 +19,15 @@
19 19
 #ifndef __USB_MSC_H__
20 20
 #define __USB_MSC_H__
21 21
 
22
+/*
23
+ * Available: a disk is present in the drive
24
+ * Locked: the host wants to prevent disk removal
25
+ */
26
+
27
+bool msc_is_medium_locked(void);
22 28
 bool msc_is_medium_available(void);
29
+
30
+// should only be set to false when unlocked
23 31
 void msc_set_medium_available(bool state);
24 32
 
25 33
 #endif // __USB_MSC_H__

+ 3
- 0
src/console.c View File

@@ -136,6 +136,9 @@ static void cnsl_interpret(const char *line) {
136 136
         println("Currently %s. %s now.",
137 137
                 state ? "mounted" : "unmounted",
138 138
                 state ? "Unplugging" : "Plugging in");
139
+        if (state && msc_is_medium_locked()) {
140
+            println("Warning: host has locked medium. Unmounting anyway.");
141
+        }
139 142
         msc_set_medium_available(!state);
140 143
     } else if (strcmp(line, "power") == 0) {
141 144
         float volt = lipo_voltage();

+ 1
- 1
src/debug_disk.c View File

@@ -100,7 +100,7 @@ void debug_disk_init(void) {
100 100
     }
101 101
 
102 102
     // maximum length: 11 bytes
103
-    f_setlabel("DEBUG DISK");
103
+    f_setlabel("Volcano RC");
104 104
 
105 105
     write_readme();
106 106
 

+ 5
- 0
src/main.c View File

@@ -26,6 +26,7 @@
26 26
 #include "console.h"
27 27
 #include "log.h"
28 28
 #include "usb.h"
29
+#include "usb_msc.h"
29 30
 #include "fat_disk.h"
30 31
 #include "debug_disk.h"
31 32
 #include "buttons.h"
@@ -88,6 +89,10 @@ int main(void) {
88 89
     debug("debug_disk_init");
89 90
     debug_disk_init();
90 91
 
92
+#ifdef AUTO_MOUNT_MASS_STORAGE
93
+    msc_set_medium_available(true);
94
+#endif // AUTO_MOUNT_MASS_STORAGE
95
+
91 96
     watchdog_enable(WATCHDOG_PERIOD_MS, 1);
92 97
 
93 98
     debug("init done");

+ 10
- 7
src/usb_msc.c View File

@@ -33,18 +33,19 @@
33 33
 #include "fat_disk.h"
34 34
 #include "log.h"
35 35
 
36
-static bool ejected = false;
37 36
 static bool medium_available = false;
37
+static bool medium_locked = false;
38 38
 
39 39
 bool msc_is_medium_available(void) {
40 40
     return medium_available;
41 41
 }
42 42
 
43
+bool msc_is_medium_locked(void) {
44
+    return medium_locked;
45
+}
46
+
43 47
 void msc_set_medium_available(bool state) {
44 48
     medium_available = state;
45
-    if (state) {
46
-        ejected = false;
47
-    }
48 49
 }
49 50
 
50 51
 // Invoked when received SCSI_CMD_INQUIRY
@@ -104,6 +105,7 @@ bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition,
104 105
         // unload disk storage
105 106
         debug("unload disk storage %d", load_eject);
106 107
         if (load_eject) {
108
+            debug("Host ejected medium. Unplugging disk.");
107 109
             medium_available = false;
108 110
         }
109 111
     }
@@ -176,14 +178,15 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16],
176 178
                 resplen = -1;
177 179
             } else {
178 180
                 debug("Host wants to lock medium.");
181
+                medium_locked = true;
179 182
             }
180 183
         } else {
181 184
             // Allow medium removal
182 185
             if (medium_available) {
183
-                debug("Host ejected medium. Unplugging disk.");
184
-                medium_available = false;
186
+                debug("Host unlocked medium.");
187
+                medium_locked = false;
185 188
             } else {
186
-                debug("host ejected non-existing medium. Not supported.");
189
+                debug("host unlocked non-existing medium. Not supported.");
187 190
                 resplen = -1;
188 191
             }
189 192
         }

Loading…
Cancel
Save