Skip to content

Commit e760936

Browse files
authored
Merge pull request #438 from liamcottle/storage/nrf52
Add support for storage stats on nRF52/LittleFS
2 parents 9df3c8c + 583cdd4 commit e760936

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

examples/companion_radio/DataStore.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ void DataStore::begin() {
4444
#include <InternalFileSystem.h>
4545
#endif
4646

47+
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
48+
int _countLfsBlock(void *p, lfs_block_t block){
49+
lfs_size_t *size = (lfs_size_t*) p;
50+
*size += 1;
51+
return 0;
52+
}
53+
54+
lfs_ssize_t _getLfsUsedBlockCount() {
55+
lfs_size_t size = 0;
56+
lfs_traverse(InternalFS._getFS(), _countLfsBlock, &size);
57+
return size;
58+
}
59+
#endif
60+
4761
uint32_t DataStore::getStorageUsedKb() const {
4862
#if defined(ESP32)
4963
return SPIFFS.usedBytes() / 1024;
@@ -52,8 +66,13 @@ uint32_t DataStore::getStorageUsedKb() const {
5266
info.usedBytes = 0;
5367
_fs->info(info);
5468
return info.usedBytes / 1024;
69+
#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
70+
const lfs_config* config = InternalFS._getFS()->cfg;
71+
int usedBlockCount = _getLfsUsedBlockCount();
72+
int usedBytes = config->block_size * usedBlockCount;
73+
return usedBytes / 1024;
5574
#else
56-
return 0; // TODO: InternalFS. method?
75+
return 0;
5776
#endif
5877
}
5978

@@ -65,8 +84,12 @@ uint32_t DataStore::getStorageTotalKb() const {
6584
info.totalBytes = 0;
6685
_fs->info(info);
6786
return info.totalBytes / 1024;
87+
#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
88+
const lfs_config* config = InternalFS._getFS()->cfg;
89+
int totalBytes = config->block_size * config->block_count;
90+
return totalBytes / 1024;
6891
#else
69-
return 0; // TODO: InternalFS. method?
92+
return 0;
7093
#endif
7194
}
7295

0 commit comments

Comments
 (0)