/**1* @file lv_ufs.h2* Implementation of RAM file system which do NOT support directories.3* The API is compatible with the lv_fs_int module.4*/56#ifndef LV_UFS_H7#define LV_UFS_H89#ifdef __cplusplus10extern "C" {11#endif121314/*********************15* INCLUDES16*********************/17#ifdef LV_CONF_INCLUDE_SIMPLE18#include "lv_conf.h"19#else20#include "../../lv_conf.h"21#endif2223#if USE_LV_FILESYSTEM2425#include "lv_fs.h"26#include "lv_mem.h"2728/*********************29* DEFINES30*********************/31#define UFS_LETTER 'U'3233/**********************34* TYPEDEFS35**********************/36/*Description of a file entry */37typedef struct38{39char * fn_d;40void * data_d;41uint32_t size; /*Data length in bytes*/42uint16_t oc; /*Open Count*/43uint8_t const_data :1;44} lv_ufs_ent_t;4546/*File descriptor, used to handle opening an entry more times simultaneously47Contains unique informations about the specific opening*/48typedef struct49{50lv_ufs_ent_t* ent; /*Pointer to the entry*/51uint32_t rwp; /*Read Write Pointer*/52uint8_t ar :1; /*1: Access for read is enabled */53uint8_t aw :1; /*1: Access for write is enabled */54} lv_ufs_file_t;5556/* Read directory descriptor.57* It is used to to iterate through the entries in a directory*/58typedef struct59{60lv_ufs_ent_t * last_ent;61} lv_ufs_dir_t;6263/**********************64* GLOBAL PROTOTYPES65**********************/6667/**68* Create a driver for ufs and initialize it.69*/70void lv_ufs_init(void);7172/**73* Give the state of the ufs74* @return true if ufs is initialized and can be used else false75*/76bool lv_ufs_ready(void);7778/**79* Open a file in ufs80* @param file_p pointer to a lv_ufs_file_t variable81* @param fn name of the file. There are no directories so e.g. "myfile.txt"82* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)83* @return LV_FS_RES_OK: no error, the file is opened84* any error from lv_fs_res_t enum85*/86lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode);8788/**89* Create a file with a constant data90* @param fn name of the file (directories are not supported)91* @param const_p pointer to a constant data92* @param len length of the data pointed by 'const_p' in bytes93* @return LV_FS_RES_OK: no error, the file is read94* any error from lv_fs_res_t enum95*/96lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len);9798/**99* Close an opened file100* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)101* @return LV_FS_RES_OK: no error, the file is read102* any error from lv_fs_res_t enum103*/104lv_fs_res_t lv_ufs_close (void * file_p);105106/**107* Remove a file. The file can not be opened.108* @param fn '\0' terminated string109* @return LV_FS_RES_OK: no error, the file is removed110* LV_FS_RES_DENIED: the file was opened, remove failed111*/112lv_fs_res_t lv_ufs_remove(const char * fn);113114/**115* Read data from an opened file116* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )117* @param buf pointer to a memory block where to store the read data118* @param btr number of Bytes To Read119* @param br the real number of read bytes (Byte Read)120* @return LV_FS_RES_OK: no error, the file is read121* any error from lv_fs_res_t enum122*/123lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br);124125/**126* Write data to an opened file127* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)128* @param buf pointer to a memory block which content will be written129* @param btw the number Bytes To Write130* @param bw The real number of written bytes (Byte Written)131* @return LV_FS_RES_OK: no error, the file is read132* any error from lv_fs_res_t enum133*/134lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);135136/**137* Set the read write pointer. Also expand the file size if necessary.138* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )139* @param pos the new position of read write pointer140* @return LV_FS_RES_OK: no error, the file is read141* any error from lv_fs_res_t enum142*/143lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos);144145/**146* Give the position of the read write pointer147* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )148* @param pos_p pointer to to store the result149* @return LV_FS_RES_OK: no error, the file is read150* any error from lv_fs_res_t enum151*/152lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p);153154/**155* Truncate the file size to the current position of the read write pointer156* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )157* @return LV_FS_RES_OK: no error, the file is read158* any error from lv_fs_res_t enum159*/160lv_fs_res_t lv_ufs_trunc (void * file_p);161162/**163* Give the size of the file in bytes164* @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )165* @param size_p pointer to store the size166* @return LV_FS_RES_OK: no error, the file is read167* any error from lv_fs_res_t enum168*/169lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p);170171/**172* Initialize a lv_ufs_read_dir_t variable to directory reading173* @param rddir_p pointer to a 'ufs_read_dir_t' variable174* @param path uFS doesn't support folders so it has to be ""175* @return LV_FS_RES_OK or any error from lv_fs_res_t enum176*/177lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path);178179/**180* Read the next file name181* @param dir_p pointer to an initialized 'ufs_read_dir_t' variable182* @param fn pointer to buffer to sore the file name183* @return LV_FS_RES_OK or any error from lv_fs_res_t enum184*/185lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn);186187/**188* Close the directory reading189* @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable190* @return LV_FS_RES_OK or any error from lv_fs_res_t enum191*/192lv_fs_res_t lv_ufs_dir_close(void * rddir_p);193194/**195* Give the size of a drive196* @param total_p pointer to store the total size [kB]197* @param free_p pointer to store the free site [kB]198* @return LV_FS_RES_OK or any error from 'fs_res_t'199*/200lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p);201202/**********************203* MACROS204**********************/205206#endif /*USE_LV_FILESYSTEM*/207208#ifdef __cplusplus209} /* extern "C" */210#endif211212#endif213214215