diff --git a/Kconfig b/Kconfig index 3174cfb21..3a65674d2 100644 --- a/Kconfig +++ b/Kconfig @@ -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" diff --git a/lv_conf_template.h b/lv_conf_template.h index bdf512666..7f1cdec62 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -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 */ diff --git a/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp b/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp index 820aa5735..4ce88404f 100644 --- a/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp +++ b/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp @@ -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; } diff --git a/src/libs/fsdrv/lv_fs_arduino_sd.cpp b/src/libs/fsdrv/lv_fs_arduino_sd.cpp index db68226a1..fe7b5ec2e 100644 --- a/src/libs/fsdrv/lv_fs_arduino_sd.cpp +++ b/src/libs/fsdrv/lv_fs_arduino_sd.cpp @@ -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; } diff --git a/src/libs/fsdrv/lv_fs_fatfs.c b/src/libs/fsdrv/lv_fs_fatfs.c index dff3c5951..5bc6f0253 100644 --- a/src/libs/fsdrv/lv_fs_fatfs.c +++ b/src/libs/fsdrv/lv_fs_fatfs.c @@ -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; diff --git a/src/libs/fsdrv/lv_fs_littlefs.c b/src/libs/fsdrv/lv_fs_littlefs.c index d9ee9f61e..e334dca60 100644 --- a/src/libs/fsdrv/lv_fs_littlefs.c +++ b/src/libs/fsdrv/lv_fs_littlefs.c @@ -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; diff --git a/src/libs/fsdrv/lv_fs_posix.c b/src/libs/fsdrv/lv_fs_posix.c index f48c70c8f..9d5af39db 100644 --- a/src/libs/fsdrv/lv_fs_posix.c +++ b/src/libs/fsdrv/lv_fs_posix.c @@ -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); diff --git a/src/libs/fsdrv/lv_fs_stdio.c b/src/libs/fsdrv/lv_fs_stdio.c index 5a4e91c07..d008b247b 100644 --- a/src/libs/fsdrv/lv_fs_stdio.c +++ b/src/libs/fsdrv/lv_fs_stdio.c @@ -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, ""); diff --git a/src/libs/fsdrv/lv_fs_win32.c b/src/libs/fsdrv/lv_fs_win32.c index 764953e12..a8540a0a1 100644 --- a/src/libs/fsdrv/lv_fs_win32.c +++ b/src/libs/fsdrv/lv_fs_win32.c @@ -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 diff --git a/src/libs/fsdrv/lv_fsdrv.h b/src/libs/fsdrv/lv_fsdrv.h index f830c3a2d..380fd3e8c 100644 --- a/src/libs/fsdrv/lv_fsdrv.h +++ b/src/libs/fsdrv/lv_fsdrv.h @@ -19,6 +19,8 @@ extern "C" { * DEFINES *********************/ +#define LV_FS_MAX_PATH_LEN 256 + /********************** * TYPEDEFS **********************/ diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index 22c2c8b9f..5fdad3ebf 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -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 */