arduino-audio-tools
Loading...
Searching...
No Matches
VFS_LittleFS.h
Go to the documentation of this file.
1#pragma once
2#include <string.h>
3#include <sys/stat.h>
4#include <sys/unistd.h>
5
7#include "esp_err.h"
8#include "esp_littlefs.h"
9#include "esp_system.h"
10
11namespace audio_tools {
12
25class VFS_LittleFS : public VFS {
26 public:
27 VFS_LittleFS(const char* mountPoint = "/littlefs") {
29 };
30 void setMountPoint(const char* mp) { mount_point = mp; }
31 bool begin() {
32 LOGI("Initializing LittleFS");
33
34 esp_vfs_littlefs_conf_t conf = {
35 .base_path = mount_point,
36 .partition_label = "storage",
37 .format_if_mount_failed = format_if_mount_failed,
38 .dont_mount = false,
39 };
40
41 // Use settings defined above to initialize and mount LittleFS filesystem.
42 // Note: esp_vfs_littlefs_register is an all-in-one convenience function.
43 esp_err_t ret = esp_vfs_littlefs_register(&conf);
44
45 if (ret != ESP_OK) {
46 if (ret == ESP_FAIL) {
47 LOGE("Failed to mount or format filesystem");
48 } else if (ret == ESP_ERR_NOT_FOUND) {
49 LOGE("Failed to find LittleFS partition");
50 } else {
51 LOGE("Failed to initialize LittleFS (%s)", esp_err_to_name(ret));
52 }
53 return false;
54 }
55
56 size_t total = 0, used = 0;
57 ret = esp_littlefs_info(conf.partition_label, &total, &used);
58 if (ret != ESP_OK) {
59 LOGE("Failed to get LittleFS partition information (%s)",
60 esp_err_to_name(ret));
61 // esp_littlefs_format(conf.partition_label);
62 return false;
63 } else {
64 LOGI("Partition size: total: %d, used: %d", total, used);
65 }
66
67 return true;
68 }
69
70 void end() {
71 // All done, unmount partition and disable SPIFFS
72 // All done, unmount partition and disable LittleFS
73 esp_vfs_littlefs_unregister(conf.partition_label);
74 LOGI("LittleFS unmounted");
75 }
76
77 protected:
78 esp_vfs_littlefs_conf_t conf;
79 int max_files = 5;
81};
82} // namespace audio_tools
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30
ESP32 Virtual File System for the LittleFS. The default mount point is "/littlefs" DRAFT implementati...
Definition VFS_LittleFS.h:25
int max_files
Definition VFS_LittleFS.h:79
VFS_LittleFS(const char *mountPoint="/littlefs")
Definition VFS_LittleFS.h:27
bool begin()
mount the file systems
Definition VFS_LittleFS.h:31
void setMountPoint(const char *mp)
provide the mount point (root directory for the file system)
Definition VFS_LittleFS.h:30
void end()
unmount the file system
Definition VFS_LittleFS.h:70
esp_vfs_littlefs_conf_t conf
Definition VFS_LittleFS.h:78
bool format_if_mount_failed
Definition VFS_LittleFS.h:80
Base class which uses c++ file functions. It is also used as base class for an ESP32 Virtual File Sys...
Definition VFS.h:18
const char * mount_point
Definition VFS.h:60
const char * mountPoint()
provides the actual mount point
Definition VFS.h:57
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6