Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_misc/lv_fs.h
1476 views
1
/**
2
* @file lv_fs.h
3
*
4
*/
5
6
#ifndef LV_FS_H
7
#define LV_FS_H
8
9
#ifdef __cplusplus
10
extern "C" {
11
#endif
12
13
/*********************
14
* INCLUDES
15
*********************/
16
#ifdef LV_CONF_INCLUDE_SIMPLE
17
#include "lv_conf.h"
18
#else
19
#include "../../lv_conf.h"
20
#endif
21
22
#if USE_LV_FILESYSTEM
23
24
#include <stdint.h>
25
#include "lv_mem.h"
26
27
/*********************
28
* DEFINES
29
*********************/
30
#define LV_FS_MAX_FN_LENGTH 64
31
32
/**********************
33
* TYPEDEFS
34
**********************/
35
enum
36
{
37
LV_FS_RES_OK = 0,
38
LV_FS_RES_HW_ERR, /*Low level hardware error*/
39
LV_FS_RES_FS_ERR, /*Error in the file system structure */
40
LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/
41
LV_FS_RES_FULL, /*Disk full*/
42
LV_FS_RES_LOCKED, /*The file is already opened*/
43
LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/
44
LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/
45
LV_FS_RES_TOUT, /*Process time outed*/
46
LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/
47
LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/
48
LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/
49
LV_FS_RES_UNKNOWN, /*Other unknown error*/
50
};
51
typedef uint8_t lv_fs_res_t;
52
53
struct __lv_fs_drv_t;
54
55
typedef struct
56
{
57
void * file_d;
58
struct __lv_fs_drv_t* drv;
59
} lv_fs_file_t;
60
61
62
typedef struct
63
{
64
void * dir_d;
65
struct __lv_fs_drv_t * drv;
66
} lv_fs_dir_t;
67
68
enum
69
{
70
LV_FS_MODE_WR = 0x01,
71
LV_FS_MODE_RD = 0x02,
72
};
73
typedef uint8_t lv_fs_mode_t;
74
75
typedef struct __lv_fs_drv_t
76
{
77
char letter;
78
uint16_t file_size;
79
uint16_t rddir_size;
80
bool (*ready) (void);
81
82
lv_fs_res_t (*open) (void * file_p, const char * path, lv_fs_mode_t mode);
83
lv_fs_res_t (*close) (void * file_p);
84
lv_fs_res_t (*remove) (const char * fn);
85
lv_fs_res_t (*read) (void * file_p, void * buf, uint32_t btr, uint32_t * br);
86
lv_fs_res_t (*write) (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
87
lv_fs_res_t (*seek) (void * file_p, uint32_t pos);
88
lv_fs_res_t (*tell) (void * file_p, uint32_t * pos_p);
89
lv_fs_res_t (*trunc) (void * file_p);
90
lv_fs_res_t (*size) (void * file_p, uint32_t * size_p);
91
lv_fs_res_t (*rename) (const char * oldname, const char * newname);
92
lv_fs_res_t (*free) (uint32_t * total_p, uint32_t * free_p);
93
94
lv_fs_res_t (*dir_open) (void * rddir_p, const char * path);
95
lv_fs_res_t (*dir_read) (void * rddir_p, char * fn);
96
lv_fs_res_t (*dir_close) (void * rddir_p);
97
} lv_fs_drv_t;
98
99
/**********************
100
* GLOBAL PROTOTYPES
101
**********************/
102
103
/**
104
* Initialize the File system interface
105
*/
106
void lv_fs_init(void);
107
108
/**
109
* Add a new drive
110
* @param drv_p pointer to an lv_fs_drv_t structure which is inited with the
111
* corresponding function pointers. The data will be copied so the variable can be local.
112
*/
113
void lv_fs_add_drv(lv_fs_drv_t * drv_p);
114
115
/**
116
* Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned.
117
* @param letter letter of the drive
118
* @return true: drive is ready; false: drive is not ready
119
*/
120
bool lv_fs_is_ready(char letter);
121
122
/**
123
* Open a file
124
* @param file_p pointer to a lv_fs_file_t variable
125
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
126
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
127
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
128
*/
129
lv_fs_res_t lv_fs_open (lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode);
130
131
/**
132
* Close an already opened file
133
* @param file_p pointer to a lv_fs_file_t variable
134
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
135
*/
136
lv_fs_res_t lv_fs_close (lv_fs_file_t * file_p);
137
138
/**
139
* Delete a file
140
* @param path path of the file to delete
141
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
142
*/
143
lv_fs_res_t lv_fs_remove (const char * path);
144
145
/**
146
* Read from a file
147
* @param file_p pointer to a lv_fs_file_t variable
148
* @param buf pointer to a buffer where the read bytes are stored
149
* @param btr Bytes To Read
150
* @param br the number of real read bytes (Bytes Read). NULL if unused.
151
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
152
*/
153
lv_fs_res_t lv_fs_read (lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br);
154
155
/**
156
* Write into a file
157
* @param file_p pointer to a lv_fs_file_t variable
158
* @param buf pointer to a buffer with the bytes to write
159
* @param btr Bytes To Write
160
* @param br the number of real written bytes (Bytes Written). NULL if unused.
161
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
162
*/
163
lv_fs_res_t lv_fs_write (lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw);
164
165
/**
166
* Set the position of the 'cursor' (read write pointer) in a file
167
* @param file_p pointer to a lv_fs_file_t variable
168
* @param pos the new position expressed in bytes index (0: start of file)
169
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
170
*/
171
lv_fs_res_t lv_fs_seek (lv_fs_file_t * file_p, uint32_t pos);
172
173
/**
174
* Give the position of the read write pointer
175
* @param file_p pointer to a lv_fs_file_t variable
176
* @param pos_p pointer to store the position of the read write pointer
177
* @return LV_FS_RES_OK or any error from 'fs_res_t'
178
*/
179
lv_fs_res_t lv_fs_tell (lv_fs_file_t * file_p, uint32_t * pos);
180
181
/**
182
* Truncate the file size to the current position of the read write pointer
183
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open )
184
* @return LV_FS_RES_OK: no error, the file is read
185
* any error from lv_fs_res_t enum
186
*/
187
lv_fs_res_t lv_fs_trunc (lv_fs_file_t * file_p);
188
189
/**
190
* Give the size of a file bytes
191
* @param file_p pointer to a lv_fs_file_t variable
192
* @param size pointer to a variable to store the size
193
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
194
*/
195
lv_fs_res_t lv_fs_size (lv_fs_file_t * file_p, uint32_t * size);
196
197
/**
198
* Rename a file
199
* @param oldname path to the file
200
* @param newname path with the new name
201
* @return LV_FS_RES_OK or any error from 'fs_res_t'
202
*/
203
lv_fs_res_t lv_fs_rename (const char * oldname, const char * newname);
204
205
/**
206
* Initialize a 'fs_dir_t' variable for directory reading
207
* @param rddir_p pointer to a 'fs_read_dir_t' variable
208
* @param path path to a directory
209
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
210
*/
211
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path);
212
213
/**
214
* Read the next filename form a directory.
215
* The name of the directories will begin with '/'
216
* @param rddir_p pointer to an initialized 'fs_rdir_t' variable
217
* @param fn pointer to a buffer to store the filename
218
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
219
*/
220
lv_fs_res_t lv_fs_dir_read (lv_fs_dir_t * rddir_p, char * fn);
221
222
/**
223
* Close the directory reading
224
* @param rddir_p pointer to an initialized 'fs_dir_t' variable
225
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
226
*/
227
lv_fs_res_t lv_fs_dir_close (lv_fs_dir_t * rddir_p);
228
229
/**
230
* Get the free and total size of a driver in kB
231
* @param letter the driver letter
232
* @param total_p pointer to store the total size [kB]
233
* @param free_p pointer to store the free size [kB]
234
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
235
*/
236
lv_fs_res_t lv_fs_free (char letter, uint32_t * total_p, uint32_t * free_p);
237
238
/**
239
* Fill a buffer with the letters of existing drivers
240
* @param buf buffer to store the letters ('\0' added after the last letter)
241
* @return the buffer
242
*/
243
char * lv_fs_get_letters(char * buf);
244
245
/**
246
* Return with the extension of the filename
247
* @param fn string with a filename
248
* @return pointer to the beginning extension or empty string if no extension
249
*/
250
const char * lv_fs_get_ext(const char * fn);
251
252
/**
253
* Step up one level
254
* @param path pointer to a file name
255
* @return the truncated file name
256
*/
257
char * lv_fs_up(char * path);
258
259
/**
260
* Get the last element of a path (e.g. U:/folder/file -> file)
261
* @param buf buffer to store the letters ('\0' added after the last letter)
262
* @return pointer to the beginning of the last element in the path
263
*/
264
const char * lv_fs_get_last(const char * path);
265
266
/**********************
267
* MACROS
268
**********************/
269
270
#endif /*USE_LV_FILESYSTEM*/
271
272
#ifdef __cplusplus
273
} /* extern "C" */
274
#endif
275
276
#endif /*LV_FS_H*/
277
278