Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed m3pi ID12RFIDIRQ
Diff: blueusb/MassStorageFS.cpp
- Revision:
- 0:e2ef12467862
diff -r 000000000000 -r e2ef12467862 blueusb/MassStorageFS.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/blueusb/MassStorageFS.cpp Mon Apr 11 23:03:22 2011 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+#include "FATFileSystem.h"
+#include "Utils.h"
+
+int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
+int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
+int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
+
+class USBFileSystem : public FATFileSystem
+{
+ int _device;
+ u32 _blockSize;
+ u32 _blockCount;
+
+public:
+ USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
+ {
+ }
+
+ void SetDevice(int device)
+ {
+ _device = device;
+ }
+
+ virtual int disk_initialize()
+ {
+ return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
+ }
+
+ virtual int disk_write(const char *buffer, int block_number)
+ {
+ return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
+ }
+
+ virtual int disk_read(char *buffer, int block_number)
+ {
+ return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
+ }
+
+ virtual int disk_sectors()
+ {
+ return _blockCount;
+ }
+};
+
+void DumpFS(int depth, int count)
+{
+ DIR *d = opendir("/usb");
+ if (!d)
+ {
+ printf("USB file system borked\n");
+ return;
+ }
+
+ printf("\nDumping root dir\n");
+ struct dirent *p;
+ for(;;)
+ {
+ p = readdir(d);
+ if (!p)
+ break;
+ int len = sizeof( dirent);
+ printf("%s %d\n", p->d_name, len);
+ }
+ closedir(d);
+}
+
+int OnDiskInsert(int device)
+{
+ USBFileSystem fs;
+ fs.SetDevice(device);
+ DumpFS(0,0);
+ return 0;
+}