Prepare LVFS support for /sdcard

This commit is contained in:
fvanroie 2024-05-24 21:58:15 +02:00
parent d903bc905f
commit f175dc599a
5 changed files with 28 additions and 26 deletions

View File

@ -211,7 +211,7 @@ typedef void* lv_group_user_data_t;
#define LV_USE_FILESYSTEM 1
#if LV_USE_FILESYSTEM
/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/
typedef void* lv_fs_drv_user_data_t;
typedef const char* lv_fs_drv_user_data_t;
/*File system interface*/
#ifndef LV_USE_FS_IF
@ -229,7 +229,7 @@ typedef void* lv_fs_drv_user_data_t;
//# define LV_FS_IF_SPIFFS '\0' // no internal esp Flash
#endif
#endif /*LV_USE_FS_IF*/
#if HASP_TARGET_ARDUINO
#if HASP_TARGET_ARDUINO && !defined(LV_FS_PC_PATH)
#define LV_FS_PC_PATH "/littlefs"
#endif

View File

@ -14,6 +14,13 @@
/*********************
* DEFINES
*********************/
#ifndef LV_FS_PC_PATH
#ifndef WIN32
#define LV_FS_PC_PATH "./" /*Project root*/
#else
#define LV_FS_PC_PATH ".\\" /*Project root*/
#endif
#endif /*LV_FS_PATH*/
/**********************
* TYPEDEFS
@ -26,8 +33,8 @@
void lv_fs_if_fatfs_init(void);
#endif
#if LV_FS_IF_PC != '\0'
void lv_fs_if_pc_init(void);
#if LV_FS_IF_PC != '\0' || LV_FS_IF_SD != '\0'
void lv_fs_if_pc_init(char letter, const char* path);
#endif
/**********************
@ -52,9 +59,12 @@ void lv_fs_if_init(void)
#endif
#if LV_FS_IF_PC != '\0'
lv_fs_if_pc_init();
lv_fs_if_pc_init(LV_FS_IF_PC, LV_FS_PC_PATH);
#endif
#if LV_FS_IF_SD != '\0'
lv_fs_if_pc_init(LV_FS_IF_SD, LV_FS_SD_PATH);
#endif
}
/**********************

View File

@ -19,17 +19,6 @@
#include <windows.h>
#endif
/*********************
* DEFINES
*********************/
#ifndef LV_FS_PC_PATH
#ifndef WIN32
#define LV_FS_PC_PATH "./" /*Projet root*/
#else
#define LV_FS_PC_PATH ".\\" /*Projet root*/
#endif
#endif /*LV_FS_PATH*/
/**********************
* TYPEDEFS
**********************/
@ -77,7 +66,7 @@ static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p);
/**
* Register a driver for the File system interface
*/
void lv_fs_if_pc_init(void)
void lv_fs_if_pc_init(char letter, const char* path)
{
/*---------------------------------------------------
* Register the file system interface in LittlevGL
@ -107,6 +96,8 @@ void lv_fs_if_pc_init(void)
fs_drv.dir_open_cb = fs_dir_open;
fs_drv.dir_read_cb = fs_dir_read;
fs_drv.user_data = LV_FS_PC_PATH;
lv_fs_drv_register(&fs_drv);
// char cur_path[512] = "";
@ -145,10 +136,10 @@ static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_
#ifndef WIN32
char buf[256];
sprintf(buf, LV_FS_PC_PATH "/%s", path);
sprintf(buf, "%s/%s", drv->user_data, path);
#else
char buf[256];
sprintf(buf, LV_FS_PC_PATH "\\%s", path);
sprintf(buf, "%s\\%s", drv->user_data, path);
#endif
LV_LOG_USER(buf);
@ -255,6 +246,7 @@ static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p)
return LV_FS_RES_OK;
}
/**
* Give the position of the read write pointer
* @param drv pointer to a driver where this function belongs
@ -318,8 +310,8 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char*
static char new[512];
static char old[512];
sprintf(old, LV_FS_PC_PATH "/%s", oldname);
sprintf(new, LV_FS_PC_PATH "/%s", newname);
sprintf(old, "%s/%s", drv->user_data, oldname);
sprintf(new, "%s/%s", drv->user_data, newname);
int r = rename(old, new);
@ -365,7 +357,7 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path)
#ifndef WIN32
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
sprintf(buf, LV_FS_PC_PATH "/%s", path);
sprintf(buf, "%s/%s", drv->user_data, path);
if((d = opendir(buf)) == NULL) {
return LV_FS_RES_FS_ERR;
} else {
@ -380,7 +372,7 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path)
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
sprintf(buf, LV_FS_PC_PATH "\\%s\\*", path);
sprintf(buf, "%s\\%s\\*", drv->user_data, path);
strcpy(next_fn, "");
d = FindFirstFile(buf, &fdata);

View File

@ -45,7 +45,7 @@ build_flags =
-D LV_ATTRIBUTE_FAST_MEM=IRAM_ATTR
-D LV_ATTRIBUTE_TASK_HANDLER=IRAM_ATTR
-D LV_USE_FS_IF=1
;-D LV_FS_PC_PATH="//littlefs" ; this needs to match the vfs mount pount
-D LV_FS_PC_PATH='"/littlefs"' ; this needs to match the vfs mount pount
; -- ArduinoJson build options ----------------------------
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
; -- tft_espi build options ------------------------

View File

@ -15,7 +15,7 @@ build_flags =
-D LV_ATTRIBUTE_FAST_MEM=
-D LV_ATTRIBUTE_TASK_HANDLER=IRAM_ATTR
-D LV_USE_FS_IF=1
;-D LV_FS_PC_PATH="//littlefs" ; this needs to match the vfs mount pount
-D LV_FS_PC_PATH='"/littlefs"' ; this needs to match the vfs mount pount
; -- ArduinoJson build options ----------------------------
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
; -- tft_espi build options ------------------------