aboutsummaryrefslogtreecommitdiff
path: root/docs/libs/lfs.rst
blob: 89234aaba4c089215d30b816d1260d31f04da96f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
.. _lfs:

==============
littlefs
==============

littlefs is a little fail-safe filesystem designed for microcontrollers.

Detailed introduction: https://github.com/littlefs-project/littlefs


Usage
-----

Enable :c:macro:`LV_USE_FS_LITTLEFS` and define a :c:macro`LV_FS_LITTLEFS_LETTER` in ``lv_conf.h``.

When enabled :c:macro:`lv_littlefs_set_handler` can be used to set up a mount point.

Example
-------

.. code:: c
    #include "lfs.h"

    // configuration of the filesystem is provided by this struct
    const struct lfs_config cfg = {
        // block device operations
        .read  = user_provided_block_device_read,
        .prog  = user_provided_block_device_prog,
        .erase = user_provided_block_device_erase,
        .sync  = user_provided_block_device_sync,

        // block device configuration
        .read_size = 16,
        .prog_size = 16,
        .block_size = 4096,
        .block_count = 128,
        .cache_size = 16,
        .lookahead_size = 16,
        .block_cycles = 500,
    };

    // mount the filesystem
    int err = lfs_mount(&lfs, &cfg);

    // reformat if we can't mount the filesystem
    // this should only happen on the first boot
    if (err) {
        lfs_format(&lfs, &cfg);
        lfs_mount(&lfs, &cfg);
    }

    lv_littlefs_set_handler(&lfs);


API
---