This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
forked from Jason2866/LittleFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlittlefs_api.c
58 lines (49 loc) · 1.72 KB
/
littlefs_api.c
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
/**
* @file littlefs_api.c
* @brief Maps the HAL of esp_partition <-> littlefs
* @author Brian Pugh
*/
#define ESP_LOCAL_LOG_LEVEL ESP_LOG_INFO
#include "esp_log.h"
#include "esp_partition.h"
#include "esp_vfs.h"
#include "lfs.h"
#include "esp_littlefs.h"
#include "littlefs_api.h"
static const char TAG[] = "esp_littlefs_api";
int littlefs_api_read(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, void *buffer, lfs_size_t size) {
esp_littlefs_t * efs = c->context;
size_t part_off = (block * c->block_size) + off;
esp_err_t err = esp_partition_read(efs->partition, part_off, buffer, size);
if (err) {
ESP_LOGE(TAG, "failed to read addr %08x, size %08x, err %d", part_off, size, err);
return LFS_ERR_IO;
}
return 0;
}
int littlefs_api_prog(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, const void *buffer, lfs_size_t size) {
esp_littlefs_t * efs = c->context;
size_t part_off = (block * c->block_size) + off;
esp_err_t err = esp_partition_write(efs->partition, part_off, buffer, size);
if (err) {
ESP_LOGE(TAG, "failed to write addr %08x, size %08x, err %d", part_off, size, err);
return LFS_ERR_IO;
}
return 0;
}
int littlefs_api_erase(const struct lfs_config *c, lfs_block_t block) {
esp_littlefs_t * efs = c->context;
size_t part_off = block * c->block_size;
esp_err_t err = esp_partition_erase_range(efs->partition, part_off, c->block_size);
if (err) {
ESP_LOGE(TAG, "failed to erase addr %08x, size %08x, err %d", part_off, c->block_size, err);
return LFS_ERR_IO;
}
return 0;
}
int littlefs_api_sync(const struct lfs_config *c) {
/* Unnecessary for esp-idf */
return 0;
}