lvgl文件系统打开文件流程简单分析

lvgl文件系统打开文件流程简单分析

1.初始化

lvgl文件系统打开文件流程简单分析_第1张图片
lv_fs_stdio_init中调用了在lv_conf.h中初始化的LV_FS_STDIO_LETTER,该宏定义用来与输入路径开头的盘符标识相匹配。在这个函数中完成了fs_drv的注册。

void lv_fs_stdio_init(void)
{
    /*---------------------------------------------------
     * Register the file system interface in LVGL
     *--------------------------------------------------*/

    /*Add a simple drive to open images*/
    static lv_fs_drv_t fs_drv; /*A driver descriptor*/
    lv_fs_drv_init(&fs_drv);

    /*Set up fields...*/
    fs_drv.letter = LV_FS_STDIO_LETTER;
    fs_drv.cache_size = LV_FS_STDIO_CACHE_SIZE;

    fs_drv.open_cb = fs_open;
    fs_drv.close_cb = fs_close;
    fs_drv.read_cb = fs_read;
    fs_drv.write_cb = fs_write;
    fs_drv.seek_cb = fs_seek;
    fs_drv.tell_cb = fs_tell;

    fs_drv.dir_close_cb = fs_dir_close;
    fs_drv.dir_open_cb = fs_dir_open;
    fs_drv.dir_read_cb = fs_dir_read;

    lv_fs_drv_register(&fs_drv);
}

打开文件

lvgl文件系统打开文件流程简单分析_第2张图片
lv_fs_get_real_path会去除盘符标识及冒号
drv->dir_open_cb会将lv_conf.h中的宏定义LV_FS_STDIO_PATH与去掉盘符标识后的输入路径连接在一起lv_snprintf(buf, sizeof(buf), LV_FS_STDIO_PATH "%s", path);
所以win10下lv_conf.h可这样定义

#define LV_USE_FS_STDIO 1
#if LV_USE_FS_STDIO
#define LV_FS_STDIO_LETTER 'D'     /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_STDIO_PATH "D:"         /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_STDIO_CACHE_SIZE  0   /*>0 to cache this number of bytes in lv_fs_read()*/
#endif

#define LV_USE_FS_WIN32 0
#if LV_USE_FS_WIN32
#define LV_FS_WIN32_LETTER  'D'    /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_WIN32_PATH "D:"         /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_WIN32_CACHE_SIZE 0    /*>0 to cache this number of bytes in lv_fs_read()*/
#endif

总结

LV_FS_STDIO_PATH只是一个标识符,重要的是LV_FS_STDIO_PATH以及输入路径

你可能感兴趣的:(嵌入式,ui)