1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_misc/lv_ufs.h

211 lines
6.2 KiB
C
Raw Normal View History

2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* @file lv_ufs.h
2017-11-23 20:42:14 +01:00
* Implementation of RAM file system which do NOT support directories.
2017-11-24 17:48:47 +01:00
* The API is compatible with the lv_fs_int module.
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
#ifndef LV_UFS_H
#define LV_UFS_H
2017-11-23 20:42:14 +01:00
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../lv_conf.h"
#if USE_LV_FILESYSTEM
2017-11-23 20:42:14 +01:00
#include <stdbool.h>
#include "lv_fs.h"
#include "lv_mem.h"
/*********************
* DEFINES
*********************/
2017-11-26 11:38:28 +01:00
#define UFS_LETTER 'U'
2017-11-23 20:42:14 +01:00
/**********************
* TYPEDEFS
**********************/
/*Description of a file entry */
typedef struct
{
char * fn_d;
void * data_d;
uint32_t size; /*Data length in bytes*/
uint16_t oc; /*Open Count*/
uint8_t const_data :1;
2017-11-24 17:48:47 +01:00
}lv_ufs_ent_t;
2017-11-23 20:42:14 +01:00
/*File descriptor, used to handle opening an entry more times simultaneously
Contains unique informations about the specific opening*/
typedef struct
{
2017-11-24 17:48:47 +01:00
lv_ufs_ent_t* ent; /*Pointer to the entry*/
2017-11-23 20:42:14 +01:00
uint32_t rwp; /*Read Write Pointer*/
uint8_t ar :1; /*1: Access for read is enabled */
uint8_t aw :1; /*1: Access for write is enabled */
2017-11-24 17:48:47 +01:00
}lv_ufs_file_t;
2017-11-23 20:42:14 +01:00
/* Read directory descriptor.
* It is used to to iterate through the entries in a directory*/
typedef struct
{
2017-11-24 17:48:47 +01:00
lv_ufs_ent_t * last_ent;
}lv_ufs_dir_t;
2017-11-23 20:42:14 +01:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a driver for ufs and initialize it.
*/
2017-11-24 17:48:47 +01:00
void lv_ufs_init(void);
2017-11-23 20:42:14 +01:00
/**
* Give the state of the ufs
* @return true if ufs is initialized and can be used else false
*/
2017-11-24 17:48:47 +01:00
bool lv_ufs_ready(void);
2017-11-23 20:42:14 +01:00
/**
* Open a file in ufs
2017-11-24 17:48:47 +01:00
* @param file_p pointer to a lv_ufs_file_t variable
2017-11-23 20:42:14 +01:00
* @param fn name of the file. There are no directories so e.g. "myfile.txt"
* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is opened
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode);
2017-11-23 20:42:14 +01:00
/**
* Create a file with a constant data
* @param fn name of the file (directories are not supported)
* @param const_p pointer to a constant data
* @param len length of the data pointed by 'const_p' in bytes
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len);
2017-11-23 20:42:14 +01:00
/**
* Close an opened file
2017-11-24 17:48:47 +01:00
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_close (void * file_p);
2017-11-23 20:42:14 +01:00
/**
* Remove a file. The file can not be opened.
* @param fn '\0' terminated string
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is removed
* LV_FS_RES_DENIED: the file was opened, remove failed
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_remove(const char * fn);
2017-11-23 20:42:14 +01:00
/**
* Read data from an opened file
2017-11-24 17:48:47 +01:00
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
2017-11-23 20:42:14 +01:00
* @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)
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br);
2017-11-23 20:42:14 +01:00
/**
* Write data to an opened file
2017-11-24 17:48:47 +01:00
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
2017-11-23 20:42:14 +01:00
* @param buf pointer to a memory block which content will be written
* @param btw the number Bytes To Write
* @param bw The real number of written bytes (Byte Written)
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
2017-11-23 20:42:14 +01:00
/**
* Set the read write pointer. Also expand the file size if necessary.
2017-11-24 17:48:47 +01:00
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
2017-11-23 20:42:14 +01:00
* @param pos the new position of read write pointer
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos);
2017-11-23 20:42:14 +01:00
/**
* Give the position of the read write pointer
2017-11-24 17:48:47 +01:00
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
2017-11-23 20:42:14 +01:00
* @param pos_p pointer to to store the result
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p);
2017-11-23 20:42:14 +01:00
/**
* Truncate the file size to the current position of the read write pointer
2017-11-24 17:48:47 +01:00
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_trunc (void * file_p);
2017-11-23 20:42:14 +01:00
/**
* Give the size of the file in bytes
2017-11-24 17:48:47 +01:00
* @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
2017-11-23 20:42:14 +01:00
* @param size_p pointer to store the size
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK: no error, the file is read
2017-11-24 17:48:47 +01:00
* any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Initialize a lv_ufs_read_dir_t variable to directory reading
2017-11-23 20:42:14 +01:00
* @param rddir_p pointer to a 'ufs_read_dir_t' variable
* @param path uFS doesn't support folders so it has to be ""
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-12-03 22:32:09 +01:00
lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path);
2017-11-23 20:42:14 +01:00
/**
* Read the next file name
2017-11-24 17:48:47 +01:00
* @param dir_p pointer to an initialized 'ufs_read_dir_t' variable
2017-11-23 20:42:14 +01:00
* @param fn pointer to buffer to sore the file name
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-12-03 22:32:09 +01:00
lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn);
2017-11-23 20:42:14 +01:00
/**
* Close the directory reading
* @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
2017-11-23 20:42:14 +01:00
*/
2017-12-03 22:32:09 +01:00
lv_fs_res_t lv_ufs_dir_close(void * rddir_p);
2017-11-23 20:42:14 +01:00
/**
* Give the size of a drive
* @param total_p pointer to store the total size [kB]
* @param free_p pointer to store the free site [kB]
2017-12-03 22:32:09 +01:00
* @return LV_FS_RES_OK or any error from 'fs_res_t'
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p);
2017-11-23 20:42:14 +01:00
/**********************
* MACROS
**********************/
#endif /*USE_LV_FILESYSTEM*/
2017-11-23 20:42:14 +01:00
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif