From 4bb7270d81c5804ef0ce5df67809e04b9b7da814 Mon Sep 17 00:00:00 2001 From: Spacehuhn Date: Sat, 16 Jul 2022 11:53:03 +0200 Subject: [PATCH] Moved format into msc --- USBNova.ino | 19 +++++++------------ src/{format => msc}/diskio.h | 0 src/{format => msc}/ff.c | 0 src/{format => msc}/ff.h | 0 src/{format => msc}/ffconf.h | 0 src/{format => msc}/format.cpp | 0 src/{format => msc}/format.h | 1 - src/msc/msc.cpp | 21 ++++++++++++++++----- src/msc/msc.h | 1 + 9 files changed, 24 insertions(+), 18 deletions(-) rename src/{format => msc}/diskio.h (100%) rename src/{format => msc}/ff.c (100%) rename src/{format => msc}/ff.h (100%) rename src/{format => msc}/ffconf.h (100%) rename src/{format => msc}/format.cpp (100%) rename src/{format => msc}/format.h (95%) diff --git a/USBNova.ino b/USBNova.ino index 1bc1ec4..930e7e3 100644 --- a/USBNova.ino +++ b/USBNova.ino @@ -9,7 +9,6 @@ #include "src/attack/attack.h" #include "src/preferences/preferences.h" #include "src/duckparser/duckparser.h" -#include "src/format/format.h" #include "src/tasks/tasks.h" void setup() { @@ -18,16 +17,12 @@ void setup() { selector::init(); // Initialize memory and ceck for problems if (!msc::init()) { - format::start(); // Format the drive - - // If it still fails, blink red LED - if (!msc::init()) { - while (true) { - led::setColor(255, 0, 0); - delay(500); - led::setColor(0, 0, 0); - delay(500); - } + // Blink red and do nothing + while (true) { + led::setColor(255, 0, 0); + delay(500); + led::setColor(0, 0, 0); + delay(500); } } preferences::load(); @@ -52,7 +47,7 @@ void setup() { // Format Flash if ((selector::mode() == SETUP) && preferences::getFormat()) { 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 diff --git a/src/format/diskio.h b/src/msc/diskio.h similarity index 100% rename from src/format/diskio.h rename to src/msc/diskio.h diff --git a/src/format/ff.c b/src/msc/ff.c similarity index 100% rename from src/format/ff.c rename to src/msc/ff.c diff --git a/src/format/ff.h b/src/msc/ff.h similarity index 100% rename from src/format/ff.h rename to src/msc/ff.h diff --git a/src/format/ffconf.h b/src/msc/ffconf.h similarity index 100% rename from src/format/ffconf.h rename to src/msc/ffconf.h diff --git a/src/format/format.cpp b/src/msc/format.cpp similarity index 100% rename from src/format/format.cpp rename to src/msc/format.cpp diff --git a/src/format/format.h b/src/msc/format.h similarity index 95% rename from src/format/format.h rename to src/msc/format.h index 76eda1f..50e64a4 100644 --- a/src/format/format.h +++ b/src/msc/format.h @@ -2,7 +2,6 @@ #pragma once - namespace format { bool start(const char* drive_name = "USB Nova"); } \ No newline at end of file diff --git a/src/msc/msc.cpp b/src/msc/msc.cpp index c9d9086..7508600 100644 --- a/src/msc/msc.cpp +++ b/src/msc/msc.cpp @@ -8,9 +8,11 @@ #include #include -#include "SPI.h" -#include "Adafruit_SPIFlash.h" -#include "Adafruit_TinyUSB.h" +#include +#include +#include + +#include "format.h" namespace msc { // ===== PRIVATE ===== // @@ -72,13 +74,22 @@ namespace msc { return false; } + // Try formatting the drive if initialization failed if(!fatfs.begin(&flash)) { - debugln("Couldn't mount flash!"); - return false; + format(); + + if(!fatfs.begin(&flash)) { + debugln("Couldn't mount flash!"); + return false; + } } return true; } + + bool format(const char* drive_name) { + return format::start(drive_name); + } void setID(const char* vid, const char* pid, const char* rev) { usb_msc.setID(vid, pid, rev); // Max. 8, 16, 4 characters diff --git a/src/msc/msc.h b/src/msc/msc.h index f8d188e..41310d1 100644 --- a/src/msc/msc.h +++ b/src/msc/msc.h @@ -6,6 +6,7 @@ namespace msc { bool init(); + bool format(const char* drive_name = "USB Nova"); void setID(const char* vid, const char* pid, const char* rev); void enableDrive();