Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_misc/lv_ufs.h
1476 views
1
/**
2
* @file lv_ufs.h
3
* Implementation of RAM file system which do NOT support directories.
4
* The API is compatible with the lv_fs_int module.
5
*/
6
7
#ifndef LV_UFS_H
8
#define LV_UFS_H
9
10
#ifdef __cplusplus
11
extern "C" {
12
#endif
13
14
15
/*********************
16
* INCLUDES
17
*********************/
18
#ifdef LV_CONF_INCLUDE_SIMPLE
19
#include "lv_conf.h"
20
#else
21
#include "../../lv_conf.h"
22
#endif
23
24
#if USE_LV_FILESYSTEM
25
26
#include "lv_fs.h"
27
#include "lv_mem.h"
28
29
/*********************
30
* DEFINES
31
*********************/
32
#define UFS_LETTER 'U'
33
34
/**********************
35
* TYPEDEFS
36
**********************/
37
/*Description of a file entry */
38
typedef struct
39
{
40
char * fn_d;
41
void * data_d;
42
uint32_t size; /*Data length in bytes*/
43
uint16_t oc; /*Open Count*/
44
uint8_t const_data :1;
45
} lv_ufs_ent_t;
46
47
/*File descriptor, used to handle opening an entry more times simultaneously
48
Contains unique informations about the specific opening*/
49
typedef struct
50
{
51
lv_ufs_ent_t* ent; /*Pointer to the entry*/
52
uint32_t rwp; /*Read Write Pointer*/
53
uint8_t ar :1; /*1: Access for read is enabled */
54
uint8_t aw :1; /*1: Access for write is enabled */
55
} lv_ufs_file_t;
56
57
/* Read directory descriptor.
58
* It is used to to iterate through the entries in a directory*/
59
typedef struct
60
{
61
lv_ufs_ent_t * last_ent;
62
} lv_ufs_dir_t;
63
64
/**********************
65
* GLOBAL PROTOTYPES
66
**********************/
67
68
/**
69
* Create a driver for ufs and initialize it.
70
*/
71
void lv_ufs_init(void);
72
73
/**
74
* Give the state of the ufs
75
* @return true if ufs is initialized and can be used else false
76
*/
77
bool lv_ufs_ready(void);
78
79
/**
80
* Open a file in ufs
81
* @param file_p pointer to a lv_ufs_file_t variable
82
* @param fn name of the file. There are no directories so e.g. "myfile.txt"
83
* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)
84
* @return LV_FS_RES_OK: no error, the file is opened
85
* any error from lv_fs_res_t enum
86
*/
87
lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode);
88
89
/**
90
* Create a file with a constant data
91
* @param fn name of the file (directories are not supported)
92
* @param const_p pointer to a constant data
93
* @param len length of the data pointed by 'const_p' in bytes
94
* @return LV_FS_RES_OK: no error, the file is read
95
* any error from lv_fs_res_t enum
96
*/
97
lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len);
98
99
/**
100
* Close an opened file
101
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
102
* @return LV_FS_RES_OK: no error, the file is read
103
* any error from lv_fs_res_t enum
104
*/
105
lv_fs_res_t lv_ufs_close (void * file_p);
106
107
/**
108
* Remove a file. The file can not be opened.
109
* @param fn '\0' terminated string
110
* @return LV_FS_RES_OK: no error, the file is removed
111
* LV_FS_RES_DENIED: the file was opened, remove failed
112
*/
113
lv_fs_res_t lv_ufs_remove(const char * fn);
114
115
/**
116
* Read data from an opened file
117
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
118
* @param buf pointer to a memory block where to store the read data
119
* @param btr number of Bytes To Read
120
* @param br the real number of read bytes (Byte Read)
121
* @return LV_FS_RES_OK: no error, the file is read
122
* any error from lv_fs_res_t enum
123
*/
124
lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br);
125
126
/**
127
* Write data to an opened file
128
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
129
* @param buf pointer to a memory block which content will be written
130
* @param btw the number Bytes To Write
131
* @param bw The real number of written bytes (Byte Written)
132
* @return LV_FS_RES_OK: no error, the file is read
133
* any error from lv_fs_res_t enum
134
*/
135
lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
136
137
/**
138
* Set the read write pointer. Also expand the file size if necessary.
139
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
140
* @param pos the new position of read write pointer
141
* @return LV_FS_RES_OK: no error, the file is read
142
* any error from lv_fs_res_t enum
143
*/
144
lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos);
145
146
/**
147
* Give the position of the read write pointer
148
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
149
* @param pos_p pointer to to store the result
150
* @return LV_FS_RES_OK: no error, the file is read
151
* any error from lv_fs_res_t enum
152
*/
153
lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p);
154
155
/**
156
* Truncate the file size to the current position of the read write pointer
157
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
158
* @return LV_FS_RES_OK: no error, the file is read
159
* any error from lv_fs_res_t enum
160
*/
161
lv_fs_res_t lv_ufs_trunc (void * file_p);
162
163
/**
164
* Give the size of the file in bytes
165
* @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
166
* @param size_p pointer to store the size
167
* @return LV_FS_RES_OK: no error, the file is read
168
* any error from lv_fs_res_t enum
169
*/
170
lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p);
171
172
/**
173
* Initialize a lv_ufs_read_dir_t variable to directory reading
174
* @param rddir_p pointer to a 'ufs_read_dir_t' variable
175
* @param path uFS doesn't support folders so it has to be ""
176
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
177
*/
178
lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path);
179
180
/**
181
* Read the next file name
182
* @param dir_p pointer to an initialized 'ufs_read_dir_t' variable
183
* @param fn pointer to buffer to sore the file name
184
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
185
*/
186
lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn);
187
188
/**
189
* Close the directory reading
190
* @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable
191
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
192
*/
193
lv_fs_res_t lv_ufs_dir_close(void * rddir_p);
194
195
/**
196
* Give the size of a drive
197
* @param total_p pointer to store the total size [kB]
198
* @param free_p pointer to store the free site [kB]
199
* @return LV_FS_RES_OK or any error from 'fs_res_t'
200
*/
201
lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p);
202
203
/**********************
204
* MACROS
205
**********************/
206
207
#endif /*USE_LV_FILESYSTEM*/
208
209
#ifdef __cplusplus
210
} /* extern "C" */
211
#endif
212
213
#endif
214
215