.

Revision:
26:06d3aa3eff55
Parent:
25:65a9183a2178
Child:
28:bc8560ba955d
diff -r 65a9183a2178 -r 06d3aa3eff55 main.cpp
--- a/main.cpp	Wed Sep 26 15:01:07 2018 +0100
+++ b/main.cpp	Mon Dec 10 13:30:30 2018 +0000
@@ -17,32 +17,14 @@
 #include <stdio.h>
 #include <errno.h>
 
-// Block devices
-#if COMPONENT_SPIF
-#include "SPIFBlockDevice.h"
-#endif
-
-#if COMPONENT_DATAFLASH
-#include "DataFlashBlockDevice.h"
-#endif 
-
-#if COMPONENT_SD
-#include "SDBlockDevice.h"
-#endif 
-
-#include "HeapBlockDevice.h"
+#include "BlockDevice.h"
 
 // File systems
 #include "LittleFileSystem.h"
 #include "FATFileSystem.h"
 
 
-// Physical block device, can be any device that supports the BlockDevice API
-SPIFBlockDevice bd(
-        MBED_CONF_SPIF_DRIVER_SPI_MOSI,
-        MBED_CONF_SPIF_DRIVER_SPI_MISO,
-        MBED_CONF_SPIF_DRIVER_SPI_CLK,
-        MBED_CONF_SPIF_DRIVER_SPI_CS);
+BlockDevice *bd = BlockDevice::get_default_instance();
 
 // File system declaration
 LittleFileSystem fs("fs");
@@ -53,7 +35,7 @@
 void erase() {
     printf("Initializing the block device... ");
     fflush(stdout);
-    int err = bd.init();
+    int err = bd->init();
     printf("%s\n", (err ? "Fail :(" : "OK"));
     if (err) {
         error("error: %s (%d)\n", strerror(-err), err);
@@ -61,7 +43,7 @@
 
     printf("Erasing the block device... ");
     fflush(stdout);
-    err = bd.erase(0, bd.size());
+    err = bd->erase(0, bd->size());
     printf("%s\n", (err ? "Fail :(" : "OK"));
     if (err) {
         error("error: %s (%d)\n", strerror(-err), err);
@@ -69,7 +51,7 @@
 
     printf("Deinitializing the block device... ");
     fflush(stdout);
-    err = bd.deinit();
+    err = bd->deinit();
     printf("%s\n", (err ? "Fail :(" : "OK"));
     if (err) {
         error("error: %s (%d)\n", strerror(-err), err);
@@ -88,14 +70,14 @@
     // Try to mount the filesystem
     printf("Mounting the filesystem... ");
     fflush(stdout);
-    int err = fs.mount(&bd);
+    int err = fs.mount(bd);
     printf("%s\n", (err ? "Fail :(" : "OK"));
     if (err) {
         // Reformat if we can't mount the filesystem
         // this should only happen on the first boot
         printf("No filesystem found, formatting... ");
         fflush(stdout);
-        err = fs.reformat(&bd);
+        err = fs.reformat(bd);
         printf("%s\n", (err ? "Fail :(" : "OK"));
         if (err) {
             error("error: %s (%d)\n", strerror(-err), err);