「App:Library:LVGL:docs:Overview:File system」の版間の差分
(→API) |
(→API) |
||
12行目: | 12行目: | ||
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>. | 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には'File system'抽象化モジュールがあり、任意の種類のファイルシステムをアタッチすることができます。 |
+ | ファイルシステムは、ドライブレターで識別されます。 | ||
− | + | 例えば、SDカードに<code style="color: #bb0000;">'S'</code>という文字が割り当てられている場合、<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]] | ||
30行目: | 29行目: | ||
See its README for the details. | See its README for the details. | ||
− | | | + | |lv_fs_ifリポジトリには、POSIX、標準C、FATFS APIを使用したドライバが用意されています。 |
− | + | 詳しくはREADMEをご覧ください。 | |
− | |||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
71行目: | 69行目: | ||
</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. | ||
− | | | + | |ドライバを追加するには、以下のように<code style="color: #bb0000;">lv_fs_drv_t</code> を初期化する必要があります。 |
− | + | <code style="color: #bb0000;">lv_fs_drv_t</code> は、ローカル変数ではなく、スタティック、グローバル、またはダイナミックにアロケートされたものである必要があります。<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*/ | ||
lv_fs_drv_init(&drv); /*Basic initialization*/ | lv_fs_drv_init(&drv); /*Basic initialization*/ | ||
96行目: | 93行目: | ||
lv_fs_drv_register(&drv); /*Finally register the drive*/ | lv_fs_drv_register(&drv); /*Finally register the drive*/ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | コールバックのいずれかを<code style="color: #bb0000;">NULL</code>にすることで、操作がサポートされていないことを示すことができる。 | |
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
117行目: | 114行目: | ||
The returned file object will be passed to other file system related callbacks. (see below) | The returned file object will be passed to other file system related callbacks. (see below) | ||
− | | | + | |<code style="color: #bb0000;">open_cb</code>のプロトタイプは以下のようなものです。 |
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> | + | <code style="color: #bb0000;">path</code> はドライブレターの後のパスです (例: "S:path/to/file.txt" -> "path/to/file.txt"). |
− | <code style="color: #bb0000;">mode</code> | + | <code style="color: #bb0000;">mode</code> には <code style="color: #bb0000;">LV_FS_MODE_WR</code> または <code style="color: #bb0000;">LV_FS_MODE_RD</code> を指定し、書き込みまたは読み出し用にオープンすることができます。 |
− | + | 戻り値は、オープンしたファイルを記述したファイルオブジェクトへのポインタ、または何らかの問題(ファイルが見つからなかったなど)があった場合は<code style="color: #bb0000;">NULL</code> です。 | |
− | + | 返されたファイルオブジェクトは、他のファイルシステム関連のコールバック関数に渡されます。(下記参照) | |
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
138行目: | 135行目: | ||
The other callbacks are quite similar. | The other callbacks are quite similar. | ||
− | For example | + | For example 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); | ||
</syntaxhighlight> | </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 <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. | For a template of these callbacks see lv_fs_template.c. | ||
− | | | + | |他のコールバックは非常によく似ています。 |
− | + | 例えば<code style="color: #bb0000;">write_cb</code> は以下のような感じです。<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); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | <code style="color: #bb0000;">file_p</code>には、LVGLは<code style="color: #bb0000;">open_cb</code>の戻り値を渡し、 | |
− | + | <code style="color: #bb0000;">buf</code>は書き込むデータ、 | |
+ | |||
+ | <code style="color: #bb0000;">btw</code> は書き込むバイト数、 | ||
+ | |||
+ | <code style="color: #bb0000;">bw</code>は実際に書き込んだバイト数です。 | ||
+ | |||
+ | これらのコールバックのテンプレートは,lv_fs_template.cを参照してください. | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview#File_system|戻る : Previous]] | ||
206行目: | 214行目: | ||
lv_fs_dir_close(&dir); | lv_fs_dir_close(&dir); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | | | + | |以下の例では、ファイルから読み取る方法を示しています。 |
<syntaxhighlight lang="C++" style="border:1px dashed gray;"> | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
lv_fs_file_t f; | lv_fs_file_t f; | ||
220行目: | 228行目: | ||
lv_fs_close(&f); | lv_fs_close(&f); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | '' | + | ''<code style="color: #bb0000;">lv_fs_open</code>'' のモードは,書き込み専用なら''<code style="color: #bb0000;">LV_FS_MODE_WR</code>'' ,両方なら''<code style="color: #bb0000;">LV_FS_MODE_RD | LV_FS_MODE_WR</code>''を指定することができます。 |
− | + | この例は、ディレクトリの内容を読み取る方法を示しています。 | |
− | + | 結果の中でディレクトリをどのようにマークするかはドライバ次第ですが、各ディレクトリ名の前に<code style="color: #bb0000;">'/'</code>を挿入するのは良い習慣と言えるでしょう。<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; | ||
lv_fs_res_t res; | lv_fs_res_t res; | ||
271行目: | 278行目: | ||
* seek | * seek | ||
* tell | * tell | ||
− | | | + | |画像オブジェクトはファイルからも開くことができます(コンパイルされたプログラムに格納されている変数を除く)。 |
− | + | 画像ウィジェットでファイルを使用するには、次のコールバックが必要です。 | |
* open | * open | ||
353行目: | 360行目: | ||
: <span style="background-color: #eeeeee;">enumerator LV_FS_SEEK_END </span> | : <span style="background-color: #eeeeee;">enumerator LV_FS_SEEK_END </span> | ||
:: Set the position from the end of the file | :: Set the position from the end of the file | ||
− | | | + | |'''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_mode_t </span> | ||
+ | : | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">typedef struct _lv_fs_drv_t lv_fs_drv_t </span> | ||
+ | : | ||
+ | |||
+ | '''Enums''' | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">enum [anonymous] </span> | ||
+ | : ファイルシステムモジュールのエラー。 | ||
+ | :'''''Values:''''' | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_OK </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_HW_ERR </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_FS_ERR </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_NOT_EX </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_FULL </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_LOCKED </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_DENIED </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_BUSY </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_TOUT </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_NOT_IMP </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_OUT_OF_MEM </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_INV_PARAM </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_RES_UNKNOWN </span> | ||
+ | :: | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">enum [anonymous] </span> | ||
+ | : File open mode. | ||
+ | :'''''Values:''''' | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_MODE_WR </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_MODE_RD </span> | ||
+ | :: | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">enum lv_fs_whence_t </span> | ||
+ | : シークモード。 | ||
+ | :'''''Values:''''' | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_SEEK_SET </span> | ||
+ | :: 位置を絶対位置 (ファイルの先頭から) から設定 | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_SEEK_CUR </span> | ||
+ | :: 現在の位置からの位置を設定します | ||
+ | :<span style="background-color: #eeeeee;">enumerator LV_FS_SEEK_END </span> | ||
+ | :: ファイルの末尾からの位置を設定する | ||
|- | |- | ||
| | | | ||
549行目: | 615行目: | ||
:: | :: | ||
: <span style="background-color: #eeeeee;">lv_fs_drv_t *drv</span> | : <span style="background-color: #eeeeee;">lv_fs_drv_t *drv</span> | ||
− | | | + | |'''Functions''' |
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void _lv_fs_init(void) </span> | ||
+ | : ファイル・システム・インタフェースの初期化 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_fs_drv_init(lv_fs_drv_t *drv) </span> | ||
+ | : ファイルシステムドライバーを既定値で初期化します。 これは、メモリのジャンクではなく、フィールドの既知の値を持つために使用されます。 その後、フィールドを設定できます。 | ||
+ | : | ||
+ | :'''Parameters''' | ||
+ | ::'''drv''' -- 初期化するドライバ変数へのポインタ | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_fs_drv_register(lv_fs_drv_t *drv) </span> | ||
+ | : 新しいドライブを追加する | ||
+ | :'''Parameters''' | ||
+ | ::'''drv''' -- lv_fs_drv_t構造体へのポインタで、対応する関数ポインタで初期化される。 ポインターのみが保存されるため、ドライバーは静的または動的に割り当てられる必要があります。 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_drv_t *lv_fs_get_drv(char letter) </span> | ||
+ | : 文字からドライバーへのポインターを指定します。 | ||
+ | :'''Parameters''' | ||
+ | ::'''letter''' -- 運転手の手紙 | ||
+ | :'''Returns''' | ||
+ | :: ドライバへのポインタ、見つからない場合はNULL | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">bool lv_fs_is_ready(char letter) </span> | ||
+ | : ドライブの準備ができているかどうかをテストします。<code style="color: #bb0000;">ready</code> 関数が初期化されていない場合は、 <code style="color: #bb0000;">true</code> が返されます。 | ||
+ | :'''Parameters''' | ||
+ | ::'''letter''' -- ドライブの文字 | ||
+ | :'''Returns''' | ||
+ | ::'''true''':ドライブの準備ができました;false:ドライブの準備ができていません | ||
+ | |||
+ | <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> | ||
+ | : ファイルを開く | ||
+ | :'''Parameters''' | ||
+ | ::*'''file_p''' -- lv_fs_file_t変数へのポインタ | ||
+ | |||
+ | ::*'''path''' -- ドライバー文字で始まるファイルへのパス (例: S:/folder/file.txt) | ||
+ | ::*'''mode''' -- read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたはlv_fs_res_tenumからのエラー | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_close(lv_fs_file_t *file_p) </span> | ||
+ | : 既に開いているファイルを閉じる | ||
+ | :'''Parameters''' | ||
+ | ::'''file_p''' -- lv_fs_file_t変数へのポインタ | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OK または 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> | ||
+ | : ファイルから読み取る | ||
+ | :'''Parameters''' | ||
+ | ::*'''file_p''' -- lv_fs_file_t変数へのポインタ | ||
+ | ::*'''buf''' -- 読み込んだバイトを格納するバッファへのポインタ | ||
+ | ::*'''btr''' -- 読み取るバイト数 | ||
+ | ::*'''br''' -- 実際の読み取りバイト数(Bytes Read)。 未使用の場合はNULL。 | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたはlv_fs_res_tenumからのエラー | ||
+ | |||
+ | <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> | ||
+ | : ファイルに書き込む | ||
+ | :'''Parameters''' | ||
+ | ::*'''file_p''' -- lv_fs_file_t変数へのポインター | ||
+ | ::*'''buf''' -- 書き込むバイトを含むバッファへのポインタ | ||
+ | ::* '''btr''' -- 書き込むバイト数 | ||
+ | ::*'''br''' -- 実際に書き込まれたバイト数(書き込まれたバイト数)。 未使用の場合はNULL。 | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたはlv_fs_res_tenumからのエラー | ||
+ | |||
+ | <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> | ||
+ | : ファイル内の「カーソル」(読み取り/書き込みポインター)の位置を設定します | ||
+ | :'''Parameters''' | ||
+ | ::*'''file_p''' -- lv_fs_file_t変数へのポインター | ||
+ | ::*'''pos''' --バイトインデックスで表される新しい位置(0:ファイルの先頭) | ||
+ | ::*'''whence''' -- 位置を設定した場所を示します。 @lv_fs_whence_tを参照してください | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたはlv_fs_res_tenumからのエラー | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_tell(lv_fs_file_t *file_p, uint32_t *pos) </span> | ||
+ | : 読み取り/書き込みポインタの位置を指定します | ||
+ | :'''Parameters''' | ||
+ | ::*'''file_p''' -- lv_fs_file_t変数へのポインター | ||
+ | ::*'''pos_p''' -- 読み取り/書き込みポインタの位置を格納するポインタ | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたは「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> | ||
+ | : ディレクトリ読み取り用に「fs_dir_t」変数を初期化します | ||
+ | :'''Parameters''' | ||
+ | ::*'''rddir_p''' -- 'lv_fs_dir_t'変数へのポインター | ||
+ | ::*'''path''' -- ディレクトリへのパス | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたはlv_fs_res_tenumからのエラー | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t *rddir_p, char *fn) </span> | ||
+ | : ディレクトリから次のファイル名を読み取ります。 ディレクトリの名前は「/」で始まります | ||
+ | :'''Parameters''' | ||
+ | ::*'''rddir_p''' -- 初期化された'fs_dir_t'変数へのポインタ | ||
+ | ::*'''fn''' -- ファイル名を格納するためのバッファへのポインタ | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたはlv_fs_res_tenumからのエラー | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t *rddir_p) </span> | ||
+ | : ディレクトリの読み取りを閉じる | ||
+ | :'''Parameters''' | ||
+ | ::'''rddir_p''' -- 初期化された'fs_dir_t'変数へのポインタ | ||
+ | :'''Returns''' | ||
+ | :: LV_FS_RES_OKまたはlv_fs_res_tenumからのエラー | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">char *lv_fs_get_letters(char *buf) </span> | ||
+ | : 既存のドライバーの文字でバッファーを埋めます | ||
+ | :'''Parameters''' | ||
+ | ::'''buf''' -- 文字を格納するためのバッファ(最後の文字の後に「\ 0」が追加されます) | ||
+ | :'''Returns''' | ||
+ | :: バッファ | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">const char *lv_fs_get_ext(const char *fn) </span> | ||
+ | : ファイル名の拡張子を付けて返す | ||
+ | :'''Parameters''' | ||
+ | ::'''fn''' -- ファイル名のある文字列 | ||
+ | :'''Returns''' | ||
+ | :: 開始拡張子へのポインタ、または拡張子がない場合は空の文字列 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">char *lv_fs_up(char *path) </span> | ||
+ | : 1レベルステップアップ | ||
+ | :'''Parameters''' | ||
+ | ::'''path''' -- ファイル名へのポインタ | ||
+ | :'''Returns''' | ||
+ | :: 切り捨てられたファイル名 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">const char *lv_fs_get_last(const char *path) </span> | ||
+ | : パスの最後の要素を取得します(例: U:/folder/file -> file) | ||
+ | :'''Parameters''' | ||
+ | ::'''path''' -- ファイル名へのポインタ | ||
+ | :'''Returns''' | ||
+ | :: パスの最後の要素の先頭へのポインタ | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">struct _lv_fs_drv_t </span> | ||
+ | :'''Public Members''' | ||
+ | :<span style="background-color: #eeeeee;">char letter </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">uint16_t cache_size </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">bool (*ready_cb)(struct _lv_fs_drv_t *drv) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">void *(*open_cb)(struct _lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_res_t (*close_cb)(struct _lv_fs_drv_t *drv, void *file_p) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_res_t (*read_cb)(struct _lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_res_t (*write_cb)(struct _lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_res_t (*seek_cb)(struct _lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_res_t (*tell_cb)(struct _lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p) </span> | ||
+ | :: | ||
+ | : | ||
+ | :<span style="background-color: #eeeeee;">void *(*dir_open_cb)(struct _lv_fs_drv_t *drv, const char *path) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_res_t (*dir_read_cb)(struct _lv_fs_drv_t *drv, void *rddir_p, char *fn) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_res_t (*dir_close_cb)(struct _lv_fs_drv_t *drv, void *rddir_p) </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">void *user_data </span> | ||
+ | :: カスタムファイルのユーザーデータ | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">struct lv_fs_file_cache_t </span> | ||
+ | :'''Public Members''' | ||
+ | :<span style="background-color: #eeeeee;">uint32_t start </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">uint32_t end </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">uint32_t file_position </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">void *buffer </span> | ||
+ | :: | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">struct lv_fs_file_t </span> | ||
+ | :'''Public Members''' | ||
+ | :<span style="background-color: #eeeeee;">void *file_d </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_drv_t *drv </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_file_cache_t *cache </span> | ||
+ | :: | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">struct lv_fs_dir_t </span> | ||
+ | :'''Public Members''' | ||
+ | :<span style="background-color: #eeeeee;">void *dir_d </span> | ||
+ | :: | ||
+ | :<span style="background-color: #eeeeee;">lv_fs_drv_t *drv</span> | ||
|} | |} | ||
2022年7月2日 (土) 10:53時点における最新版
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には'File system'抽象化モジュールがあり、任意の種類のファイルシステムをアタッチすることができます。
ファイルシステムは、ドライブレターで識別されます。 例えば、SDカードに |
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. |
lv_fs_ifリポジトリには、POSIX、標準C、FATFS APIを使用したドライバが用意されています。
詳しくはREADMEをご覧ください。 |
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 |
ドライバを追加するには、以下のようにlv_fs_drv_t を初期化する必要があります。
lv_fs_drv_t は、ローカル変数ではなく、スタティック、グローバル、またはダイナミックにアロケートされたものである必要があります。 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*/
コールバックのいずれかを |
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) |
open_cb のプロトタイプは以下のようなものです。
void * (*open_cb)(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode);
戻り値は、オープンしたファイルを記述したファイルオブジェクトへのポインタ、または何らかの問題(ファイルが見つからなかったなど)があった場合は 返されたファイルオブジェクトは、他のファイルシステム関連のコールバック関数に渡されます。(下記参照) |
Other callbacks
英文 | 自動翻訳 |
---|---|
The other callbacks are quite similar. For example looks like this: 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. |
他のコールバックは非常によく似ています。
例えばwrite_cb は以下のような感じです。 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_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);
|
以下の例では、ファイルから読み取る方法を示しています。
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);
この例は、ディレクトリの内容を読み取る方法を示しています。 結果の中でディレクトリをどのようにマークするかはドライバ次第ですが、各ディレクトリ名の前に'/' を挿入するのは良い習慣と言えるでしょう。 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).
|
画像オブジェクトはファイルからも開くことができます(コンパイルされたプログラムに格納されている変数を除く)。
|
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
|
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
|
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
|