menu "FAT Filesystem support"

    config FATFS_VOLUME_COUNT
        int "Number of volumes"
        default 2
        range 1 10
        help
            Number of volumes (logical drives) to use.

    choice FATFS_LONG_FILENAMES
        prompt "Long filename support"
        default FATFS_LFN_NONE
        help
            Support long filenames in FAT. Long filename data increases
            memory usage. FATFS can be configured to store the buffer for
            long filename data in stack or heap.

        config FATFS_LFN_NONE
            bool "No long filenames"
        config FATFS_LFN_HEAP
            bool "Long filename buffer in heap"
        config FATFS_LFN_STACK
            bool "Long filename buffer on stack"
    endchoice
    choice FATFS_SECTOR_SIZE
        prompt "Sector size"
        default FATFS_SECTOR_4096
        help
            Specify the size of the sector in bytes for FATFS partition generator.

        config FATFS_SECTOR_512
            bool "512"
        config FATFS_SECTOR_4096
            bool "4096"
    endchoice
    choice FATFS_CHOOSE_CODEPAGE
        prompt "OEM Code Page"
        default FATFS_CODEPAGE_437
        help
            OEM code page used for file name encodings.

            If "Dynamic" is selected, code page can be chosen at runtime using
            f_setcp function. Note that choosing this option will increase
            application size by ~480kB.

        config FATFS_CODEPAGE_DYNAMIC
            bool "Dynamic (all code pages supported)"
        config FATFS_CODEPAGE_437
            bool "US (CP437)"
        config FATFS_CODEPAGE_720
            bool "Arabic (CP720)"
        config FATFS_CODEPAGE_737
            bool "Greek (CP737)"
        config FATFS_CODEPAGE_771
            bool "KBL (CP771)"
        config FATFS_CODEPAGE_775
            bool "Baltic (CP775)"
        config FATFS_CODEPAGE_850
            bool "Latin 1 (CP850)"
        config FATFS_CODEPAGE_852
            bool "Latin 2 (CP852)"
        config FATFS_CODEPAGE_855
            bool "Cyrillic (CP855)"
        config FATFS_CODEPAGE_857
            bool "Turkish (CP857)"
        config FATFS_CODEPAGE_860
            bool "Portugese (CP860)"
        config FATFS_CODEPAGE_861
            bool "Icelandic (CP861)"
        config FATFS_CODEPAGE_862
            bool "Hebrew (CP862)"
        config FATFS_CODEPAGE_863
            bool "Canadian French (CP863)"
        config FATFS_CODEPAGE_864
            bool "Arabic (CP864)"
        config FATFS_CODEPAGE_865
            bool "Nordic (CP865)"
        config FATFS_CODEPAGE_866
            bool "Russian (CP866)"
        config FATFS_CODEPAGE_869
            bool "Greek 2 (CP869)"
        config FATFS_CODEPAGE_932
            bool "Japanese (DBCS) (CP932)"
        config FATFS_CODEPAGE_936
            bool "Simplified Chinese (DBCS) (CP936)"
        config FATFS_CODEPAGE_949
            bool "Korean (DBCS) (CP949)"
        config FATFS_CODEPAGE_950
            bool "Traditional Chinese (DBCS) (CP950)"

    endchoice
    config FATFS_CODEPAGE
        int
        default 0 if FATFS_CODEPAGE_DYNAMIC
        default 437 if FATFS_CODEPAGE_437
        default 720 if FATFS_CODEPAGE_720
        default 737 if FATFS_CODEPAGE_737
        default 771 if FATFS_CODEPAGE_771
        default 775 if FATFS_CODEPAGE_775
        default 850 if FATFS_CODEPAGE_850
        default 852 if FATFS_CODEPAGE_852
        default 855 if FATFS_CODEPAGE_855
        default 857 if FATFS_CODEPAGE_857
        default 860 if FATFS_CODEPAGE_860
        default 861 if FATFS_CODEPAGE_861
        default 862 if FATFS_CODEPAGE_862
        default 863 if FATFS_CODEPAGE_863
        default 864 if FATFS_CODEPAGE_864
        default 865 if FATFS_CODEPAGE_865
        default 866 if FATFS_CODEPAGE_866
        default 869 if FATFS_CODEPAGE_869
        default 932 if FATFS_CODEPAGE_932
        default 936 if FATFS_CODEPAGE_936
        default 949 if FATFS_CODEPAGE_949
        default 950 if FATFS_CODEPAGE_950
        default 437

    config FATFS_MAX_LFN
        int "Max long filename length"
        depends on !FATFS_LFN_NONE
        default 255
        range 12 255
        help
            Maximum long filename length. Can be reduced to save RAM.

    choice FATFS_API_ENCODING
        prompt "API character encoding"
        depends on !FATFS_LFN_NONE
        default FATFS_API_ENCODING_ANSI_OEM
        help
            Choose encoding for character and string arguments/returns when using
            FATFS APIs. The encoding of arguments will usually depend on text
            editor settings.

        config FATFS_API_ENCODING_ANSI_OEM
            bool "API uses ANSI/OEM encoding"
        config FATFS_API_ENCODING_UTF_8
            bool "API uses UTF-8 encoding"
    endchoice

    config FATFS_FS_LOCK
        int "Number of simultaneously open files protected by lock function"
        default 0
        range 0 65535
        help
            This option sets the FATFS configuration value _FS_LOCK.
            The option _FS_LOCK switches file lock function to control duplicated file open
            and illegal operation to open objects.

            * 0: Disable file lock function. To avoid volume corruption, application
            should avoid illegal open, remove and rename to the open objects.

            * >0: Enable file lock function. The value defines how many files/sub-directories
            can be opened simultaneously under file lock control.

            Note that the file lock control is independent of re-entrancy.

    config FATFS_TIMEOUT_MS
        int "Timeout for acquiring a file lock, ms"
        default 10000
        help
            This option sets FATFS configuration value _FS_TIMEOUT, scaled to milliseconds.
            Sets the number of milliseconds FATFS will wait to acquire a mutex when
            operating on an open file. For example, if one task is performing a lenghty
            operation, another task will wait for the first task to release the lock,
            and time out after amount of time set by this option.


    config FATFS_PER_FILE_CACHE
        bool "Use separate cache for each file"
        default y
        help
            This option affects FATFS configuration value _FS_TINY.

            If this option is set, _FS_TINY is 0, and each open file has its own cache,
            size of the cache is equal to the _MAX_SS variable (512 or 4096 bytes).
            This option uses more RAM if more than 1 file is open, but needs less reads
            and writes to the storage for some operations.

            If this option is not set, _FS_TINY is 1, and single cache is used for
            all open files, size is also equal to _MAX_SS variable. This reduces the
            amount of heap used when multiple files are open, but increases the number
            of read and write operations which FATFS needs to make.


    config FATFS_ALLOC_PREFER_EXTRAM
        bool "Perfer external RAM when allocating FATFS buffers"
        default y
        depends on SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC
        help
            When the option is enabled, internal buffers used by FATFS will be allocated
            from external RAM. If the allocation from external RAM fails, the buffer will
            be allocated from the internal RAM.
            Disable this option if optimizing for performance. Enable this option if
            optimizing for internal memory size.


    config FATFS_USE_FASTSEEK
        bool "Enable fast seek algorithm when using lseek function through VFS FAT"
        default n
        help
            The fast seek feature enables fast backward/long seek operations without
            FAT access by using an in-memory CLMT (cluster link map table).
            Please note, fast-seek is only allowed for read-mode files, if a
            file is opened in write-mode, the seek mechanism will automatically fallback
            to the default implementation.


    config FATFS_FAST_SEEK_BUFFER_SIZE
        int "Fast seek CLMT buffer size"
        default 64
        depends on FATFS_USE_FASTSEEK
        help
            If fast seek algorithm is enabled, this defines the size of
            CLMT buffer used by this algorithm in 32-bit word units.
            This value should be chosen based on prior knowledge of
            maximum elements of each file entry would store.

    config FATFS_VFS_FSTAT_BLKSIZE
        int "Default block size"
        default 0
        help
            If set to 0, the 'newlib' library's default size (BLKSIZ) is used (128 B).
            If set to a non-zero value, the value is used as the block size.
            Default file buffer size is set to this value
            and the buffer is allocated when first attempt of reading/writing to a file is made.
            Increasing this value improves fread() speed, however the heap usage is increased as well.

            NOTE: The block size value is shared by all the filesystem functions
            accessing target media for given file descriptor!
            See 'Improving I/O performance' section of 'Maximizing Execution Speed' documentation page
            for more details.
endmenu
