Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added rename/format(spi,qspi) to littlefs #1

Merged
merged 1 commit into from
Nov 13, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/LittleFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ bool LittleFS_SPIFlash::begin(uint8_t cspin, SPIClass &spiport)
return true;
}

FLASHMEM
bool LittleFS_SPIFlash::format()
{

Serial.println("attemping to format existing media");
if (lfs_format(&lfs, &config) < 0) {
Serial.println("format failed :(");
return false;
}
Serial.println("attemping to mount freshly formatted media");
if (lfs_mount(&lfs, &config) < 0) {
Serial.println("mount after format failed :(");
return false;
}
Serial.println("success");
return true;
}



static void make_command_and_address(uint8_t *buf, uint8_t cmd, uint32_t addr, uint8_t addrbits)
{
Expand Down Expand Up @@ -205,7 +224,7 @@ int LittleFS_SPIFlash::wait(uint32_t microseconds)
if (usec > microseconds) return LFS_ERR_IO; // timeout
yield();
}
Serial.printf(" waited %u us\n", (unsigned int)usec);
//Serial.printf(" waited %u us\n", (unsigned int)usec);
return 0; // success
}

Expand Down Expand Up @@ -397,6 +416,25 @@ bool LittleFS_QSPIFlash::begin()
return true;
}

FLASHMEM
bool LittleFS_QSPIFlash::format()
{

Serial.println("attemping to format existing media");
if (lfs_format(&lfs, &config) < 0) {
Serial.println("format failed :(");
return false;
}
Serial.println("attemping to mount freshly formatted media");
if (lfs_mount(&lfs, &config) < 0) {
Serial.println("mount after format failed :(");
return false;
}
Serial.println("success");
return true;
}



int LittleFS_QSPIFlash::read(lfs_block_t block, lfs_off_t offset, void *buf, lfs_size_t size)
{
Expand Down
10 changes: 9 additions & 1 deletion src/LittleFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ class LittleFS : public FS
if (lfs_mkdir(&lfs, filepath) < 0) return false;
return true;
}

bool rename(const char *oldfilepath, const char *newfilepath) {
if (!configured) return false;
if (lfs_rename(&lfs, oldfilepath, newfilepath) < 0) return false;
return true;
}

bool remove(const char *filepath) {
if (!configured) return false;
if (lfs_remove(&lfs, filepath) < 0) return false;
Expand Down Expand Up @@ -297,6 +304,7 @@ class LittleFS_SPIFlash : public LittleFS
port = nullptr;
}
bool begin(uint8_t cspin, SPIClass &spiport=SPI);
bool format();
private:
int read(lfs_block_t block, lfs_off_t offset, void *buf, lfs_size_t size);
int prog(lfs_block_t block, lfs_off_t offset, const void *buf, lfs_size_t size);
Expand Down Expand Up @@ -333,6 +341,7 @@ class LittleFS_QSPIFlash : public LittleFS
public:
LittleFS_QSPIFlash() { }
bool begin();
bool format();
private:
int read(lfs_block_t block, lfs_off_t offset, void *buf, lfs_size_t size);
int prog(lfs_block_t block, lfs_off_t offset, const void *buf, lfs_size_t size);
Expand Down Expand Up @@ -365,7 +374,6 @@ class LittleFS_QSPIFlash : public LittleFS
public:
LittleFS_QSPIFlash() { }
bool begin() { return false; }
};
#endif


Expand Down