lv_fs.h
API reference for lv_fs.h
Functions
lv_fs_get_drv
Give a pointer to a driver from its letter
lv_fs_drv_t * lv_fs_get_drv(char letter)| Name | Type | Description |
|---|---|---|
letter | char | the driver-identifier letter |
Returns: lv_fs_drv_t * — pointer to a driver or NULL if not found
lv_fs_get_buffer_from_path
Get the buffer address and size from a path object
lv_result_t lv_fs_get_buffer_from_path(lv_fs_path_ex_t *path, void **buffer, uint32_t *size)| Name | Type | Description |
|---|---|---|
path | lv_fs_path_ex_t * | pointer to an initialized lv_fs_path_ex data |
buffer | void ** | pointer to a void * variable to store the address |
size | uint32_t * | pointer to an uint32_t data to store the size |
Returns: lv_result_t — LV_RESULT_OK: buffer and size are set; LV_RESULT_INVALID: an error happened.
lv_fs_get_size
Get the size in bytes of an open file. The file read/write position will not be affected.
lv_fs_res_t lv_fs_get_size(lv_fs_file_t *file_p, uint32_t *size_res)| Name | Type | Description |
|---|---|---|
file_p | lv_fs_file_t * | pointer to a lv_fs_file_t variable |
size_res | uint32_t * | pointer to store the file size |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t
lv_fs_path_get_size
Get the size in bytes of a file at the given path.
lv_fs_res_t lv_fs_path_get_size(const char *path, uint32_t *size_res)| Name | Type | Description |
|---|---|---|
path | const char * | the path of the file |
size_res | uint32_t * | pointer to store the file size |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t
lv_fs_get_letters
Fill a buffer with the letters of existing drivers
char * lv_fs_get_letters(char *buf)| Name | Type | Description |
|---|---|---|
buf | char * | buffer to store the letters ('\0' added after the last letter) |
Returns: char * — the buffer
lv_fs_get_ext
Return with the extension of the filename
const char * lv_fs_get_ext(const char *fn)| Name | Type | Description |
|---|---|---|
fn | const char * | string with a filename |
Returns: const char * — pointer to the beginning extension or empty string if no extension
lv_fs_get_last
Get the last element of a path (e.g. U:/folder/file -> file)
const char * lv_fs_get_last(const char *path)| Name | Type | Description |
|---|---|---|
path | const char * | pointer to a file name |
Returns: const char * — pointer to the beginning of the last element in the path
lv_fs_drv_init
Initialize a file system driver with default values. It is used to ensure all fields have known values and not memory junk. After it you can set the fields.
void lv_fs_drv_init(lv_fs_drv_t *drv)| Name | Type | Description |
|---|---|---|
drv | lv_fs_drv_t * | pointer to driver variable to initialize |
lv_fs_drv_register
Add a new drive
void lv_fs_drv_register(lv_fs_drv_t *drv)| Name | Type | Description |
|---|---|---|
drv | lv_fs_drv_t * | pointer to an lv_fs_drv_t structure which is inited with the corresponding function pointers. Only pointer is saved, so the driver should be static or dynamically allocated. |
lv_fs_remove_drive
Remove a drive and call its remove function if available
void lv_fs_remove_drive(char letter)| Name | Type | Description |
|---|---|---|
letter | char | letter identifier of the drive to remove |
lv_fs_is_ready
Test if a drive is ready or not. If the ready function was not initialized true will be returned.
bool lv_fs_is_ready(char letter)| Name | Type | Description |
|---|---|---|
letter | char | letter of the drive |
Returns: bool — true: drive is ready; false: drive is not ready
lv_fs_open
Open a file
lv_fs_res_t lv_fs_open(lv_fs_file_t *file_p, const char *path, lv_fs_mode_t mode)| Name | Type | Description |
|---|---|---|
file_p | lv_fs_file_t * | pointer to a lv_fs_file_t variable |
path | const char * | path to the file beginning with the driver letter (e.g. S:/folder/file.txt) |
mode | lv_fs_mode_t | read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_make_path_from_buffer
Create a special object from buffer/ memory address which looks like a file and can be passed as path to lv_fs_open and other functions accepting a path.
For example
//Create a PNG file from t a buffer and use it
lv_fs_path_ex_t p;
lv_fs_make_path_from_buffer(&p, 'A', my_buf, my_buf_size, "png");
lv_image_set_src(image1, &p);void lv_fs_make_path_from_buffer(lv_fs_path_ex_t *path, char letter, const void *buf, uint32_t size, const char *ext)| Name | Type | Description |
|---|---|---|
path | lv_fs_path_ex_t * | path to a lv_fs_path_ex object |
letter | char | the identifier letter of the driver. E.g. LV_FS_MEMFS_LETTER |
buf | const void * | address of the memory buffer |
size | uint32_t | size of the memory buffer in bytes |
ext | const char * | the extension, e.g. "png". May be NULL. When NULL no extension is added. |
lv_fs_close
Close an already opened file
lv_fs_res_t lv_fs_close(lv_fs_file_t *file_p)| Name | Type | Description |
|---|---|---|
file_p | lv_fs_file_t * | pointer to a lv_fs_file_t variable |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_read
Read from a file
lv_fs_res_t lv_fs_read(lv_fs_file_t *file_p, void *buf, uint32_t btr, uint32_t *br)| Name | Type | Description |
|---|---|---|
file_p | lv_fs_file_t * | pointer to a lv_fs_file_t variable |
buf | void * | pointer to a buffer where the read bytes are stored |
btr | uint32_t | Bytes To Read |
br | uint32_t * | the number of real read bytes (Bytes Read). May be NULL. |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_write
Write into a file
lv_fs_res_t lv_fs_write(lv_fs_file_t *file_p, const void *buf, uint32_t btw, uint32_t *bw)| Name | Type | Description |
|---|---|---|
file_p | lv_fs_file_t * | pointer to a lv_fs_file_t variable |
buf | const void * | pointer to a buffer with the bytes to write |
btw | uint32_t | Bytes To Write |
bw | uint32_t * | the number of real written bytes (Bytes Written). May be NULL. |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_seek
Set the position of the 'cursor' (read write pointer) in a file
lv_fs_res_t lv_fs_seek(lv_fs_file_t *file_p, uint32_t pos, lv_fs_whence_t whence)| Name | Type | Description |
|---|---|---|
file_p | lv_fs_file_t * | pointer to a lv_fs_file_t variable |
pos | uint32_t | the new position expressed in bytes index (0: start of file) |
whence | lv_fs_whence_t | tells from where to set position. See lv_fs_whence_t |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_tell
Give the position of the read write pointer
lv_fs_res_t lv_fs_tell(lv_fs_file_t *file_p, uint32_t *pos)| Name | Type | Description |
|---|---|---|
file_p | lv_fs_file_t * | pointer to a lv_fs_file_t variable |
pos | uint32_t * | pointer to store the position of the read write pointer |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from 'fs_res_t'
lv_fs_load_to_buf
Read the contents of a file at the given path into a buffer.
lv_fs_res_t lv_fs_load_to_buf(void *buf, uint32_t buf_size, const char *path)| Name | Type | Description |
|---|---|---|
buf | void * | a buffer to read the contents of the file into |
buf_size | uint32_t | the size of the buffer and the amount to read from the file |
path | const char * | the path of the file |
Returns: lv_fs_res_t — LV_FS_RES_OK on success, LV_FS_RES_UNKNOWN if fewer than buf_size bytes could be read from the file, or any error from lv_fs_res_t
lv_fs_load_with_alloc
Load a file into a memory buffer.
void * lv_fs_load_with_alloc(const char *path, uint32_t *size)| Name | Type | Description |
|---|---|---|
path | const char * | the path of the file |
size | uint32_t * | pointer to store the size of the loaded file |
Returns: void * — a pointer to the loaded file buffer, or NULL if an error occurred
lv_fs_dir_open
Initialize a 'fs_dir_t' variable for directory reading
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t *rddir_p, const char *path)| Name | Type | Description |
|---|---|---|
rddir_p | lv_fs_dir_t * | pointer to a 'lv_fs_dir_t' variable |
path | const char * | path to a directory |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_dir_read
Read the next filename form a directory. The name of the directories will begin with '/'
lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t *rddir_p, char *fn, uint32_t fn_len)| Name | Type | Description |
|---|---|---|
rddir_p | lv_fs_dir_t * | pointer to an initialized 'fs_dir_t' variable |
fn | char * | pointer to a buffer to store the filename |
fn_len | uint32_t | length of the buffer to store the filename |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_dir_close
Close the directory reading
lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t *rddir_p)| Name | Type | Description |
|---|---|---|
rddir_p | lv_fs_dir_t * | pointer to an initialized 'fs_dir_t' variable |
Returns: lv_fs_res_t — LV_FS_RES_OK or any error from lv_fs_res_t enum
lv_fs_up
Step up one level
char * lv_fs_up(char *path)| Name | Type | Description |
|---|---|---|
path | char * | pointer to a file name |
Returns: char * — the truncated file name
lv_fs_path_join
Concatenate two path components and automatically add/remove a separator as needed. buf, buf_sz, and the return value are analogous to lv_snprintf
int lv_fs_path_join(char *buf, size_t buf_sz, const char *base, const char *end)| Name | Type | Description |
|---|---|---|
buf | char * | the buffer to place the result in |
buf_sz | size_t | the size of buf. At most buf_sz - 1 characters will be written to buf, and a null terminator |
base | const char * | the first path component |
end | const char * | the second path component |
Returns: int — the number of characters (not including the null terminator) that would be written to buf, even if buf_sz-1 was smaller
Enums
lv_fs_res_t
Errors in the file system module.
| Name | Value |
|---|---|
LV_FS_RES_OK | 0 |
LV_FS_RES_HW_ERR | |
LV_FS_RES_FS_ERR | |
LV_FS_RES_NOT_EX | |
LV_FS_RES_FULL | |
LV_FS_RES_LOCKED | |
LV_FS_RES_DENIED | |
LV_FS_RES_BUSY | |
LV_FS_RES_TOUT | |
LV_FS_RES_NOT_IMP | |
LV_FS_RES_OUT_OF_MEM | |
LV_FS_RES_INV_PARAM | |
LV_FS_RES_DRIVE_LETTER_ALREADY_USED | |
LV_FS_RES_UNKNOWN |
lv_fs_mode_t
File open mode.
| Name | Value |
|---|---|
LV_FS_MODE_WR | 0x01 |
LV_FS_MODE_RD | 0x02 |
Used by 1 function
lv_fs_open— parammode
lv_fs_whence_t
Seek modes.
| Name | Value | Description |
|---|---|---|
LV_FS_SEEK_SET | 0x00 | Set the position from absolutely (from the start of file) |
LV_FS_SEEK_CUR | 0x01 | Set the position from the current position |
LV_FS_SEEK_END | 0x02 | Set the position from the end of the file |
Used by 1 function
lv_fs_seek— paramwhence
Structs
_lv_fs_drv_t
| Member | Type | Description |
|---|---|---|
letter | char | |
cache_size | uint32_t | |
ready_cb | bool(*)(lv_fs_drv_t *drv) | |
remove_cb | void(*)(lv_fs_drv_t *drv) | |
open_cb | void *(*)(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode) | |
close_cb | lv_fs_res_t(*)(lv_fs_drv_t *drv, void *file_p) | |
read_cb | lv_fs_res_t(*)(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br) | |
write_cb | lv_fs_res_t(*)(lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw) | |
seek_cb | lv_fs_res_t(*)(lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence) | |
tell_cb | lv_fs_res_t(*)(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p) | |
dir_open_cb | void *(*)(lv_fs_drv_t *drv, const char *path) | |
dir_read_cb | lv_fs_res_t(*)(lv_fs_drv_t *drv, void *rddir_p, char *fn, uint32_t fn_len) | |
dir_close_cb | lv_fs_res_t(*)(lv_fs_drv_t *drv, void *rddir_p) | |
user_data | void * | Custom file user data |
lv_fs_file_t
| Member | Type | Description |
|---|---|---|
file_d | void * | |
drv | lv_fs_drv_t * | |
cache | lv_fs_file_cache_t * |
Used by 7 functions
lv_fs_open— paramfile_plv_fs_close— paramfile_plv_fs_read— paramfile_plv_fs_write— paramfile_plv_fs_seek— paramfile_plv_fs_tell— paramfile_plv_fs_get_size— paramfile_p
lv_fs_dir_t
| Member | Type | Description |
|---|---|---|
dir_d | void * | |
drv | lv_fs_drv_t * |
Used by 3 functions
lv_fs_dir_open— paramrddir_plv_fs_dir_read— paramrddir_plv_fs_dir_close— paramrddir_p
lv_fs_path_ex_t
Extended path object to specify buffer for memory-mapped files
| Member | Type | Description |
|---|---|---|
path | char[64] | Store the driver letter address and size |
Used by 2 functions
lv_fs_make_path_from_buffer— parampathlv_fs_get_buffer_from_path— parampath
Typedefs
lv_fs_drv_t
typedef struct _lv_fs_drv_t lv_fs_drv_tUsed by 2 functions
lv_fs_drv_init— paramdrvlv_fs_drv_register— paramdrv
Macros
LV_FS_MAX_FN_LENGTH
#define LV_FS_MAX_FN_LENGTH 64LV_FS_MAX_PATH_LENGTH
#define LV_FS_MAX_PATH_LENGTH 256LV_FS_CACHE_FROM_BUFFER
#define LV_FS_CACHE_FROM_BUFFER UINT32_MAXDependencies
Last updated on