|
|
|
@ -19,6 +19,7 @@ |
|
|
|
#include "rd_stdio.h" |
|
|
|
#if LV_USE_FS_LITTLEFS |
|
|
|
#include "../../lvgl/lvgl.h" |
|
|
|
#include "../littlefs/include/lfs.h" |
|
|
|
#endif |
|
|
|
/*----------------------------------------------*
|
|
|
|
* 外部变量说明 * |
|
|
|
@ -64,6 +65,7 @@ WEAK void *Rd_Fopen(const char *path, const char *mode) |
|
|
|
#if LV_USE_FS_LITTLEFS |
|
|
|
lv_fs_mode_t lv_mode; |
|
|
|
if (strchr(mode, 'r') != NULL) lv_mode = LV_FS_MODE_RD; |
|
|
|
else if (strchr(mode, 'a') != NULL) lv_mode = LV_FS_MODE_RD | LV_FS_MODE_WR; |
|
|
|
else lv_mode = LV_FS_MODE_WR; |
|
|
|
|
|
|
|
lv_fs_file_t *file = RD_MALLOC(sizeof(lv_fs_file_t)); |
|
|
|
@ -83,19 +85,14 @@ WEAK void *Rd_Fopen(const char *path, const char *mode) |
|
|
|
lfs_file_t *file = RD_MALLOC(sizeof(lfs_file_t)); |
|
|
|
int flags = 0; |
|
|
|
if (strlen(path) >= 2 && path[1] == ':') p = path + 2; |
|
|
|
/* 按 mode 首字符解析:r 只读 / w 写并截断 / a 追加;
|
|
|
|
带 '+' 则为读写。避免 "a+" 被误判为 TRUNC 清空文件 */ |
|
|
|
if (mode[0] == 'r') { |
|
|
|
if (strchr(mode, 'r') != NULL) { |
|
|
|
flags = LFS_O_RDONLY; |
|
|
|
if (strchr(mode, '+')) flags = LFS_O_RDWR; |
|
|
|
} else if (mode[0] == 'w') { |
|
|
|
} else if (strchr(mode, 'w') != NULL) { |
|
|
|
flags = LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC; |
|
|
|
if (strchr(mode, '+')) flags = LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC; |
|
|
|
} else if (mode[0] == 'a') { |
|
|
|
flags = LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND; |
|
|
|
if (strchr(mode, '+')) flags = LFS_O_RDWR | LFS_O_CREAT | LFS_O_APPEND; |
|
|
|
} else if (strchr(mode, 'a') != NULL) { |
|
|
|
flags = LFS_O_RDWR | LFS_O_CREAT | LFS_O_APPEND; |
|
|
|
} else { |
|
|
|
flags = LFS_O_RDONLY; /* 未知 mode 默认只读 */ |
|
|
|
flags = LFS_O_RDONLY; |
|
|
|
} |
|
|
|
int err = lfs_file_open(&g_lfs, file, p, flags); |
|
|
|
if(err) return NULL; |
|
|
|
@ -307,7 +304,15 @@ WEAK int Rd_fflush(void *file) |
|
|
|
{ |
|
|
|
#ifdef USE_W25QXX |
|
|
|
#if LV_USE_FS_LITTLEFS |
|
|
|
(void)file; |
|
|
|
if (file == NULL) return RD_FAILURE; |
|
|
|
lv_fs_file_t *fp = (lv_fs_file_t *)file; |
|
|
|
lfs_t *lfs = fp->drv->user_data; |
|
|
|
int err = lfs_file_sync(lfs, fp->file_d); |
|
|
|
if (err < 0) |
|
|
|
{ |
|
|
|
printf("lfs_file_sync failed: %d\n", err); |
|
|
|
return RD_FAILURE; |
|
|
|
} |
|
|
|
return RD_SUCCESS; |
|
|
|
#else |
|
|
|
if (file == NULL) return RD_FAILURE; |
|
|
|
@ -355,8 +360,12 @@ WEAK int Rd_rename(const char *oldpath, const char *newpath) |
|
|
|
|
|
|
|
int Rd_Lfs_Mount(void) |
|
|
|
{ |
|
|
|
#ifdef USE_W25QXX |
|
|
|
lfs_format(&g_lfs, &g_cfg); |
|
|
|
return lfs_mount(&g_lfs, &g_cfg); |
|
|
|
#else |
|
|
|
return 0; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
WEAK void Rd_LittleFSInit(void) |
|
|
|
|