-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfatfsvfs.cpp
69 lines (57 loc) · 2.04 KB
/
fatfsvfs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* FATFS.cpp
*
* Created on: May 20, 2017
* Author: kolban
*/
#include "fatfsvfs.h"
#include <esp_err.h>
#include <esp_vfs_fat.h>
/**
* @brief Constructor.
*
* In ESP32, every file system has a mount point. If a file access is attempted south of that
* mount point, then the corresponding file system will be used. The `mountPath` parameter defines
* the mount point for this instance of the FATFS file system.
* In order to save the files for subsequent retrieval, the file data has to be written to flash memory.
* A partition table provides a map or layout of the flash memory by defining named partitions. The
* `partitionName` parameter defines the name of the partition used to provide the underlying storage
* for this instance of the FATFS file system.
*
* @param [in] mountPath The path in the VFS where the FAT file system should be mounted.
* @param [in] partitionName The name of the partition used to store the FAT file system.
*/
FATFS_VFS::FATFS_VFS(std::string mountPath, std::string partitionName) {
m_mountPath = mountPath;
m_partitionName = partitionName;
m_maxFiles = 4;
m_wl_handle = WL_INVALID_HANDLE;
} // FATFS_VFS
FATFS_VFS::~FATFS_VFS() {
} // ~FATFS_VFS
/**
* @brief Mount the FAT file system into VFS.
* The FAT file system found in the partition is mounted into the VFS.
* @return N/A.
*/
void FATFS_VFS::mount() {
esp_vfs_fat_mount_config_t mountConfig;
mountConfig.max_files = m_maxFiles;
mountConfig.format_if_mount_failed = true;
ESP_ERROR_CHECK(esp_vfs_fat_spiflash_mount(m_mountPath.c_str(), m_partitionName.c_str(), &mountConfig, &m_wl_handle));
} // mount
/**
* @brief Set the allowable number of concurrently open files.
* @param [in] maxFiles Number of concurrently open files.
* @return N/A.
*/
void FATFS_VFS::setMaxFiles(int maxFiles) {
m_maxFiles = maxFiles;
} // setMaxFiles
/**
* @brief Unmount a previously mounted file system.
* @return N/A.
*/
void FATFS_VFS::unmount() {
ESP_ERROR_CHECK(esp_vfs_fat_spiflash_unmount(m_mountPath.c_str(), m_wl_handle));
} // unmount