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
 #define MENU_PREFER_VOLCANO
22
 #define MENU_PREFER_VOLCANO
23
 //#define MENU_PREFER_CRAFTY
23
 //#define MENU_PREFER_CRAFTY
24
 
24
 
25
+#define AUTO_MOUNT_MASS_STORAGE
26
+
25
 #define WATCHDOG_PERIOD_MS 1000
27
 #define WATCHDOG_PERIOD_MS 1000
26
 
28
 
27
 // ASCII 0x18 = CAN (cancel)
29
 // ASCII 0x18 = CAN (cancel)

+ 8
- 0
include/usb_msc.h View File

19
 #ifndef __USB_MSC_H__
19
 #ifndef __USB_MSC_H__
20
 #define __USB_MSC_H__
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
 bool msc_is_medium_available(void);
28
 bool msc_is_medium_available(void);
29
+
30
+// should only be set to false when unlocked
23
 void msc_set_medium_available(bool state);
31
 void msc_set_medium_available(bool state);
24
 
32
 
25
 #endif // __USB_MSC_H__
33
 #endif // __USB_MSC_H__

+ 3
- 0
src/console.c View File

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

+ 1
- 1
src/debug_disk.c View File

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

+ 5
- 0
src/main.c View File

26
 #include "console.h"
26
 #include "console.h"
27
 #include "log.h"
27
 #include "log.h"
28
 #include "usb.h"
28
 #include "usb.h"
29
+#include "usb_msc.h"
29
 #include "fat_disk.h"
30
 #include "fat_disk.h"
30
 #include "debug_disk.h"
31
 #include "debug_disk.h"
31
 #include "buttons.h"
32
 #include "buttons.h"
88
     debug("debug_disk_init");
89
     debug("debug_disk_init");
89
     debug_disk_init();
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
     watchdog_enable(WATCHDOG_PERIOD_MS, 1);
96
     watchdog_enable(WATCHDOG_PERIOD_MS, 1);
92
 
97
 
93
     debug("init done");
98
     debug("init done");

+ 10
- 7
src/usb_msc.c View File

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

Loading…
Cancel
Save