「App:Library:LVGL:docs:Overview:File system」の版間の差分
7行目: | 7行目: | ||
|- | |- | ||
| | | | ||
− | LVGL has a 'File system' abstraction module that enables you to attach any type of file system. A file system is identified by an assigned drive letter. For example, if an SD card is associated with the letter <code style="color: #bb0000;">'S'</code>, a file can be reached using <code style="color: #bb0000;">"S:path/to/file.txt"</code>. | + | LVGL has a 'File system' abstraction module that enables you to attach any type of file system. |
− | | | + | |
+ | A file system is identified by an assigned drive letter. | ||
+ | |||
+ | For example, if an SD card is associated with the letter <code style="color: #bb0000;">'S'</code>, a file can be reached using <code style="color: #bb0000;">"S:path/to/file.txt"</code>. | ||
+ | |LVGL has a 'File system' abstraction module that enables you to attach any type of file system. | ||
+ | |||
+ | A file system is identified by an assigned drive letter. | ||
+ | |||
+ | For example, if an SD card is associated with the letter <code style="color: #bb0000;">'S'</code>, a file can be reached using <code style="color: #bb0000;">"S:path/to/file.txt"</code>. | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
19行目: | 27行目: | ||
|- | |- | ||
| | | | ||
− | The lv_fs_if repository contains prepared drivers using POSIX, standard C and the FATFS API. See its README for the details. | + | The lv_fs_if repository contains prepared drivers using POSIX, standard C and the FATFS API. |
− | | | + | |
+ | See its README for the details. | ||
+ | |The lv_fs_if repository contains prepared drivers using POSIX, standard C and the FATFS API. | ||
+ | |||
+ | See its README for the details. | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
32行目: | 44行目: | ||
|- | |- | ||
| | | | ||
− | To add a driver, a <code style="color: #bb0000;">lv_fs_drv_t</code> needs to be initialized like below. The <code style="color: #bb0000;">lv_fs_drv_t</code> needs to be static, global or dynamically allocated and not a local variable. | + | To add a driver, a <code style="color: #bb0000;">lv_fs_drv_t</code> needs to be initialized like below. |
+ | |||
+ | The <code style="color: #bb0000;">lv_fs_drv_t</code> needs to be static, global or dynamically allocated and not a local variable. | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | static lv_fs_drv_t drv; /*Needs to be static or global*/ | ||
+ | lv_fs_drv_init(&drv); /*Basic initialization*/ | ||
+ | |||
+ | drv.letter = 'S'; /*An uppercase letter to identify the drive */ | ||
+ | drv.cache_size = my_cahce_size; /*Cache size for reading in bytes. 0 to not cache.*/ | ||
+ | |||
+ | drv.ready_cb = my_ready_cb; /*Callback to tell if the drive is ready to use */ | ||
+ | drv.open_cb = my_open_cb; /*Callback to open a file */ | ||
+ | drv.close_cb = my_close_cb; /*Callback to close a file */ | ||
+ | drv.read_cb = my_read_cb; /*Callback to read a file */ | ||
+ | drv.write_cb = my_write_cb; /*Callback to write a file */ | ||
+ | drv.seek_cb = my_seek_cb; /*Callback to seek in a file (Move cursor) */ | ||
+ | drv.tell_cb = my_tell_cb; /*Callback to tell the cursor position */ | ||
+ | |||
+ | drv.dir_open_cb = my_dir_open_cb; /*Callback to open directory to read its content */ | ||
+ | drv.dir_read_cb = my_dir_read_cb; /*Callback to read a directory's content */ | ||
+ | drv.dir_close_cb = my_dir_close_cb; /*Callback to close a directory */ | ||
+ | |||
+ | drv.user_data = my_user_data; /*Any custom data if required*/ | ||
+ | |||
+ | lv_fs_drv_register(&drv); /*Finally register the drive*/ | ||
+ | </syntaxhighlight> | ||
+ | Any of the callbacks can be <code style="color: #bb0000;">NULL</code> to indicate that operation is not supported. | ||
+ | |To add a driver, a <code style="color: #bb0000;">lv_fs_drv_t</code> needs to be initialized like below. | ||
+ | The <code style="color: #bb0000;">lv_fs_drv_t</code> needs to be static, global or dynamically allocated and not a local variable. | ||
<syntaxhighlight lang="C++" style="border:1px dashed gray;"> | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
static lv_fs_drv_t drv; /*Needs to be static or global*/ | static lv_fs_drv_t drv; /*Needs to be static or global*/ | ||
57行目: | 97行目: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Any of the callbacks can be <code style="color: #bb0000;">NULL</code> to indicate that operation is not supported. | Any of the callbacks can be <code style="color: #bb0000;">NULL</code> to indicate that operation is not supported. | ||
− | |||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
71行目: | 110行目: | ||
The prototype of <code style="color: #bb0000;">open_cb</code> looks like this: | The prototype of <code style="color: #bb0000;">open_cb</code> looks like this: | ||
void * (*open_cb)(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode); | void * (*open_cb)(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode); | ||
− | <code style="color: #bb0000;">path</code> is the path after the drive letter (e.g. "S:path/to/file.txt" -> "path/to/file.txt"). <code style="color: #bb0000;">mode</code> can be <code style="color: #bb0000;">LV_FS_MODE_WR</code> or <code style="color: #bb0000;">LV_FS_MODE_RD</code> to open for writes or reads. | + | <code style="color: #bb0000;">path</code> is the path after the drive letter (e.g. "S:path/to/file.txt" -> "path/to/file.txt"). |
+ | |||
+ | <code style="color: #bb0000;">mode</code> can be <code style="color: #bb0000;">LV_FS_MODE_WR</code> or <code style="color: #bb0000;">LV_FS_MODE_RD</code> to open for writes or reads. | ||
+ | |||
+ | The return value is a pointer to a ''file object'' that describes the opened file or <code style="color: #bb0000;">NULL</code> if there were any issues (e.g. the file wasn't found). | ||
+ | |||
+ | The returned file object will be passed to other file system related callbacks. (see below) | ||
+ | |The prototype of <code style="color: #bb0000;">open_cb</code> looks like this: | ||
+ | void * (*open_cb)(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode); | ||
+ | <code style="color: #bb0000;">path</code> is the path after the drive letter (e.g. "S:path/to/file.txt" -> "path/to/file.txt"). | ||
− | The return value is a pointer to a ''file object'' that describes the opened file or <code style="color: #bb0000;">NULL</code> if there were any issues (e.g. the file wasn't found). The returned file object will be passed to other file system related callbacks. (see below) | + | <code style="color: #bb0000;">mode</code> can be <code style="color: #bb0000;">LV_FS_MODE_WR</code> or <code style="color: #bb0000;">LV_FS_MODE_RD</code> to open for writes or reads. |
− | + | ||
+ | The return value is a pointer to a ''file object'' that describes the opened file or <code style="color: #bb0000;">NULL</code> if there were any issues (e.g. the file wasn't found). | ||
+ | |||
+ | The returned file object will be passed to other file system related callbacks. (see below) | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
85行目: | 136行目: | ||
|- | |- | ||
| | | | ||
− | The other callbacks are quite similar. For example <code style="color: #bb0000;">write_cb</code> looks like this: | + | The other callbacks are quite similar. |
+ | |||
+ | For example <code style="color: #bb0000;">write_cb</code> looks like this: | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | lv_fs_res_t (*write_cb)(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); | ||
+ | </syntaxhighlight> | ||
+ | For <code style="color: #bb0000;">file_p</code>, LVGL passes the return value of <code style="color: #bb0000;">open_cb</code>, <code style="color: #bb0000;">buf</code> is the data to write, <code style="color: #bb0000;">btw</code> is the Bytes To Write, <code style="color: #bb0000;">bw</code> is the actually written bytes. | ||
+ | |||
+ | For a template of these callbacks see lv_fs_template.c. | ||
+ | |The other callbacks are quite similar. | ||
+ | For example <code style="color: #bb0000;">write_cb</code> looks like this: | ||
<syntaxhighlight lang="C++" style="border:1px dashed gray;"> | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
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 (*write_cb)(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); | ||
92行目: | 153行目: | ||
For a template of these callbacks see lv_fs_template.c. | For a template of these callbacks see lv_fs_template.c. | ||
− | |||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
119行目: | 179行目: | ||
''The mode in <code style="color: #bb0000;">lv_fs_open</code> can be <code style="color: #bb0000;">LV_FS_MODE_WR</code> to open for writes only or <code style="color: #bb0000;">LV_FS_MODE_RD | LV_FS_MODE_WR</code> for both'' | ''The mode in <code style="color: #bb0000;">lv_fs_open</code> can be <code style="color: #bb0000;">LV_FS_MODE_WR</code> to open for writes only or <code style="color: #bb0000;">LV_FS_MODE_RD | LV_FS_MODE_WR</code> for both'' | ||
− | This example shows how to read a directory's content. It's up to the driver how to mark directories in the result but it can be a good practice to insert a <code style="color: #bb0000;">'/'</code> in front of each directory name. | + | This example shows how to read a directory's content. |
+ | |||
+ | It's up to the driver how to mark directories in the result but it can be a good practice to insert a <code style="color: #bb0000;">'/'</code> in front of each directory name. | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | lv_fs_dir_t dir; | ||
+ | lv_fs_res_t res; | ||
+ | res = lv_fs_dir_open(&dir, "S:/folder"); | ||
+ | if(res != LV_FS_RES_OK) my_error_handling(); | ||
+ | |||
+ | char fn[256]; | ||
+ | while(1) { | ||
+ | res = lv_fs_dir_read(&dir, fn); | ||
+ | if(res != LV_FS_RES_OK) { | ||
+ | my_error_handling(); | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | /*fn is empty, if not more files to read*/ | ||
+ | if(strlen(fn) == 0) { | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | printf("%s\n", fn); | ||
+ | } | ||
+ | |||
+ | lv_fs_dir_close(&dir); | ||
+ | </syntaxhighlight> | ||
+ | |The example below shows how to read from a file: | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | lv_fs_file_t f; | ||
+ | lv_fs_res_t res; | ||
+ | res = lv_fs_open(&f, "S:folder/file.txt", LV_FS_MODE_RD); | ||
+ | if(res != LV_FS_RES_OK) my_error_handling(); | ||
+ | |||
+ | uint32_t read_num; | ||
+ | uint8_t buf[8]; | ||
+ | res = lv_fs_read(&f, buf, 8, &read_num); | ||
+ | if(res != LV_FS_RES_OK || read_num != 8) my_error_handling(); | ||
+ | |||
+ | lv_fs_close(&f); | ||
+ | </syntaxhighlight> | ||
+ | ''The mode in <code style="color: #bb0000;">lv_fs_open</code> can be <code style="color: #bb0000;">LV_FS_MODE_WR</code> to open for writes only or <code style="color: #bb0000;">LV_FS_MODE_RD | LV_FS_MODE_WR</code> for both'' | ||
+ | |||
+ | This example shows how to read a directory's content. | ||
+ | |||
+ | It's up to the driver how to mark directories in the result but it can be a good practice to insert a <code style="color: #bb0000;">'/'</code> in front of each directory name. | ||
<syntaxhighlight lang="C++" style="border:1px dashed gray;"> | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
lv_fs_dir_t dir; | lv_fs_dir_t dir; | ||
144行目: | 249行目: | ||
lv_fs_dir_close(&dir); | lv_fs_dir_close(&dir); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
167行目: | 271行目: | ||
* seek | * seek | ||
* tell | * tell | ||
− | | | + | |Image objects can be opened from files too (besides variables stored in the compiled program). |
+ | |||
+ | |||
+ | |||
+ | |||
+ | To use files in image widgets the following callbacks are required: | ||
+ | |||
+ | * open | ||
+ | * close | ||
+ | * read | ||
+ | * seek | ||
+ | * tell | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
178行目: | 293行目: | ||
|- | |- | ||
| | | | ||
− | Typedefs | + | '''Typedefs''' |
<span style="background-color:#e7f2fa;color:#2980b9;">typedef uint8_t lv_fs_res_t </span> | <span style="background-color:#e7f2fa;color:#2980b9;">typedef uint8_t lv_fs_res_t </span> | ||
189行目: | 304行目: | ||
: | : | ||
− | Enums | + | '''Enums''' |
<span style="background-color:#e7f2fa;color:#2980b9;">enum [anonymous] </span> | <span style="background-color:#e7f2fa;color:#2980b9;">enum [anonymous] </span> | ||
− | : Errors in the file system module. ''Values:'' | + | : Errors in the file system module. |
+ | : '''''Values:''''' | ||
: <span style="background-color: #eeeeee;">enumerator LV_FS_RES_OK </span> | : <span style="background-color: #eeeeee;">enumerator LV_FS_RES_OK </span> | ||
:: | :: | ||
221行目: | 337行目: | ||
<span style="background-color:#e7f2fa;color:#2980b9;">enum [anonymous] </span> | <span style="background-color:#e7f2fa;color:#2980b9;">enum [anonymous] </span> | ||
− | : File open mode. ''Values:'' | + | : File open mode. |
+ | : '''''Values:''''' | ||
: <span style="background-color: #eeeeee;">enumerator LV_FS_MODE_WR </span> | : <span style="background-color: #eeeeee;">enumerator LV_FS_MODE_WR </span> | ||
:: | :: | ||
228行目: | 345行目: | ||
<span style="background-color:#e7f2fa;color:#2980b9;">enum lv_fs_whence_t </span> | <span style="background-color:#e7f2fa;color:#2980b9;">enum lv_fs_whence_t </span> | ||
− | : Seek modes. '' | + | : Seek modes. |
+ | : '''''Values:''''' | ||
: <span style="background-color: #eeeeee;">enumerator LV_FS_SEEK_SET </span> | : <span style="background-color: #eeeeee;">enumerator LV_FS_SEEK_SET </span> | ||
:: Set the position from absolutely (from the start of file) | :: Set the position from absolutely (from the start of file) | ||
242行目: | 360行目: | ||
<span style="background-color:#e7f2fa;color:#2980b9;">void lv_fs_drv_init(lv_fs_drv_t *drv) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_fs_drv_init(lv_fs_drv_t *drv) </span> | ||
− | : Initialize a file system driver with default values. It is used to surly have known values in the fields ant not memory junk. After it you can set the fields. | + | : Initialize a file system driver with default values. |
− | : '''Parameters''' | + | : It is used to surly have known values in the fields ant not memory junk. |
− | :: drv -- pointer to driver variable to initialize | + | : After it you can set the fields. |
+ | : | ||
+ | :'''Parameters''' | ||
+ | :: '''drv''' -- pointer to driver variable to initialize | ||
<span style="background-color:#e7f2fa;color:#2980b9;">void lv_fs_drv_register(lv_fs_drv_t *drv) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_fs_drv_register(lv_fs_drv_t *drv) </span> | ||
: Add a new drive | : Add a new drive | ||
− | : Parameters | + | : '''Parameters''' |
− | :: 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. | + | :: '''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. | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_drv_t *lv_fs_get_drv(char letter) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_drv_t *lv_fs_get_drv(char letter) </span> | ||
: Give a pointer to a driver from its letter | : Give a pointer to a driver from its letter | ||
− | : Parameters | + | : '''Parameters''' |
− | :: letter -- the driver letter | + | :: '''letter''' -- the driver letter |
− | : Returns | + | : '''Returns''' |
:: pointer to a driver or NULL if not found | :: pointer to a driver or NULL if not found | ||
<span style="background-color:#e7f2fa;color:#2980b9;">bool lv_fs_is_ready(char letter) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">bool lv_fs_is_ready(char letter) </span> | ||
: Test if a drive is ready or not. If the <code style="color: #bb0000;">ready</code> function was not initialized <code style="color: #bb0000;">true</code> will be returned. | : Test if a drive is ready or not. If the <code style="color: #bb0000;">ready</code> function was not initialized <code style="color: #bb0000;">true</code> will be returned. | ||
− | : Parameters | + | : '''Parameters''' |
− | :: letter -- letter of the drive | + | :: '''letter''' -- letter of the drive |
− | : Returns | + | : '''Returns''' |
− | :: true: drive is ready; false: drive is not ready | + | :: '''true''': drive is ready; false: drive is not ready |
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_open(lv_fs_file_t *file_p, const char *path, lv_fs_mode_t mode) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_open(lv_fs_file_t *file_p, const char *path, lv_fs_mode_t mode) </span> | ||
: Open a file | : Open a file | ||
− | : Parameters | + | : '''Parameters''' |
− | ::* file_p -- pointer to a lv_fs_file_t variable | + | ::* '''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) | + | ::* '''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 | + | ::* '''mode''' -- read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_close(lv_fs_file_t *file_p) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_close(lv_fs_file_t *file_p) </span> | ||
: Close an already opened file | : Close an already opened file | ||
− | : Parameters | + | : '''Parameters''' |
− | :: file_p -- pointer to a lv_fs_file_t variable | + | :: '''file_p''' -- pointer to a lv_fs_file_t variable |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_read(lv_fs_file_t *file_p, void *buf, uint32_t btr, uint32_t *br) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_read(lv_fs_file_t *file_p, void *buf, uint32_t btr, uint32_t *br) </span> | ||
: Read from a file | : Read from a file | ||
− | : Parameters | + | : '''Parameters''' |
− | ::* file_p -- pointer to a lv_fs_file_t variable | + | ::* '''file_p''' -- pointer to a lv_fs_file_t variable |
− | ::* buf -- pointer to a buffer where the read bytes are stored | + | ::* '''buf''' -- pointer to a buffer where the read bytes are stored |
− | ::* btr -- Bytes To Read | + | ::* '''btr''' -- Bytes To Read |
− | ::* br -- the number of real read bytes (Bytes Read). NULL if unused. | + | ::* '''br''' -- the number of real read bytes (Bytes Read). NULL if unused. |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_write(lv_fs_file_t *file_p, const void *buf, uint32_t btw, uint32_t *bw) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_write(lv_fs_file_t *file_p, const void *buf, uint32_t btw, uint32_t *bw) </span> | ||
: Write into a file | : Write into a file | ||
− | : Parameters | + | : '''Parameters''' |
− | ::* file_p -- pointer to a lv_fs_file_t variable | + | ::* '''file_p''' -- pointer to a lv_fs_file_t variable |
− | ::* buf -- pointer to a buffer with the bytes to write | + | ::* '''buf''' -- pointer to a buffer with the bytes to write |
− | ::* btr -- Bytes To Write | + | ::* '''btr''' -- Bytes To Write |
− | ::* br -- the number of real written bytes (Bytes Written). NULL if unused. | + | ::* '''br''' -- the number of real written bytes (Bytes Written). NULL if unused. |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_seek(lv_fs_file_t *file_p, uint32_t pos, lv_fs_whence_t whence) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_seek(lv_fs_file_t *file_p, uint32_t pos, lv_fs_whence_t whence) </span> | ||
: Set the position of the 'cursor' (read write pointer) in a file | : Set the position of the 'cursor' (read write pointer) in a file | ||
− | : Parameters | + | : '''Parameters''' |
− | ::* file_p -- pointer to a lv_fs_file_t variable | + | ::* '''file_p''' -- pointer to a lv_fs_file_t variable |
− | ::* pos -- the new position expressed in bytes index (0: start of file) | + | ::* '''pos''' -- the new position expressed in bytes index (0: start of file) |
− | ::* whence -- tells from where set the position. See @lv_fs_whence_t | + | ::* '''whence''' -- tells from where set the position. See @lv_fs_whence_t |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_tell(lv_fs_file_t *file_p, uint32_t *pos) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_tell(lv_fs_file_t *file_p, uint32_t *pos) </span> | ||
: Give the position of the read write pointer | : Give the position of the read write pointer | ||
− | : Parameters | + | : '''Parameters''' |
− | ::* file_p -- pointer to a lv_fs_file_t variable | + | ::* '''file_p''' -- pointer to a lv_fs_file_t variable |
− | ::* pos_p -- pointer to store the position of the read write pointer | + | ::* '''pos_p''' -- pointer to store the position of the read write pointer |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from 'fs_res_t' | :: LV_FS_RES_OK or any error from 'fs_res_t' | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t *rddir_p, const char *path) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t *rddir_p, const char *path) </span> | ||
: Initialize a 'fs_dir_t' variable for directory reading | : Initialize a 'fs_dir_t' variable for directory reading | ||
− | : Parameters | + | : '''Parameters''' |
− | ::* rddir_p -- pointer to a 'lv_fs_dir_t' variable | + | ::* '''rddir_p''' -- pointer to a 'lv_fs_dir_t' variable |
− | ::* path -- path to a directory | + | ::* '''path''' -- path to a directory |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t *rddir_p, char *fn) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t *rddir_p, char *fn) </span> | ||
: Read the next filename form a directory. The name of the directories will begin with '/' | : Read the next filename form a directory. The name of the directories will begin with '/' | ||
− | : Parameters | + | : '''Parameters''' |
− | ::* rddir_p -- pointer to an initialized 'fs_dir_t' variable | + | ::* '''rddir_p''' -- pointer to an initialized 'fs_dir_t' variable |
− | ::* fn -- pointer to a buffer to store the filename | + | ::* '''fn''' -- pointer to a buffer to store the filename |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t *rddir_p) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t *rddir_p) </span> | ||
: Close the directory reading | : Close the directory reading | ||
− | : Parameters | + | : '''Parameters''' |
− | :: rddir_p -- pointer to an initialized 'fs_dir_t' variable | + | :: '''rddir_p''' -- pointer to an initialized 'fs_dir_t' variable |
− | : Returns | + | : '''Returns''' |
:: LV_FS_RES_OK or any error from lv_fs_res_t enum | :: LV_FS_RES_OK or any error from lv_fs_res_t enum | ||
<span style="background-color:#e7f2fa;color:#2980b9;">char *lv_fs_get_letters(char *buf) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">char *lv_fs_get_letters(char *buf) </span> | ||
: Fill a buffer with the letters of existing drivers | : Fill a buffer with the letters of existing drivers | ||
− | : Parameters | + | : '''Parameters''' |
− | :: buf -- buffer to store the letters ('\0' added after the last letter) | + | :: '''buf''' -- buffer to store the letters ('\0' added after the last letter) |
− | : Returns | + | : '''Returns''' |
:: the buffer | :: the buffer | ||
<span style="background-color:#e7f2fa;color:#2980b9;">const char *lv_fs_get_ext(const char *fn) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">const char *lv_fs_get_ext(const char *fn) </span> | ||
: Return with the extension of the filename | : Return with the extension of the filename | ||
− | : Parameters | + | : '''Parameters''' |
− | :: fn -- string with a filename | + | :: '''fn''' -- string with a filename |
− | : Returns | + | : '''Returns''' |
:: pointer to the beginning extension or empty string if no extension | :: pointer to the beginning extension or empty string if no extension | ||
<span style="background-color:#e7f2fa;color:#2980b9;">char *lv_fs_up(char *path) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">char *lv_fs_up(char *path) </span> | ||
: Step up one level | : Step up one level | ||
− | : Parameters | + | : '''Parameters''' |
− | :: path -- pointer to a file name | + | :: '''path''' -- pointer to a file name |
− | : Returns | + | : '''Returns''' |
:: the truncated file name | :: the truncated file name | ||
<span style="background-color:#e7f2fa;color:#2980b9;">const char *lv_fs_get_last(const char *path) </span> | <span style="background-color:#e7f2fa;color:#2980b9;">const char *lv_fs_get_last(const char *path) </span> | ||
: Get the last element of a path (e.g. U:/folder/file -> file) | : Get the last element of a path (e.g. U:/folder/file -> file) | ||
− | : Parameters | + | : '''Parameters''' |
− | :: path -- pointer to a file name | + | :: '''path''' -- pointer to a file name |
− | : Returns | + | : '''Returns''' |
:: pointer to the beginning of the last element in the path | :: pointer to the beginning of the last element in the path | ||
2022年7月2日 (土) 10:36時点における版
https://docs.lvgl.io/8.2/overview/file-system.html
File system
英文 | 自動翻訳 |
---|---|
LVGL has a 'File system' abstraction module that enables you to attach any type of file system. A file system is identified by an assigned drive letter. For example, if an SD card is associated with the letter |
LVGL has a 'File system' abstraction module that enables you to attach any type of file system.
A file system is identified by an assigned drive letter. For example, if an SD card is associated with the letter |
Ready to use drivers
英文 | 自動翻訳 |
---|---|
The lv_fs_if repository contains prepared drivers using POSIX, standard C and the FATFS API. See its README for the details. |
The lv_fs_if repository contains prepared drivers using POSIX, standard C and the FATFS API.
See its README for the details. |
Adding a driver
Registering a driver
英文 | 自動翻訳 |
---|---|
To add a driver, a The static lv_fs_drv_t drv; /*Needs to be static or global*/
lv_fs_drv_init(&drv); /*Basic initialization*/
drv.letter = 'S'; /*An uppercase letter to identify the drive */
drv.cache_size = my_cahce_size; /*Cache size for reading in bytes. 0 to not cache.*/
drv.ready_cb = my_ready_cb; /*Callback to tell if the drive is ready to use */
drv.open_cb = my_open_cb; /*Callback to open a file */
drv.close_cb = my_close_cb; /*Callback to close a file */
drv.read_cb = my_read_cb; /*Callback to read a file */
drv.write_cb = my_write_cb; /*Callback to write a file */
drv.seek_cb = my_seek_cb; /*Callback to seek in a file (Move cursor) */
drv.tell_cb = my_tell_cb; /*Callback to tell the cursor position */
drv.dir_open_cb = my_dir_open_cb; /*Callback to open directory to read its content */
drv.dir_read_cb = my_dir_read_cb; /*Callback to read a directory's content */
drv.dir_close_cb = my_dir_close_cb; /*Callback to close a directory */
drv.user_data = my_user_data; /*Any custom data if required*/
lv_fs_drv_register(&drv); /*Finally register the drive*/
Any of the callbacks can be |
To add a driver, a lv_fs_drv_t needs to be initialized like below.
The static lv_fs_drv_t drv; /*Needs to be static or global*/
lv_fs_drv_init(&drv); /*Basic initialization*/
drv.letter = 'S'; /*An uppercase letter to identify the drive */
drv.cache_size = my_cahce_size; /*Cache size for reading in bytes. 0 to not cache.*/
drv.ready_cb = my_ready_cb; /*Callback to tell if the drive is ready to use */
drv.open_cb = my_open_cb; /*Callback to open a file */
drv.close_cb = my_close_cb; /*Callback to close a file */
drv.read_cb = my_read_cb; /*Callback to read a file */
drv.write_cb = my_write_cb; /*Callback to write a file */
drv.seek_cb = my_seek_cb; /*Callback to seek in a file (Move cursor) */
drv.tell_cb = my_tell_cb; /*Callback to tell the cursor position */
drv.dir_open_cb = my_dir_open_cb; /*Callback to open directory to read its content */
drv.dir_read_cb = my_dir_read_cb; /*Callback to read a directory's content */
drv.dir_close_cb = my_dir_close_cb; /*Callback to close a directory */
drv.user_data = my_user_data; /*Any custom data if required*/
lv_fs_drv_register(&drv); /*Finally register the drive*/
Any of the callbacks can be |
Implementing the callbacks
Open callback
英文 | 自動翻訳 |
---|---|
The prototype of void * (*open_cb)(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode);
The return value is a pointer to a file object that describes the opened file or The returned file object will be passed to other file system related callbacks. (see below) |
The prototype of open_cb looks like this:
void * (*open_cb)(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode);
The return value is a pointer to a file object that describes the opened file or The returned file object will be passed to other file system related callbacks. (see below) |
Other callbacks
英文 | 自動翻訳 |
---|---|
The other callbacks are quite similar. For example lv_fs_res_t (*write_cb)(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
For For a template of these callbacks see lv_fs_template.c. |
The other callbacks are quite similar.
For example lv_fs_res_t (*write_cb)(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
For For a template of these callbacks see lv_fs_template.c. |
Usage example
英文 | 自動翻訳 |
---|---|
The example below shows how to read from a file: lv_fs_file_t f;
lv_fs_res_t res;
res = lv_fs_open(&f, "S:folder/file.txt", LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) my_error_handling();
uint32_t read_num;
uint8_t buf[8];
res = lv_fs_read(&f, buf, 8, &read_num);
if(res != LV_FS_RES_OK || read_num != 8) my_error_handling();
lv_fs_close(&f);
The mode in This example shows how to read a directory's content. It's up to the driver how to mark directories in the result but it can be a good practice to insert a lv_fs_dir_t dir;
lv_fs_res_t res;
res = lv_fs_dir_open(&dir, "S:/folder");
if(res != LV_FS_RES_OK) my_error_handling();
char fn[256];
while(1) {
res = lv_fs_dir_read(&dir, fn);
if(res != LV_FS_RES_OK) {
my_error_handling();
break;
}
/*fn is empty, if not more files to read*/
if(strlen(fn) == 0) {
break;
}
printf("%s\n", fn);
}
lv_fs_dir_close(&dir);
|
The example below shows how to read from a file:
lv_fs_file_t f;
lv_fs_res_t res;
res = lv_fs_open(&f, "S:folder/file.txt", LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) my_error_handling();
uint32_t read_num;
uint8_t buf[8];
res = lv_fs_read(&f, buf, 8, &read_num);
if(res != LV_FS_RES_OK || read_num != 8) my_error_handling();
lv_fs_close(&f);
The mode in This example shows how to read a directory's content. It's up to the driver how to mark directories in the result but it can be a good practice to insert a lv_fs_dir_t dir;
lv_fs_res_t res;
res = lv_fs_dir_open(&dir, "S:/folder");
if(res != LV_FS_RES_OK) my_error_handling();
char fn[256];
while(1) {
res = lv_fs_dir_read(&dir, fn);
if(res != LV_FS_RES_OK) {
my_error_handling();
break;
}
/*fn is empty, if not more files to read*/
if(strlen(fn) == 0) {
break;
}
printf("%s\n", fn);
}
lv_fs_dir_close(&dir);
|
Use drives for images
英文 | 自動翻訳 |
---|---|
Image objects can be opened from files too (besides variables stored in the compiled program).
|
Image objects can be opened from files too (besides variables stored in the compiled program).
|
API
英文 | 自動翻訳 |
---|---|
Typedefs typedef uint8_t lv_fs_res_t typedef uint8_t lv_fs_mode_t typedef struct _lv_fs_drv_t lv_fs_drv_t Enums enum [anonymous]
enum [anonymous]
enum lv_fs_whence_t
Functions void _lv_fs_init(void)
void lv_fs_drv_init(lv_fs_drv_t *drv)
void lv_fs_drv_register(lv_fs_drv_t *drv)
lv_fs_drv_t *lv_fs_get_drv(char letter)
bool lv_fs_is_ready(char letter)
lv_fs_res_t lv_fs_open(lv_fs_file_t *file_p, const char *path, lv_fs_mode_t mode)
lv_fs_res_t lv_fs_close(lv_fs_file_t *file_p)
lv_fs_res_t lv_fs_read(lv_fs_file_t *file_p, void *buf, uint32_t btr, uint32_t *br)
lv_fs_res_t lv_fs_write(lv_fs_file_t *file_p, const void *buf, uint32_t btw, uint32_t *bw)
lv_fs_res_t lv_fs_seek(lv_fs_file_t *file_p, uint32_t pos, lv_fs_whence_t whence)
lv_fs_res_t lv_fs_tell(lv_fs_file_t *file_p, uint32_t *pos)
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t *rddir_p, const char *path)
lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t *rddir_p, char *fn)
lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t *rddir_p)
char *lv_fs_get_letters(char *buf)
const char *lv_fs_get_ext(const char *fn)
char *lv_fs_up(char *path)
const char *lv_fs_get_last(const char *path)
struct _lv_fs_drv_t
struct lv_fs_file_cache_t
struct lv_fs_file_t
struct lv_fs_dir_t
|