Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libraries/SD/examples/SD_Test/SD_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ void setup(){
renameFile(SD, "/hello.txt", "/foo.txt");
readFile(SD, "/foo.txt");
testFileIO(SD, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}

void loop(){
Expand Down
29 changes: 29 additions & 0 deletions libraries/SD/src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "vfs_api.h"
#include "sd_diskio.h"
#include "ff.h"
#include "FS.h"
#include "SD.h"

Expand Down Expand Up @@ -73,4 +74,32 @@ uint64_t SDFS::cardSize()
return (uint64_t)sectors * sectorSize;
}

uint64_t SDFS::totalBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*(fsinfo->n_fatent - 2)
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}

uint64_t SDFS::usedBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*((fsinfo->n_fatent - 2) - (fsinfo->free_clst))
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}

SDFS SD = SDFS(FSImplPtr(new VFSImpl()));
2 changes: 2 additions & 0 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class SDFS : public FS
void end();
sdcard_type_t cardType();
uint64_t cardSize();
uint64_t totalBytes();
uint64_t usedBytes();
};

}
Expand Down
2 changes: 2 additions & 0 deletions libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ void setup(){
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
readFile(SD_MMC, "/foo.txt");
testFileIO(SD_MMC, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}

void loop(){
Expand Down
28 changes: 28 additions & 0 deletions libraries/SD_MMC/src/SD_MMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern "C" {
#include "driver/sdmmc_defs.h"
#include "sdmmc_cmd.h"
}
#include "ff.h"
#include "SD_MMC.h"

using namespace fs;
Expand Down Expand Up @@ -98,5 +99,32 @@ uint64_t SDMMCFS::cardSize()
return (uint64_t)_card->csd.capacity * _card->csd.sector_size;
}

uint64_t SDMMCFS::totalBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*(fsinfo->n_fatent - 2)
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}

uint64_t SDMMCFS::usedBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*((fsinfo->n_fatent - 2) - (fsinfo->free_clst))
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}

SDMMCFS SD_MMC = SDMMCFS(FSImplPtr(new VFSImpl()));
2 changes: 2 additions & 0 deletions libraries/SD_MMC/src/SD_MMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class SDMMCFS : public FS
void end();
sdcard_type_t cardType();
uint64_t cardSize();
uint64_t totalBytes();
uint64_t usedBytes();
};

}
Expand Down