Moved format into msc

This commit is contained in:
Spacehuhn 2022-07-16 11:53:03 +02:00
parent 47342ea053
commit 4bb7270d81
9 changed files with 24 additions and 18 deletions

View File

@ -9,7 +9,6 @@
#include "src/attack/attack.h" #include "src/attack/attack.h"
#include "src/preferences/preferences.h" #include "src/preferences/preferences.h"
#include "src/duckparser/duckparser.h" #include "src/duckparser/duckparser.h"
#include "src/format/format.h"
#include "src/tasks/tasks.h" #include "src/tasks/tasks.h"
void setup() { void setup() {
@ -18,16 +17,12 @@ void setup() {
selector::init(); selector::init();
// Initialize memory and ceck for problems // Initialize memory and ceck for problems
if (!msc::init()) { if (!msc::init()) {
format::start(); // Format the drive // Blink red and do nothing
while (true) {
// If it still fails, blink red LED led::setColor(255, 0, 0);
if (!msc::init()) { delay(500);
while (true) { led::setColor(0, 0, 0);
led::setColor(255, 0, 0); delay(500);
delay(500);
led::setColor(0, 0, 0);
delay(500);
}
} }
} }
preferences::load(); preferences::load();
@ -52,7 +47,7 @@ void setup() {
// Format Flash // Format Flash
if ((selector::mode() == SETUP) && preferences::getFormat()) { if ((selector::mode() == SETUP) && preferences::getFormat()) {
led::setColor(255, 255, 255); led::setColor(255, 255, 255);
format::start(preferences::getDriveName().c_str()); msc::format(preferences::getDriveName().c_str());
} }
// Create preferences file if it doesn't exist yet // Create preferences file if it doesn't exist yet

View File

@ -2,7 +2,6 @@
#pragma once #pragma once
namespace format { namespace format {
bool start(const char* drive_name = "USB Nova"); bool start(const char* drive_name = "USB Nova");
} }

View File

@ -8,9 +8,11 @@
#include <string> #include <string>
#include <stack> #include <stack>
#include "SPI.h" #include <SPI.h>
#include "Adafruit_SPIFlash.h" #include <Adafruit_SPIFlash.h>
#include "Adafruit_TinyUSB.h" #include <Adafruit_TinyUSB.h>
#include "format.h"
namespace msc { namespace msc {
// ===== PRIVATE ===== // // ===== PRIVATE ===== //
@ -72,13 +74,22 @@ namespace msc {
return false; return false;
} }
// Try formatting the drive if initialization failed
if(!fatfs.begin(&flash)) { if(!fatfs.begin(&flash)) {
debugln("Couldn't mount flash!"); format();
return false;
if(!fatfs.begin(&flash)) {
debugln("Couldn't mount flash!");
return false;
}
} }
return true; return true;
} }
bool format(const char* drive_name) {
return format::start(drive_name);
}
void setID(const char* vid, const char* pid, const char* rev) { void setID(const char* vid, const char* pid, const char* rev) {
usb_msc.setID(vid, pid, rev); // Max. 8, 16, 4 characters usb_msc.setID(vid, pid, rev); // Max. 8, 16, 4 characters

View File

@ -6,6 +6,7 @@
namespace msc { namespace msc {
bool init(); bool init();
bool format(const char* drive_name = "USB Nova");
void setID(const char* vid, const char* pid, const char* rev); void setID(const char* vid, const char* pid, const char* rev);
void enableDrive(); void enableDrive();