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
60
61
62
63
64
use crate::sys::*;

pub struct Configuration {
    pub max_files: u32,
    pub format_if_mount_failed: bool,
    pub allocation_unit_size: usize,
    #[cfg(not(esp_idf_version_major = "4",))] // For ESP-IDF v5.0 and later
    pub disk_status_check_enable: bool,
    #[cfg(not(any(
        esp_idf_version_major = "4",
        all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
        all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
        all(esp_idf_version_major = "5", esp_idf_version_minor = "2"),
    )))] // ESP-IDF 5.3 and later
    pub use_one_fat: bool,
}

impl Default for Configuration {
    fn default() -> Self {
        Self::new()
    }
}

impl Configuration {
    pub const fn new() -> Self {
        Self {
            max_files: 4,
            format_if_mount_failed: false,
            allocation_unit_size: 16 * 1024,
            #[cfg(not(
                esp_idf_version_major = "4",
            ))] // For ESP-IDF v5.0 and later
            disk_status_check_enable: false,
            #[cfg(not(any(
                esp_idf_version_major = "4",
                all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
                all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
                all(esp_idf_version_major = "5", esp_idf_version_minor = "2"),
            )))] // ESP-IDF 5.3 and later
            use_one_fat: false,
        }
    }
}

impl From<Configuration> for esp_vfs_fat_mount_config_t {
    fn from(config: Configuration) -> Self {
        esp_vfs_fat_mount_config_t {
            max_files: config.max_files as i32,
            format_if_mount_failed: config.format_if_mount_failed,
            allocation_unit_size: config.allocation_unit_size,
            #[cfg(not(
                esp_idf_version_major = "4",
            ))] // For ESP-IDF v5.0 and later
            disk_status_check_enable: config.disk_status_check_enable,
            #[cfg(not(any(
                esp_idf_version_major = "4",
                all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
                all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
                all(esp_idf_version_major = "5", esp_idf_version_minor = "2"),
            )))] // ESP-IDF 5.3 and later
            use_one_fat: config.use_one_fat,
        }
    }
}