mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-23 03:06:42 +00:00
Update lv_fs_if library
This commit is contained in:
parent
522938417c
commit
518914a714
@ -76,6 +76,10 @@ typedef int16_t lv_coord_t;
|
||||
/* LittelvGL's internal memory manager's settings.
|
||||
* The graphical objects and other related data are stored here. */
|
||||
|
||||
//#define LV_FS_SEEK(x, y) lv_fs_seek(x, y, LV_FS_SEEK_SET)
|
||||
#define LV_FS_SEEK(x, y) lv_fs_seek(x, y)
|
||||
#define _lv_img_decoder_t _lv_img_decoder
|
||||
|
||||
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
|
||||
#define LV_MEM_CUSTOM 0
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
@ -211,6 +215,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*/
|
||||
#define LV_FS_PC_PATH "/littlefs"
|
||||
|
||||
#endif
|
||||
|
||||
|
17
lib/lv_fs_if/.github/stale.yml
vendored
Normal file
17
lib/lv_fs_if/.github/stale.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 21
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 7
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- architecture
|
||||
- pinned
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue or pull request has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
52
lib/lv_fs_if/.gitignore
vendored
Normal file
52
lib/lv_fs_if/.gitignore
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
@ -1,9 +1,8 @@
|
||||
# File System Interface
|
||||
|
||||
LittlevGL has a [File system](https://docs.littlevgl.com/en/html/overview/file-system.html) module to attach memories which can manipulate with files. Here you can find interfaces to
|
||||
LittlevGL has a [File system](https://docs.lvgl.io/latest/en/html/overview/file-system.html) module to attach memories which can manipulate with files. Here you can find interfaces to
|
||||
- FATFS
|
||||
- PC (Linux and Windows)
|
||||
- SPIFFS (ESP32 and ESP8266)
|
||||
file systems.
|
||||
|
||||
You still need to provide the drivers and libraries, this repo gives "only" the bridge between FATFS/PC/etc and LittlevGL.
|
||||
@ -16,10 +15,9 @@ You still need to provide the drivers and libraries, this repo gives "only" the
|
||||
#if LV_USE_FS_IF
|
||||
# define LV_FS_IF_FATFS '\0'
|
||||
# define LV_FS_IF_PC '\0'
|
||||
# define LV_FS_IF_SPIFFS 'F'
|
||||
#endif /*LV_USE_FS_IF*/
|
||||
```
|
||||
|
||||
2. Enable an interface you need by changing `'\0'` to letter you want to use for that drive. E.g. `'S'` for SD card with FATFS.
|
||||
|
||||
3. Call `lv_fs_if_init()` to register the enabled interfaces.
|
||||
3. Call `lv_fs_if_init()` (after `lv_init()`) to register the enabled interfaces.
|
||||
|
4
lib/lv_fs_if/library.json
Normal file
4
lib/lv_fs_if/library.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "lv_fs_if",
|
||||
"version": "0.0.0+20220202035348"
|
||||
}
|
@ -70,7 +70,7 @@ void lv_fs_if_fatfs_init(void)
|
||||
*--------------------------------------------------*/
|
||||
|
||||
/* Add a simple drive to open images */
|
||||
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
|
||||
lv_fs_drv_t fs_drv; /*A driver descriptor*/
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
/*Set up fields...*/
|
||||
@ -119,12 +119,9 @@ static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_
|
||||
{
|
||||
uint8_t flags = 0;
|
||||
|
||||
if(mode == LV_FS_MODE_WR)
|
||||
flags = FA_WRITE | FA_OPEN_ALWAYS;
|
||||
else if(mode == LV_FS_MODE_RD)
|
||||
flags = FA_READ;
|
||||
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
|
||||
flags = FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
|
||||
if(mode == LV_FS_MODE_WR) flags = FA_WRITE | FA_OPEN_ALWAYS;
|
||||
else if(mode == LV_FS_MODE_RD) flags = FA_READ;
|
||||
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
|
||||
|
||||
FRESULT res = f_open(file_p, path, flags);
|
||||
|
||||
@ -136,6 +133,7 @@ static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close an opened file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
@ -162,10 +160,8 @@ static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p)
|
||||
static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
|
||||
{
|
||||
FRESULT res = f_read(file_p, buf, btr, (UINT*)br);
|
||||
if(res == FR_OK)
|
||||
return LV_FS_RES_OK;
|
||||
else
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
if(res == FR_OK) return LV_FS_RES_OK;
|
||||
else return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,10 +176,8 @@ static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t b
|
||||
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
|
||||
{
|
||||
FRESULT res = f_write(file_p, buf, btw, (UINT*)bw);
|
||||
if(res == FR_OK)
|
||||
return LV_FS_RES_OK;
|
||||
else
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
if(res == FR_OK) return LV_FS_RES_OK;
|
||||
else return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,10 +262,8 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char*
|
||||
|
||||
FRESULT res = f_rename(oldname, newname);
|
||||
|
||||
if(res == FR_OK)
|
||||
return LV_FS_RES_OK;
|
||||
else
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
if(res == FR_OK) return LV_FS_RES_OK;
|
||||
else return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,10 +293,8 @@ static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p
|
||||
static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *path)
|
||||
{
|
||||
FRESULT res = f_opendir(dir_p, path);
|
||||
if(res == FR_OK)
|
||||
return LV_FS_RES_OK;
|
||||
else
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
if(res == FR_OK) return LV_FS_RES_OK;
|
||||
else return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -328,8 +318,8 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn)
|
||||
if(fno.fattrib & AM_DIR) {
|
||||
fn[0] = '/';
|
||||
strcpy(&fn[1], fno.fname);
|
||||
} else
|
||||
strcpy(fn, fno.fname);
|
||||
}
|
||||
else strcpy(fn, fno.fname);
|
||||
|
||||
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
|
||||
|
||||
|
@ -29,10 +29,6 @@ void lv_fs_if_fatfs_init(void);
|
||||
void lv_fs_if_pc_init(void);
|
||||
#endif
|
||||
|
||||
#if LV_FS_IF_SPIFFS != '\0'
|
||||
#include "lv_fs_spiffs.h"
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
@ -58,9 +54,6 @@ void lv_fs_if_init(void)
|
||||
lv_fs_if_pc_init();
|
||||
#endif
|
||||
|
||||
#if LV_FS_IF_SPIFFS != '\0'
|
||||
lv_fs_if_spiffs_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
@ -45,3 +45,4 @@ void lv_fs_if_init(void);
|
||||
#endif
|
||||
|
||||
#endif /*LV_FS_IF_H*/
|
||||
|
||||
|
@ -12,10 +12,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#if !defined(ARDUINO_ARCH_ESP8266) && !defined(STM32F4xx) && !defined(STM32F7xx)
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
@ -24,12 +22,10 @@
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef LV_FS_PC_PATH
|
||||
#if defined(ESP32)
|
||||
#define LV_FS_PC_PATH "/littlefs" /*Projet root*/
|
||||
#elif defined(WIN32)
|
||||
#ifndef WIN32
|
||||
#define LV_FS_PC_PATH "./" /*Projet root*/
|
||||
#else
|
||||
#define LV_FS_PC_PATH "" /*Projet root*/
|
||||
#define LV_FS_PC_PATH ".\\" /*Projet root*/
|
||||
#endif
|
||||
#endif /*LV_FS_PATH*/
|
||||
|
||||
@ -41,12 +37,10 @@
|
||||
typedef FILE* file_t;
|
||||
|
||||
/*Similarly to `file_t` create a type for directory reading too */
|
||||
#if defined(WIN32)
|
||||
typedef HANDLE dir_t;
|
||||
#elif defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx)
|
||||
typedef FILE* dir_t;
|
||||
#else
|
||||
#ifndef WIN32
|
||||
typedef DIR* dir_t;
|
||||
#else
|
||||
typedef HANDLE dir_t;
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
@ -89,7 +83,7 @@ void lv_fs_if_pc_init(void)
|
||||
*--------------------------------------------------*/
|
||||
|
||||
/* Add a simple drive to open images */
|
||||
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
|
||||
lv_fs_drv_t fs_drv; /*A driver descriptor*/
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
/*Set up fields...*/
|
||||
@ -113,6 +107,11 @@ void lv_fs_if_pc_init(void)
|
||||
fs_drv.dir_read_cb = fs_dir_read;
|
||||
|
||||
lv_fs_drv_register(&fs_drv);
|
||||
|
||||
// char cur_path[512] = "";
|
||||
// getcwd(cur_path, sizeof(cur_path));
|
||||
LV_LOG_USER("LV_FS_PC is initialized with.");
|
||||
// LV_LOG_USER("The following path is considered as root directory:\n%s", cur_path);
|
||||
}
|
||||
|
||||
/**********************
|
||||
@ -150,13 +149,10 @@ static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_
|
||||
char buf[256];
|
||||
sprintf(buf, LV_FS_PC_PATH "\\%s", path);
|
||||
#endif
|
||||
// printf("Opening file: %s (%s)\n", buf, path);
|
||||
|
||||
file_t f = fopen(buf, flags);
|
||||
if(f == NULL) {
|
||||
// printf("Failed to open %s\n", buf);
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
if(f == NULL) return LV_FS_RES_UNKNOWN;
|
||||
|
||||
/*Be sure we are the beginning of the file*/
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
@ -231,7 +227,6 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos)
|
||||
(void)drv; /*Unused*/
|
||||
file_t* fp = file_p; /*Just avoid the confusing casings*/
|
||||
fseek(*fp, pos, SEEK_SET);
|
||||
// printf("Seek size: %u\n", pos);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
@ -251,7 +246,6 @@ static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p)
|
||||
|
||||
fseek(*fp, 0L, SEEK_END);
|
||||
*size_p = ftell(*fp);
|
||||
// printf("File size: %u\n", *size_p);
|
||||
|
||||
/*Restore file pointer*/
|
||||
fseek(*fp, cur, SEEK_SET);
|
||||
@ -304,8 +298,6 @@ static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p)
|
||||
|
||||
fflush(*fp); /*If not syncronized fclose can write the truncated part*/
|
||||
uint32_t p = ftell(*fp);
|
||||
(void)p; // unused
|
||||
|
||||
// ftruncate(fileno(*fp), p);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
@ -326,14 +318,12 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char*
|
||||
sprintf(old, LV_FS_PC_PATH "/%s", oldname);
|
||||
sprintf(new, LV_FS_PC_PATH "/%s", newname);
|
||||
|
||||
int r = rename(old, new);
|
||||
|
||||
if(r == 0)
|
||||
return LV_FS_RES_OK;
|
||||
else
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
|
||||
// int r = rename(old, new);
|
||||
|
||||
// if(r == 0)
|
||||
// return LV_FS_RES_OK;
|
||||
// else
|
||||
// return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -369,10 +359,7 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
dir_t d;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx)
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
|
||||
#elif !defined(WIN32)
|
||||
#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);
|
||||
@ -429,13 +416,12 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn)
|
||||
(void)drv; /*Unused*/
|
||||
dir_t* dp = dir_p; /*Just avoid the confusing casings*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifndef WIN32
|
||||
struct dirent* entry;
|
||||
do {
|
||||
entry = readdir(*dp);
|
||||
|
||||
if(entry) {
|
||||
|
||||
if(entry->d_type == DT_DIR)
|
||||
sprintf(fn, "/%s", entry->d_name);
|
||||
else
|
||||
@ -444,9 +430,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn)
|
||||
strcpy(fn, "");
|
||||
}
|
||||
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#else
|
||||
strcpy(fn, next_fn);
|
||||
|
||||
strcpy(next_fn, "");
|
||||
@ -481,10 +465,7 @@ static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
dir_t* dp = dir_p;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(STM32F4xx)
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
|
||||
#elif !defined(WIN32)
|
||||
#ifndef WIN32
|
||||
closedir(*dp);
|
||||
#else
|
||||
FindClose(*dp);
|
||||
|
@ -1,494 +0,0 @@
|
||||
/**
|
||||
* @file lv_fs_spiffs.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#if 0 &&defined(ARDUINO)
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "lv_fs_if.h"
|
||||
#include "lv_fs_spiffs.h"
|
||||
#include "ArduinoLog.h"
|
||||
|
||||
#if LV_USE_FS_IF
|
||||
#if LV_FS_IF_SPIFFS != '\0'
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#if HASP_USE_SPIFFS > 0
|
||||
#include "SPIFFS.h"
|
||||
#define LV_FS_SPIFFS SPIFFS
|
||||
#elif HASP_USE_LITTLEFS > 0
|
||||
|
||||
#ifndef ESP_ARDUINO_VERSION_VAL
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
|
||||
#endif
|
||||
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
|
||||
#include <LittleFS.h>
|
||||
#define LV_FS_SPIFFS LittleFS
|
||||
#else
|
||||
#include "LITTLEFS.h"
|
||||
#include "esp_littlefs.h"
|
||||
#define LV_FS_SPIFFS LITTLEFS
|
||||
#endif // ESP_ARDUINO_VERSION
|
||||
|
||||
#endif
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#include "LittleFS.h"
|
||||
#define LV_FS_SPIFFS LittleFS
|
||||
#endif // ARDUINO_ARCH
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
#include <FS.h>
|
||||
#include <Esp.h>
|
||||
#endif // ARDUINO_ARCH
|
||||
|
||||
#define TAG_LVFS 91
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/* Create a type to store the required data about your file.*/
|
||||
typedef FILE* lv_spiffs_file_t;
|
||||
|
||||
/*Similarly to `file_t` create a type for directory reading too */
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
typedef FILE* lv_spiffs_dir_t;
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
typedef Dir* lv_spiffs_dir_t;
|
||||
#define FILE_READ "r"
|
||||
#define FILE_WRITE "r+"
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void fs_init(void);
|
||||
|
||||
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode);
|
||||
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p);
|
||||
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br);
|
||||
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw);
|
||||
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos);
|
||||
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p);
|
||||
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p);
|
||||
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path);
|
||||
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p);
|
||||
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname);
|
||||
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p);
|
||||
static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path);
|
||||
static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn);
|
||||
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void lv_fs_if_spiffs_init(void)
|
||||
{
|
||||
/*----------------------------------------------------
|
||||
* Initialize your storage device and File System
|
||||
* -------------------------------------------------*/
|
||||
Log.verbose(88, "File system init start");
|
||||
fs_init();
|
||||
|
||||
/*---------------------------------------------------
|
||||
* Register the file system interface in LittlevGL
|
||||
*--------------------------------------------------*/
|
||||
|
||||
/* Add a simple drive to open images */
|
||||
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
/*Set up fields...*/
|
||||
fs_drv.file_size = sizeof(lv_spiffs_file_t);
|
||||
fs_drv.letter = LV_FS_IF_SPIFFS;
|
||||
fs_drv.open_cb = fs_open;
|
||||
fs_drv.close_cb = fs_close;
|
||||
fs_drv.read_cb = fs_read;
|
||||
fs_drv.write_cb = fs_write;
|
||||
fs_drv.seek_cb = fs_seek;
|
||||
fs_drv.tell_cb = fs_tell;
|
||||
fs_drv.free_space_cb = fs_free;
|
||||
fs_drv.size_cb = fs_size;
|
||||
// fs_drv.remove_cb = fs_remove;
|
||||
// fs_drv.rename_cb = fs_rename;
|
||||
// fs_drv.trunc_cb = fs_trunc;
|
||||
|
||||
// fs_drv.rddir_size = sizeof(lv_spiffs_dir_t);
|
||||
// fs_drv.dir_close_cb = fs_dir_close;
|
||||
// fs_drv.dir_open_cb = fs_dir_open;
|
||||
// fs_drv.dir_read_cb = fs_dir_read;
|
||||
|
||||
lv_fs_drv_register(&fs_drv);
|
||||
Log.verbose(88, "File system init complete");
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/* Initialize your Storage device and File system. */
|
||||
static void fs_init(void)
|
||||
{
|
||||
esp_vfs_littlefs_conf_t conf = {.base_path = "/lfs", .partition_label = "spiffs", .format_if_mount_failed = false};
|
||||
|
||||
esp_err_t res = esp_vfs_littlefs_register(&conf);
|
||||
|
||||
if(res != ESP_OK) {
|
||||
if(res == ESP_FAIL) {
|
||||
Log.error(88, "Failed to mount or format filesystem");
|
||||
} else if(res == ESP_ERR_NOT_FOUND) {
|
||||
Log.error(88, "Failed to find LittleFS partition");
|
||||
} else {
|
||||
Log.error(88, "Failed to initialize LittleFS (%s)", esp_err_to_name(res));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
size_t total = 0, used = 0;
|
||||
res = esp_littlefs_info(conf.partition_label, &total, &used);
|
||||
if(res != ESP_OK) {
|
||||
Log.error(88, "Failed to get LittleFS partition information (%s)", esp_err_to_name(res));
|
||||
} else {
|
||||
Log.verbose(88, "Partition size: total: %d, used: %d", total, used);
|
||||
}
|
||||
|
||||
// Use POSIX and C standard library functions to work with files.
|
||||
// First create a file.
|
||||
Log.verbose(88, "Opening file /lfs/hello.txt");
|
||||
FILE* f = fopen("/lfs/hello.txt", "w");
|
||||
if(f == NULL) {
|
||||
Log.error(88, "Failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
fprintf(f, "LittleFS Rocks!\n");
|
||||
fclose(f);
|
||||
Log.verbose(88, "File written");
|
||||
|
||||
Log.verbose(88, "LittleFS init OK");
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable
|
||||
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
|
||||
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_open(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
|
||||
const char* flags = "";
|
||||
|
||||
if(mode == LV_FS_MODE_WR)
|
||||
flags = "w";
|
||||
else if(mode == LV_FS_MODE_RD)
|
||||
flags = "r";
|
||||
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
|
||||
flags = "rb+";
|
||||
|
||||
/*Make the path relative to the current directory (the projects root folder)*/
|
||||
|
||||
char complete_path[strlen(path) + 1];
|
||||
complete_path[0] = '/';
|
||||
complete_path[1] = '\0';
|
||||
strcat(complete_path, path);
|
||||
|
||||
Log.verbose(88, "Opening file %s", path);
|
||||
lv_spiffs_file_t f = fopen(path, flags);
|
||||
if(f == NULL) return LV_FS_RES_UNKNOWN;
|
||||
|
||||
/*Be sure we are the beginning of the file*/
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
/* 'file_p' is pointer to a file descriptor and
|
||||
* we need to store our file descriptor here*/
|
||||
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; /*Just avoid the confusing casings*/
|
||||
*fp = f;
|
||||
Log.verbose(88, "Open eof file_p %d", feof(*fp));
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an opened file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable. (opened with lv_ufs_open)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_close(lv_fs_drv_t* drv, void* file_p)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; /*Just avoid the confusing casings*/
|
||||
fclose(*fp);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from an opened file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable.
|
||||
* @param buf pointer to a memory block where to store the read data
|
||||
* @param btr number of Bytes To Read
|
||||
* @param br the real number of read bytes (Byte Read)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_read(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; /*Just avoid the confusing casings*/
|
||||
Log.verbose(88, "Read eof %d", feof(*fp));
|
||||
*br = fread(buf, 1, btr, *fp);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into a file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable
|
||||
* @param buf pointer to a buffer with the bytes to write
|
||||
* @param btr Bytes To Write
|
||||
* @param br the number of real written bytes (Bytes Written). NULL if unused.
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_write(lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; /*Just avoid the confusing casings*/
|
||||
Log.verbose(88, "Write eof %d", feof(*fp));
|
||||
*bw = fwrite(buf, 1, btw, *fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the read write pointer. Also expand the file size if necessary.
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable. (opened with lv_ufs_open )
|
||||
* @param pos the new position of read write pointer
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_seek(lv_fs_drv_t* drv, void* file_p, uint32_t pos)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; /*Just avoid the confusing casings*/
|
||||
fseek(*fp, pos, SEEK_SET);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the size of a file bytes
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable
|
||||
* @param size pointer to a variable to store the size
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_size(lv_fs_drv_t* drv, void* file_p, uint32_t* size_p)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; /*Just avoid the confusing casings*/
|
||||
fseek(*fp, 0L, SEEK_END);
|
||||
*size_p = ftell(*fp);
|
||||
fseek(*fp, 0L, SEEK_SET);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the position of the read write pointer
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable.
|
||||
* @param pos_p pointer to to store the result
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_tell(lv_fs_drv_t* drv, void* file_p, uint32_t* pos_p)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
lv_spiffs_file_t* fp = (lv_spiffs_file_t*)file_p; /*Just avoid the confusing casings*/
|
||||
*pos_p = ftell(*fp);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param path path of the file to delete
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_remove(lv_fs_drv_t* drv, const char* path)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
|
||||
char filename[32];
|
||||
snprintf_P(filename, sizeof(filename), PSTR("/%s"), path);
|
||||
|
||||
if(!LV_FS_SPIFFS.exists(filename)) {
|
||||
return LV_FS_RES_NOT_EX;
|
||||
|
||||
} else if(LV_FS_SPIFFS.remove(filename)) {
|
||||
return LV_FS_RES_OK;
|
||||
|
||||
} else {
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the file size to the current position of the read write pointer
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open )
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_trunc(lv_fs_drv_t* drv, void* file_p)
|
||||
{
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param oldname path to the file
|
||||
* @param newname path with the new name
|
||||
* @return LV_FS_RES_OK or any error from 'fs_res_t'
|
||||
*/
|
||||
static lv_fs_res_t fs_rename(lv_fs_drv_t* drv, const char* oldname, const char* newname)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
char fromname[32];
|
||||
char toname[32];
|
||||
|
||||
snprintf_P(fromname, sizeof(fromname), PSTR("/%s"), oldname);
|
||||
snprintf_P(toname, sizeof(toname), PSTR("/%s"), newname);
|
||||
|
||||
if(LV_FS_SPIFFS.rename(fromname, toname)) {
|
||||
return LV_FS_RES_OK;
|
||||
} else {
|
||||
return LV_FS_RES_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the free and total size of a driver in kB
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param letter the driver letter
|
||||
* @param total_p pointer to store the total size [kB]
|
||||
* @param free_p pointer to store the free size [kB]
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_free(lv_fs_drv_t* drv, uint32_t* total_p, uint32_t* free_p)
|
||||
{
|
||||
(void)drv; /*Unused*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
FSInfo fs_info;
|
||||
LV_FS_SPIFFS.info(fs_info);
|
||||
*total_p = (uint32_t)fs_info.totalBytes;
|
||||
*free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes;
|
||||
return LV_FS_RES_OK;
|
||||
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
*total_p = (uint32_t)LV_FS_SPIFFS.totalBytes();
|
||||
*free_p = (uint32_t)LV_FS_SPIFFS.totalBytes() - LV_FS_SPIFFS.usedBytes();
|
||||
return LV_FS_RES_OK;
|
||||
|
||||
#endif
|
||||
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a 'fs_read_dir_t' variable for directory reading
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param dir_p pointer to a 'fs_read_dir_t' variable
|
||||
* @param path path to a directory
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
// static lv_fs_res_t fs_dir_open(lv_fs_drv_t* drv, void* dir_p, const char* path)
|
||||
// {
|
||||
// lv_spiffs_dir_t dir;
|
||||
|
||||
// #if defined(ARDUINO_ARCH_ESP32)
|
||||
// dir = &LV_FS_SPIFFS.open(path);
|
||||
// if(!dir) {
|
||||
// return LV_FS_RES_UNKNOWN;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
// #if defined(ARDUINO_ARCH_ESP8266)
|
||||
// dir = LV_FS_SPIFFS.openDir(path);
|
||||
// #endif
|
||||
|
||||
// lv_spiffs_dir_t* dp = (lv_spiffs_dir_t*)dir_p; /*Just avoid the confusing casings*/
|
||||
// *dp = dir;
|
||||
// return LV_FS_RES_OK;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Read the next filename form a directory.
|
||||
* The name of the directories will begin with '/'
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param dir_p pointer to an initialized 'fs_read_dir_t' variable
|
||||
* @param fn pointer to a buffer to store the filename
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
// static lv_fs_res_t fs_dir_read(lv_fs_drv_t* drv, void* dir_p, char* fn)
|
||||
// {
|
||||
// lv_spiffs_dir_t dir = *(lv_spiffs_dir_t*)dir_p; /*Convert type*/
|
||||
|
||||
// #if defined(ARDUINO_ARCH_ESP32)
|
||||
// File file = dir.openNextFile();
|
||||
// if(file) {
|
||||
// strcpy(fn, file.name());
|
||||
// return LV_FS_RES_OK;
|
||||
// } else {
|
||||
// return LV_FS_RES_UNKNOWN;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
// #if defined(ARDUINO_ARCH_ESP8266)
|
||||
// if(dir.next()) {
|
||||
// strcpy(fn, dir.fileName().c_str());
|
||||
// return LV_FS_RES_OK;
|
||||
// } else {
|
||||
// return LV_FS_RES_UNKNOWN;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
// return LV_FS_RES_NOT_IMP;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Close the directory reading
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param dir_p pointer to an initialized 'fs_read_dir_t' variable
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_dir_close(lv_fs_drv_t* drv, void* dir_p)
|
||||
{
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
#endif /*LV_USE_FS_IF*/
|
||||
#endif /*LV_FS_IF_SPIFFS*/
|
||||
|
||||
#endif /*ARDUINO*/
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
* @file lv_fs_if.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_FS_IF_SPIFFS_H
|
||||
#define LV_FS_IF_SPIFFS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void lv_fs_if_spiffs_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
@ -127,7 +127,7 @@ int lv_ft_fseek(lv_ft_stream_t* stream, long int offset, int origin)
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
lv_fs_res_t res = lv_fs_seek(f_ptr, start + offset);
|
||||
lv_fs_res_t res = LV_FS_SEEK(f_ptr, start + offset);
|
||||
return res == LV_FS_RES_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ static int read_bits_signed(bit_iterator_t* it, int n_bits, lv_fs_res_t* res)
|
||||
|
||||
static int read_label(lv_fs_file_t* fp, int start, const char* label)
|
||||
{
|
||||
lv_fs_seek(fp, start);
|
||||
LV_FS_SEEK(fp, start);
|
||||
|
||||
uint32_t length;
|
||||
char buf[4];
|
||||
@ -245,7 +245,7 @@ static bool load_cmaps_tables(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc,
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < font_dsc->cmap_num; ++i) {
|
||||
lv_fs_res_t res = lv_fs_seek(fp, cmaps_start + cmap_table[i].data_offset);
|
||||
lv_fs_res_t res =LV_FS_SEEK(fp, cmaps_start + cmap_table[i].data_offset);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
@ -353,7 +353,7 @@ static int32_t load_glyph(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uin
|
||||
for(unsigned int i = 0; i < loca_count; ++i) {
|
||||
lv_font_fmt_txt_glyph_dsc_t* gdsc = &glyph_dsc[i];
|
||||
|
||||
lv_fs_res_t res = lv_fs_seek(fp, start + glyph_offset[i]);
|
||||
lv_fs_res_t res =LV_FS_SEEK(fp, start + glyph_offset[i]);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -419,7 +419,7 @@ static int32_t load_glyph(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uin
|
||||
cur_bmp_size = 0;
|
||||
|
||||
for(unsigned int i = 1; i < loca_count; ++i) {
|
||||
lv_fs_res_t res = lv_fs_seek(fp, start + glyph_offset[i]);
|
||||
lv_fs_res_t res =LV_FS_SEEK(fp, start + glyph_offset[i]);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user