/**1* @file lv_fs.h2*3*/45#ifndef LV_FS_H6#define LV_FS_H78#ifdef __cplusplus9extern "C" {10#endif1112/*********************13* INCLUDES14*********************/15#ifdef LV_CONF_INCLUDE_SIMPLE16#include "lv_conf.h"17#else18#include "../../lv_conf.h"19#endif2021#if USE_LV_FILESYSTEM2223#include <stdint.h>24#include "lv_mem.h"2526/*********************27* DEFINES28*********************/29#define LV_FS_MAX_FN_LENGTH 643031/**********************32* TYPEDEFS33**********************/34enum35{36LV_FS_RES_OK = 0,37LV_FS_RES_HW_ERR, /*Low level hardware error*/38LV_FS_RES_FS_ERR, /*Error in the file system structure */39LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/40LV_FS_RES_FULL, /*Disk full*/41LV_FS_RES_LOCKED, /*The file is already opened*/42LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/43LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/44LV_FS_RES_TOUT, /*Process time outed*/45LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/46LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/47LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/48LV_FS_RES_UNKNOWN, /*Other unknown error*/49};50typedef uint8_t lv_fs_res_t;5152struct __lv_fs_drv_t;5354typedef struct55{56void * file_d;57struct __lv_fs_drv_t* drv;58} lv_fs_file_t;596061typedef struct62{63void * dir_d;64struct __lv_fs_drv_t * drv;65} lv_fs_dir_t;6667enum68{69LV_FS_MODE_WR = 0x01,70LV_FS_MODE_RD = 0x02,71};72typedef uint8_t lv_fs_mode_t;7374typedef struct __lv_fs_drv_t75{76char letter;77uint16_t file_size;78uint16_t rddir_size;79bool (*ready) (void);8081lv_fs_res_t (*open) (void * file_p, const char * path, lv_fs_mode_t mode);82lv_fs_res_t (*close) (void * file_p);83lv_fs_res_t (*remove) (const char * fn);84lv_fs_res_t (*read) (void * file_p, void * buf, uint32_t btr, uint32_t * br);85lv_fs_res_t (*write) (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);86lv_fs_res_t (*seek) (void * file_p, uint32_t pos);87lv_fs_res_t (*tell) (void * file_p, uint32_t * pos_p);88lv_fs_res_t (*trunc) (void * file_p);89lv_fs_res_t (*size) (void * file_p, uint32_t * size_p);90lv_fs_res_t (*rename) (const char * oldname, const char * newname);91lv_fs_res_t (*free) (uint32_t * total_p, uint32_t * free_p);9293lv_fs_res_t (*dir_open) (void * rddir_p, const char * path);94lv_fs_res_t (*dir_read) (void * rddir_p, char * fn);95lv_fs_res_t (*dir_close) (void * rddir_p);96} lv_fs_drv_t;9798/**********************99* GLOBAL PROTOTYPES100**********************/101102/**103* Initialize the File system interface104*/105void lv_fs_init(void);106107/**108* Add a new drive109* @param drv_p pointer to an lv_fs_drv_t structure which is inited with the110* corresponding function pointers. The data will be copied so the variable can be local.111*/112void lv_fs_add_drv(lv_fs_drv_t * drv_p);113114/**115* Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned.116* @param letter letter of the drive117* @return true: drive is ready; false: drive is not ready118*/119bool lv_fs_is_ready(char letter);120121/**122* Open a file123* @param file_p pointer to a lv_fs_file_t variable124* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)125* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR126* @return LV_FS_RES_OK or any error from lv_fs_res_t enum127*/128lv_fs_res_t lv_fs_open (lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode);129130/**131* Close an already opened file132* @param file_p pointer to a lv_fs_file_t variable133* @return LV_FS_RES_OK or any error from lv_fs_res_t enum134*/135lv_fs_res_t lv_fs_close (lv_fs_file_t * file_p);136137/**138* Delete a file139* @param path path of the file to delete140* @return LV_FS_RES_OK or any error from lv_fs_res_t enum141*/142lv_fs_res_t lv_fs_remove (const char * path);143144/**145* Read from a file146* @param file_p pointer to a lv_fs_file_t variable147* @param buf pointer to a buffer where the read bytes are stored148* @param btr Bytes To Read149* @param br the number of real read bytes (Bytes Read). NULL if unused.150* @return LV_FS_RES_OK or any error from lv_fs_res_t enum151*/152lv_fs_res_t lv_fs_read (lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br);153154/**155* Write into a file156* @param file_p pointer to a lv_fs_file_t variable157* @param buf pointer to a buffer with the bytes to write158* @param btr Bytes To Write159* @param br the number of real written bytes (Bytes Written). NULL if unused.160* @return LV_FS_RES_OK or any error from lv_fs_res_t enum161*/162lv_fs_res_t lv_fs_write (lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw);163164/**165* Set the position of the 'cursor' (read write pointer) in a file166* @param file_p pointer to a lv_fs_file_t variable167* @param pos the new position expressed in bytes index (0: start of file)168* @return LV_FS_RES_OK or any error from lv_fs_res_t enum169*/170lv_fs_res_t lv_fs_seek (lv_fs_file_t * file_p, uint32_t pos);171172/**173* Give the position of the read write pointer174* @param file_p pointer to a lv_fs_file_t variable175* @param pos_p pointer to store the position of the read write pointer176* @return LV_FS_RES_OK or any error from 'fs_res_t'177*/178lv_fs_res_t lv_fs_tell (lv_fs_file_t * file_p, uint32_t * pos);179180/**181* Truncate the file size to the current position of the read write pointer182* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open )183* @return LV_FS_RES_OK: no error, the file is read184* any error from lv_fs_res_t enum185*/186lv_fs_res_t lv_fs_trunc (lv_fs_file_t * file_p);187188/**189* Give the size of a file bytes190* @param file_p pointer to a lv_fs_file_t variable191* @param size pointer to a variable to store the size192* @return LV_FS_RES_OK or any error from lv_fs_res_t enum193*/194lv_fs_res_t lv_fs_size (lv_fs_file_t * file_p, uint32_t * size);195196/**197* Rename a file198* @param oldname path to the file199* @param newname path with the new name200* @return LV_FS_RES_OK or any error from 'fs_res_t'201*/202lv_fs_res_t lv_fs_rename (const char * oldname, const char * newname);203204/**205* Initialize a 'fs_dir_t' variable for directory reading206* @param rddir_p pointer to a 'fs_read_dir_t' variable207* @param path path to a directory208* @return LV_FS_RES_OK or any error from lv_fs_res_t enum209*/210lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path);211212/**213* Read the next filename form a directory.214* The name of the directories will begin with '/'215* @param rddir_p pointer to an initialized 'fs_rdir_t' variable216* @param fn pointer to a buffer to store the filename217* @return LV_FS_RES_OK or any error from lv_fs_res_t enum218*/219lv_fs_res_t lv_fs_dir_read (lv_fs_dir_t * rddir_p, char * fn);220221/**222* Close the directory reading223* @param rddir_p pointer to an initialized 'fs_dir_t' variable224* @return LV_FS_RES_OK or any error from lv_fs_res_t enum225*/226lv_fs_res_t lv_fs_dir_close (lv_fs_dir_t * rddir_p);227228/**229* Get the free and total size of a driver in kB230* @param letter the driver letter231* @param total_p pointer to store the total size [kB]232* @param free_p pointer to store the free size [kB]233* @return LV_FS_RES_OK or any error from lv_fs_res_t enum234*/235lv_fs_res_t lv_fs_free (char letter, uint32_t * total_p, uint32_t * free_p);236237/**238* Fill a buffer with the letters of existing drivers239* @param buf buffer to store the letters ('\0' added after the last letter)240* @return the buffer241*/242char * lv_fs_get_letters(char * buf);243244/**245* Return with the extension of the filename246* @param fn string with a filename247* @return pointer to the beginning extension or empty string if no extension248*/249const char * lv_fs_get_ext(const char * fn);250251/**252* Step up one level253* @param path pointer to a file name254* @return the truncated file name255*/256char * lv_fs_up(char * path);257258/**259* Get the last element of a path (e.g. U:/folder/file -> file)260* @param buf buffer to store the letters ('\0' added after the last letter)261* @return pointer to the beginning of the last element in the path262*/263const char * lv_fs_get_last(const char * path);264265/**********************266* MACROS267**********************/268269#endif /*USE_LV_FILESYSTEM*/270271#ifdef __cplusplus272} /* extern "C" */273#endif274275#endif /*LV_FS_H*/276277278