diff --git a/include/Filesystem.h b/include/Filesystem.h index b71d972..a201e45 100644 --- a/include/Filesystem.h +++ b/include/Filesystem.h @@ -3,7 +3,7 @@ #include "MainFilesystem.h" -void mountFilesystem(mbed::BlockDevice& bd, LittleFileSystem2& fs); -void unmountFilesystem(mbed::BlockDevice& bd, LittleFileSystem2& fs); +void mountFilesystem(mbed::BlockDevice &bd, LittleFileSystem2 &fs); +void unmountFilesystem(mbed::BlockDevice &bd, LittleFileSystem2 &fs); #endif diff --git a/include/FlashErase.h b/include/FlashErase.h index 529ade9..db2857b 100644 --- a/include/FlashErase.h +++ b/include/FlashErase.h @@ -4,6 +4,6 @@ #include "Filesystem.h" #include "MainBD.h" -void doErase(mbed::BlockDevice& bd, LittleFileSystem2& fs); +void doErase(mbed::BlockDevice &bd, LittleFileSystem2 &fs); #endif diff --git a/include/MainBD.h b/include/MainBD.h index bd55a9a..a9161e0 100644 --- a/include/MainBD.h +++ b/include/MainBD.h @@ -1,8 +1,8 @@ #ifndef MAINBD_H #define MAINBD_H -#include "mbed.h" #include "QSPIFBlockDevice.h" +#include "mbed.h" extern QSPIFBlockDevice mainBD; diff --git a/include/MainFilesystem.h b/include/MainFilesystem.h index 3782e01..68ccf22 100644 --- a/include/MainFilesystem.h +++ b/include/MainFilesystem.h @@ -1,8 +1,8 @@ #ifndef MAINFS_H #define MAINFS_H -#include "mbed.h" #include "LittleFileSystem2.h" +#include "mbed.h" extern LittleFileSystem2 mainFS; diff --git a/include/MyUSBMSD.h b/include/MyUSBMSD.h index 62aff60..54e9785 100644 --- a/include/MyUSBMSD.h +++ b/include/MyUSBMSD.h @@ -1,16 +1,18 @@ #ifndef MYUSBMSD_H #define MYUSBMSD_H -#include "mbed.h" #include "USBMSD.h" +#include "mbed.h" class MyUSBMSD : public USBMSD { -public: - MyUSBMSD(mbed::BlockDevice *bd, bool connect_blocking=true, uint16_t vendor_id=0x0703, uint16_t product_id=0x0104, uint16_t product_release=0x0001); + public: + MyUSBMSD(mbed::BlockDevice *bd, bool connect_blocking = true, + uint16_t vendor_id = 0x0703, uint16_t product_id = 0x0104, + uint16_t product_release = 0x0001); -private: + private: virtual const uint8_t *string_iproduct_desc(); }; -void doUSBMSD(mbed::BlockDevice& bd, LittleFileSystem2& fs); +void doUSBMSD(mbed::BlockDevice &bd, LittleFileSystem2 &fs); #endif diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index a314d09..4ab76a2 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -1,14 +1,12 @@ -#include "mbed.h" #include "ButtonThread.h" +#include "mbed.h" EventFlags buttonFlags; #define PUSH_FLAG 0b01 #define LIFT_FLAG 0b10 -void button_onrise(void) { - buttonFlags.set(PUSH_FLAG); -} +void button_onrise(void) { buttonFlags.set(PUSH_FLAG); } int readButtonPresses(void) { int pressed_count = 0; @@ -17,13 +15,13 @@ buttonFlags.wait_any(PUSH_FLAG); pressed_count++; - while(true) { + while (true) { uint32_t flags = buttonFlags.wait_any(PUSH_FLAG, 1000); bool timed_out = flags == osFlagsErrorTimeout; bool had_any_error = flags & osFlagsError; - if(timed_out) { + if (timed_out) { break; - } else if(had_any_error) { + } else if (had_any_error) { error("Uhh what the f?\n"); } else { pressed_count++; @@ -41,7 +39,7 @@ InterruptIn buttonIRQ(BUTTON1); buttonIRQ.rise(button_onrise); - while(true) { + while (true) { int presses = readButtonPresses(); buttonPressMutex.lock(); buttonPressCount = presses; @@ -52,8 +50,8 @@ bool waitPressCondition(Kernel::Clock::time_point timeout) { // buttonPressCount is 0 if we have already read the current value - while(buttonPressCount == 0) { - if(cv.wait_until(timeout) == cv_status::timeout) { + while (buttonPressCount == 0) { + if (cv.wait_until(timeout) == cv_status::timeout) { return false; } } @@ -65,7 +63,7 @@ Kernel::Clock::time_point timeout = Kernel::Clock::now() + wait_time; int presses = -1; buttonPressMutex.lock(); - if(waitPressCondition(timeout)) { + if (waitPressCondition(timeout)) { presses = buttonPressCount; buttonPressCount = 0; } diff --git a/src/Filesystem.cpp b/src/Filesystem.cpp index ded610d..96b1aa7 100644 --- a/src/Filesystem.cpp +++ b/src/Filesystem.cpp @@ -1,8 +1,8 @@ +#include "Filesystem.h" +#include "MainBD.h" #include "mbed.h" #include #include -#include "Filesystem.h" -#include "MainBD.h" // Maximum number of elements in buffer #define BUFFER_MAX_LEN 10 @@ -10,7 +10,7 @@ // function to attempt to mount the filesystem and // reformat and mount it again should it fail -void mountFilesystem(mbed::BlockDevice& bd, LittleFileSystem2& fs) { +void mountFilesystem(mbed::BlockDevice &bd, LittleFileSystem2 &fs) { int err; // Try to mount the filesystem printf("Mounting the filesystem... "); @@ -26,11 +26,11 @@ if (err) { error("error: %s (%d)\n", strerror(-err), err); } - // Try to mount the filesystem again - printf("Mounting the filesystem... "); - fflush(stdout); - err = fs.mount(&bd); - printf("%s\n", (err ? "Fail :(" : "OK")); + // Try to mount the filesystem again + printf("Mounting the filesystem... "); + fflush(stdout); + err = fs.mount(&bd); + printf("%s\n", (err ? "Fail :(" : "OK")); if (err) { error("error: %s (%d)\n", strerror(-err), err); } @@ -38,7 +38,7 @@ } // function to unmount the filesystem -void unmountFilesystem(mbed::BlockDevice& bd, LittleFileSystem2& fs) { +void unmountFilesystem(mbed::BlockDevice &bd, LittleFileSystem2 &fs) { // Try to unmount the filesystem printf("Unmounting the filesystem... "); fflush(stdout); diff --git a/src/FlashErase.cpp b/src/FlashErase.cpp index 613f5a2..9ee65b5 100644 --- a/src/FlashErase.cpp +++ b/src/FlashErase.cpp @@ -1,10 +1,10 @@ +#include "FlashErase.h" #include "mbed.h" #include #include -#include "FlashErase.h" // function to erase the flash -void doErase(mbed::BlockDevice& bd, LittleFileSystem2& fs) { +void doErase(mbed::BlockDevice &bd, LittleFileSystem2 &fs) { // Try to unmount the filesystem unmountFilesystem(bd, fs); printf("Initializing the block device... "); @@ -28,6 +28,6 @@ err = bd.deinit(); printf("%s\n", (err ? "Fail :(" : "OK")); if (err) { - error("error: %s (%d)\n", strerror(-err), err); + error("error: %s (%d)\n", strerror(-err), err); } } diff --git a/src/MainBD.cpp b/src/MainBD.cpp index cee3c60..987d9e3 100644 --- a/src/MainBD.cpp +++ b/src/MainBD.cpp @@ -1,10 +1,11 @@ #if !DEVICE_QSPI -#error [NOT_SUPPORTED] QSPI not supported for this target +#error[NOT_SUPPORTED] QSPI not supported for this target #endif -#include "mbed.h" #include "MainBD.h" +#include "mbed.h" // set up the QSPI flash -QSPIFBlockDevice mainBD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, - QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); +QSPIFBlockDevice mainBD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, + QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, + QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); diff --git a/src/MainFilesystem.cpp b/src/MainFilesystem.cpp index c6021a9..74f7218 100644 --- a/src/MainFilesystem.cpp +++ b/src/MainFilesystem.cpp @@ -1,5 +1,5 @@ -#include "mbed.h" #include "MainFilesystem.h" +#include "mbed.h" // setup the filesystem LittleFileSystem2 mainFS("fs"); diff --git a/src/MyUSBMSD.cpp b/src/MyUSBMSD.cpp index b53e901..4403cf8 100644 --- a/src/MyUSBMSD.cpp +++ b/src/MyUSBMSD.cpp @@ -1,35 +1,38 @@ +#include "MyUSBMSD.h" #include "ButtonThread.h" #include "Filesystem.h" #include "mbed.h" -#include "MyUSBMSD.h" // create a custom usb mass storage subclass to override // the product description -MyUSBMSD::MyUSBMSD(mbed::BlockDevice *bd, bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release) - : USBMSD(bd, connect_blocking, vendor_id, product_id, product_release) { -} +MyUSBMSD::MyUSBMSD(mbed::BlockDevice *bd, bool connect_blocking, + uint16_t vendor_id, uint16_t product_id, uint16_t product_release) + : USBMSD(bd, connect_blocking, vendor_id, product_id, product_release) {} const uint8_t *MyUSBMSD::string_iproduct_desc() { static const uint8_t string_iproduct_descriptor[] = { - 0x28, //bLength - STRING_DESCRIPTOR, //bDescriptorType - 'L', 0, 'u', 0, 'm', 0, 'i', 0, 'n', 0, 'a', 0, 'S', 0, 'e', 0, 'n', 0, 's', 0, 'u', 0, 'm', 0, ' ', 0, 'T', 0, 'a', 0, 'r', 0, 'd', 0, 'i', 0, 's', 0 //bString iProduct - usb mass storage + 0x28, // bLength + STRING_DESCRIPTOR, // bDescriptorType + 'L', 0, 'u', 0, 'm', 0, 'i', 0, 'n', 0, 'a', 0, 'S', 0, 'e', 0, + 'n', 0, 's', 0, 'u', 0, 'm', 0, ' ', 0, 'T', 0, 'a', 0, 'r', 0, + 'd', 0, 'i', 0, 's', 0 // bString iProduct - usb mass storage }; return string_iproduct_descriptor; } -void doUSBMSD(mbed::BlockDevice& bd, LittleFileSystem2& fs) { +void doUSBMSD(mbed::BlockDevice &bd, LittleFileSystem2 &fs) { // Try to unmount the filesystem -unmountFilesystem(bd, fs); + unmountFilesystem(bd, fs); printf("Switching to the usb mass storage mode...\n"); MyUSBMSD usb(&bd, true, 0x1209, 0x10); while (true) { int presses = waitForPresses(0s); usb.process(); - if(presses == 1) { - printf("Disconnecting the usb mass storage device...\n"); + if (presses == 1) { + printf("Disconnecting the usb mass storage " + "device...\n"); usb.disconnect(); printf("Switched usb mass storage mode off.\n"); mountFilesystem(bd, fs); diff --git a/src/main.cpp b/src/main.cpp index 485099d..39512dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,12 @@ -#include "mbed.h" #include "ButtonThread.h" #include "Filesystem.h" #include "FlashErase.h" #include "MainBD.h" #include "MainFilesystem.h" #include "MyUSBMSD.h" +#include "mbed.h" -int main() -{ +int main() { printf("Project Tardis\n"); mountFilesystem(mainBD, mainFS); @@ -15,13 +14,13 @@ Thread buttonThread; buttonThread.start(buttonTask); - while(true) { + while (true) { int presses = waitForPresses(600s); - if(presses == 1) { + if (presses == 1) { doUSBMSD(mainBD, mainFS); } - if(presses == 2) { + if (presses == 2) { doErase(mainBD, mainFS); } }