lv_fs.h

Defines

LV_FS_MAX_FN_LENGTH
LV_FS_MAX_PATH_LENGTH
LV_FS_CACHE_FROM_BUFFER

Typedefs

typedef _lv_fs_res_t lv_fs_res_t
typedef _lv_fs_mode_t lv_fs_mode_t
typedef struct _lv_fs_drv_t lv_fs_drv_t

Enums

enum _lv_fs_res_t

Errors in the file system module.

Values:

enumerator LV_FS_RES_OK
enumerator LV_FS_RES_HW_ERR
enumerator LV_FS_RES_FS_ERR
enumerator LV_FS_RES_NOT_EX
enumerator LV_FS_RES_FULL
enumerator LV_FS_RES_LOCKED
enumerator LV_FS_RES_DENIED
enumerator LV_FS_RES_BUSY
enumerator LV_FS_RES_TOUT
enumerator LV_FS_RES_NOT_IMP
enumerator LV_FS_RES_OUT_OF_MEM
enumerator LV_FS_RES_INV_PARAM
enumerator LV_FS_RES_UNKNOWN
enum _lv_fs_mode_t

File open mode.

Values:

enumerator LV_FS_MODE_WR
enumerator LV_FS_MODE_RD
enum lv_fs_whence_t

Seek modes.

Values:

enumerator LV_FS_SEEK_SET

Set the position from absolutely (from the start of file)

enumerator LV_FS_SEEK_CUR

Set the position from the current position

enumerator LV_FS_SEEK_END

Set the position from the end of the file

Functions

void _lv_fs_init(void)

Initialize the File system interface

void _lv_fs_deinit(void)

Deinitialize the File system interface

void lv_fs_drv_init(lv_fs_drv_t *drv)

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.

参数:

drv -- pointer to driver variable to initialize

void lv_fs_drv_register(lv_fs_drv_t *drv)

Add a new drive

参数:

drv -- 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_drv_t *lv_fs_get_drv(char letter)

Give a pointer to a driver from its letter

参数:

letter -- the driver letter

返回:

pointer to a driver or NULL if not found

bool lv_fs_is_ready(char letter)

Test if a drive is ready or not. If the ready function was not initialized true will be returned.

参数:

letter -- letter of the drive

返回:

true: drive is ready; false: drive is not ready

lv_fs_res_t lv_fs_open(lv_fs_file_t *file_p, const char *path, lv_fs_mode_t mode)

Open a file

参数:
  • file_p -- pointer to a lv_fs_file_t variable

  • path -- path to the file beginning with the driver letter (e.g. S:/folder/file.txt)

  • mode -- read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

void lv_fs_make_path_from_buffer(lv_fs_path_ex_t *path, char letter, const void *buf, uint32_t size)

Make a path object for the memory-mapped file compatible with the file system interface

参数:
  • path -- path to a lv_fs_path_ex object

  • letter -- the letter of the driver. E.g. LV_FS_MEMFS_LETTER

  • buf -- address of the memory buffer

  • size -- size of the memory buffer in bytes

lv_fs_res_t lv_fs_close(lv_fs_file_t *file_p)

Close an already opened file

参数:

file_p -- pointer to a lv_fs_file_t variable

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

lv_fs_res_t lv_fs_read(lv_fs_file_t *file_p, void *buf, uint32_t btr, uint32_t *br)

Read from a file

参数:
  • file_p -- pointer to a lv_fs_file_t variable

  • buf -- pointer to a buffer where the read bytes are stored

  • btr -- Bytes To Read

  • br -- the number of real read bytes (Bytes Read). NULL if unused.

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

lv_fs_res_t lv_fs_write(lv_fs_file_t *file_p, const void *buf, uint32_t btw, uint32_t *bw)

Write into a file

参数:
  • file_p -- pointer to a lv_fs_file_t variable

  • buf -- pointer to a buffer with the bytes to write

  • btw -- Bytes To Write

  • bw -- the number of real written bytes (Bytes Written). NULL if unused.

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

lv_fs_res_t lv_fs_seek(lv_fs_file_t *file_p, uint32_t pos, lv_fs_whence_t whence)

Set the position of the 'cursor' (read write pointer) in a file

参数:
  • file_p -- pointer to a lv_fs_file_t variable

  • pos -- the new position expressed in bytes index (0: start of file)

  • whence -- tells from where set the position. See @lv_fs_whence_t

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

lv_fs_res_t lv_fs_tell(lv_fs_file_t *file_p, uint32_t *pos)

Give the position of the read write pointer

参数:
  • file_p -- pointer to a lv_fs_file_t variable

  • pos -- pointer to store the position of the read write pointer

返回:

LV_FS_RES_OK or any error from 'fs_res_t'

lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t *rddir_p, const char *path)

Initialize a 'fs_dir_t' variable for directory reading

参数:
  • rddir_p -- pointer to a 'lv_fs_dir_t' variable

  • path -- path to a directory

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t *rddir_p, char *fn, uint32_t fn_len)

Read the next filename form a directory. The name of the directories will begin with '/'

参数:
  • rddir_p -- pointer to an initialized 'fs_dir_t' variable

  • fn -- pointer to a buffer to store the filename

  • fn_len -- length of the buffer to store the filename

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t *rddir_p)

Close the directory reading

参数:

rddir_p -- pointer to an initialized 'fs_dir_t' variable

返回:

LV_FS_RES_OK or any error from lv_fs_res_t enum

char *lv_fs_get_letters(char *buf)

Fill a buffer with the letters of existing drivers

参数:

buf -- buffer to store the letters ('\0' added after the last letter)

返回:

the buffer

const char *lv_fs_get_ext(const char *fn)

Return with the extension of the filename

参数:

fn -- string with a filename

返回:

pointer to the beginning extension or empty string if no extension

char *lv_fs_up(char *path)

Step up one level

参数:

path -- pointer to a file name

返回:

the truncated file name

const char *lv_fs_get_last(const char *path)

Get the last element of a path (e.g. U:/folder/file -> file)

参数:

path -- pointer to a file name

返回:

pointer to the beginning of the last element in the path

struct _lv_fs_drv_t

Public Members

char letter
uint32_t cache_size
bool (*ready_cb)(lv_fs_drv_t *drv)
void *(*open_cb)(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode)
lv_fs_res_t (*close_cb)(lv_fs_drv_t *drv, void *file_p)
lv_fs_res_t (*read_cb)(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br)
lv_fs_res_t (*write_cb)(lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw)
lv_fs_res_t (*seek_cb)(lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence)
lv_fs_res_t (*tell_cb)(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p)
void *(*dir_open_cb)(lv_fs_drv_t *drv, const char *path)
lv_fs_res_t (*dir_read_cb)(lv_fs_drv_t *drv, void *rddir_p, char *fn, uint32_t fn_len)
lv_fs_res_t (*dir_close_cb)(lv_fs_drv_t *drv, void *rddir_p)
void *user_data

Custom file user data

struct lv_fs_file_cache_t

Public Members

uint32_t start
uint32_t end
uint32_t file_position
void *buffer
struct lv_fs_file_t

Public Members

void *file_d
lv_fs_drv_t *drv
lv_fs_file_cache_t *cache
struct lv_fs_path_ex_t

Public Members

char path[4]
const void *buffer
uint32_t size
struct lv_fs_dir_t

Public Members

void *dir_d
lv_fs_drv_t *drv