feat(fsdrv): set the working directory (#7272)

Signed-off-by: lhdjply <lhdjply@126.com>
This commit is contained in:
Liu Yi 2024-11-20 11:00:10 +08:00 committed by GitHub
parent e85059d822
commit 11be75e302
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 77 additions and 17 deletions

12
Kconfig
View File

@ -1240,6 +1240,9 @@ menu "LVGL configuration"
int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')"
default 0
depends on LV_USE_FS_FATFS
config LV_FS_FATFS_PATH
string "Set the working directory"
depends on LV_USE_FS_FATFS
config LV_FS_FATFS_CACHE_SIZE
int ">0 to cache this number of bytes in lv_fs_read()"
default 0
@ -1258,6 +1261,9 @@ menu "LVGL configuration"
int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')"
default 0
depends on LV_USE_FS_LITTLEFS
config LV_FS_LITTLEFS_PATH
string "Set the working directory"
depends on LV_USE_FS_LITTLEFS
config LV_USE_FS_ARDUINO_ESP_LITTLEFS
bool "File system on top of Arduino ESP littlefs API"
@ -1265,6 +1271,9 @@ menu "LVGL configuration"
int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')"
default 0
depends on LV_USE_FS_ARDUINO_ESP_LITTLEFS
config LV_FS_ARDUINO_ESP_LITTLEFS_PATH
string "Set the working directory"
depends on LV_USE_FS_ARDUINO_ESP_LITTLEFS
config LV_USE_FS_ARDUINO_SD
bool "File system on top of Arduino SD API"
@ -1272,6 +1281,9 @@ menu "LVGL configuration"
int "Set an upper cased letter on which the drive will accessible (e.g. 65 for 'A')"
default 0
depends on LV_USE_FS_ARDUINO_SD
config LV_FS_ARDUINO_SD_PATH
string "Set the working directory"
depends on LV_USE_FS_ARDUINO_SD
config LV_USE_LODEPNG
bool "PNG decoder library"

View File

@ -814,6 +814,7 @@
#define LV_USE_FS_FATFS 0
#if LV_USE_FS_FATFS
#define LV_FS_FATFS_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#define LV_FS_FATFS_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#define LV_FS_FATFS_CACHE_SIZE 0 /**< >0 to cache this number of bytes in lv_fs_read() */
#endif
@ -827,18 +828,21 @@
#define LV_USE_FS_LITTLEFS 0
#if LV_USE_FS_LITTLEFS
#define LV_FS_LITTLEFS_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#define LV_FS_LITTLEFS_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#endif
/** API for Arduino LittleFs. */
#define LV_USE_FS_ARDUINO_ESP_LITTLEFS 0
#if LV_USE_FS_ARDUINO_ESP_LITTLEFS
#define LV_FS_ARDUINO_ESP_LITTLEFS_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#define LV_FS_ARDUINO_ESP_LITTLEFS_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#endif
/** API for Arduino Sd. */
#define LV_USE_FS_ARDUINO_SD 0
#if LV_USE_FS_ARDUINO_SD
#define LV_FS_ARDUINO_SD_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#define LV_FS_ARDUINO_SD_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#endif
/** LODEPNG decoder library */

View File

@ -77,7 +77,10 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
flags = FILE_WRITE;
File file = LittleFS.open(path, flags);
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_ARDUINO_ESP_LITTLEFS_PATH "%s", path);
File file = LittleFS.open(buf, flags);
if(!file) {
return NULL;
}

View File

@ -69,7 +69,10 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
flags = FILE_WRITE;
File file = SD.open(path, flags);
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_ARDUINO_SD_PATH "%s", path);
File file = SD.open(buf, flags);
if(!file) {
return NULL;
}

View File

@ -117,7 +117,10 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
FIL * f = lv_malloc(sizeof(FIL));
if(f == NULL) return NULL;
FRESULT res = f_open(f, path, flags);
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_FATFS_PATH "%s", path);
FRESULT res = f_open(f, buf, flags);
if(res == FR_OK) {
return f;
}
@ -232,7 +235,10 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
DIR * d = lv_malloc(sizeof(DIR));
if(d == NULL) return NULL;
FRESULT res = f_opendir(d, path);
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_FATFS_PATH "%s", path);
FRESULT res = f_opendir(d, buf);
if(res != FR_OK) {
lv_free(d);
d = NULL;

View File

@ -82,8 +82,11 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
LittleFile * lf = lv_malloc(sizeof(LittleFile));
LV_ASSERT_MALLOC(lf);
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_LITTLEFS_PATH "%s", path);
lfs_t * lfs = drv->user_data;
int err = lfs_file_open(lfs, &lf->file, path, flags);
int err = lfs_file_open(lfs, &lf->file, buf, flags);
if(err) {
return NULL;
}
@ -200,8 +203,11 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
LittleDirectory * ld = lv_malloc(sizeof(LittleDirectory));
LV_ASSERT_MALLOC(ld);
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_LITTLEFS_PATH "%s", path);
lfs_t * lfs = drv->user_data;
int err = lfs_dir_open(lfs, &ld->dir, path);
int err = lfs_dir_open(lfs, &ld->dir, buf);
if(err != LFS_ERR_OK) {
lv_free(ld);
return NULL;

View File

@ -113,7 +113,7 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = O_RDWR | O_CREAT;
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_POSIX_PATH "%s", path);
int fd = open(buf, flags, 0666);

View File

@ -26,15 +26,13 @@
#error "Invalid drive letter"
#endif
#define MAX_PATH_LEN 256
/**********************
* TYPEDEFS
**********************/
typedef struct {
#ifdef _WIN32
HANDLE dir_p;
char next_fn[MAX_PATH_LEN];
char next_fn[LV_FS_MAX_PATH_LEN];
#else
DIR * dir_p;
#endif
@ -118,7 +116,7 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
/*Make the path relative to the current directory (the projects root folder)*/
char buf[MAX_PATH_LEN];
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_STDIO_PATH "%s", path);
return fopen(buf, flags);
@ -228,7 +226,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
dir_handle_t * handle = (dir_handle_t *)lv_malloc(sizeof(dir_handle_t));
#ifndef WIN32
/*Make the path relative to the current directory (the projects root folder)*/
char buf[MAX_PATH_LEN];
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_STDIO_PATH "%s", path);
handle->dir_p = opendir(buf);
if(handle->dir_p == NULL) {
@ -241,7 +239,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
WIN32_FIND_DATAA fdata;
/*Make the path relative to the current directory (the projects root folder)*/
char buf[MAX_PATH_LEN];
char buf[LV_FS_MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_STDIO_PATH "%s\\*", path);
lv_strcpy(handle->next_fn, "");

View File

@ -22,14 +22,12 @@
#error "Invalid drive letter"
#endif
#define MAX_PATH_LEN 256
/**********************
* TYPEDEFS
**********************/
typedef struct {
HANDLE dir_p;
char next_fn[MAX_PATH_LEN];
char next_fn[LV_FS_MAX_PATH_LEN];
lv_fs_res_t next_error;
} dir_handle_t;
@ -371,7 +369,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
WIN32_FIND_DATAA fdata;
/*Make the path relative to the current directory (the projects root folder)*/
char buf[MAX_PATH_LEN];
char buf[LV_FS_MAX_PATH_LEN];
#ifdef LV_FS_WIN32_PATH
lv_snprintf(buf, sizeof(buf), LV_FS_WIN32_PATH "%s\\*", path);
#else

View File

@ -19,6 +19,8 @@ extern "C" {
* DEFINES
*********************/
#define LV_FS_MAX_PATH_LEN 256
/**********************
* TYPEDEFS
**********************/

View File

@ -2630,6 +2630,13 @@
#define LV_FS_FATFS_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#endif
#endif
#ifndef LV_FS_FATFS_PATH
#ifdef CONFIG_LV_FS_FATFS_PATH
#define LV_FS_FATFS_PATH CONFIG_LV_FS_FATFS_PATH
#else
#define LV_FS_FATFS_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#endif
#endif
#ifndef LV_FS_FATFS_CACHE_SIZE
#ifdef CONFIG_LV_FS_FATFS_CACHE_SIZE
#define LV_FS_FATFS_CACHE_SIZE CONFIG_LV_FS_FATFS_CACHE_SIZE
@ -2673,6 +2680,13 @@
#define LV_FS_LITTLEFS_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#endif
#endif
#ifndef LV_FS_LITTLEFS_PATH
#ifdef CONFIG_LV_FS_LITTLEFS_PATH
#define LV_FS_LITTLEFS_PATH CONFIG_LV_FS_LITTLEFS_PATH
#else
#define LV_FS_LITTLEFS_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#endif
#endif
#endif
/** API for Arduino LittleFs. */
@ -2691,6 +2705,13 @@
#define LV_FS_ARDUINO_ESP_LITTLEFS_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#endif
#endif
#ifndef LV_FS_ARDUINO_ESP_LITTLEFS_PATH
#ifdef CONFIG_LV_FS_ARDUINO_ESP_LITTLEFS_PATH
#define LV_FS_ARDUINO_ESP_LITTLEFS_PATH CONFIG_LV_FS_ARDUINO_ESP_LITTLEFS_PATH
#else
#define LV_FS_ARDUINO_ESP_LITTLEFS_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#endif
#endif
#endif
/** API for Arduino Sd. */
@ -2709,6 +2730,13 @@
#define LV_FS_ARDUINO_SD_LETTER '\0' /**< Set an upper cased letter on which the drive will accessible (e.g. 'A') */
#endif
#endif
#ifndef LV_FS_ARDUINO_SD_PATH
#ifdef CONFIG_LV_FS_ARDUINO_SD_PATH
#define LV_FS_ARDUINO_SD_PATH CONFIG_LV_FS_ARDUINO_SD_PATH
#else
#define LV_FS_ARDUINO_SD_PATH "" /**< Set the working directory. File/directory paths will be appended to it. */
#endif
#endif
#endif
/** LODEPNG decoder library */