espforge_lib/config/
project.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Debug, Deserialize, Serialize)]
5pub struct EspforgeConfig {
6    pub name: String,
7    pub platform: PlatformConfig,
8    #[serde(default)]
9    pub wokwi_board: Option<WokwiBoard>,
10    #[serde(default)]
11    pub wokwi: Option<WokwiConfig>,
12    #[serde(default)]
13    pub enable_async: bool,
14}
15
16#[derive(Debug, Deserialize, Serialize)]
17pub struct WokwiConfig {
18    pub diagram: Option<String>,
19    pub config: Option<String>,
20}
21
22#[derive(Debug, Deserialize, Serialize)]
23#[serde(rename_all = "kebab-case")]
24pub enum WokwiBoard {
25    BoardEsp32DevkitCV4,
26    BoardEsp32S2Devkitm1,
27    BoardEsp32S3Devkitc1,
28    BoardEsp32C3Devkitm1,
29    BoardEsp32C6Devkitc1,
30    BoardEsp32H2Devkitm1,
31    BoardXiaoEsp32C3,
32    BoardXiaoEsp32C6,
33    BoardXiaoEsp32S3,
34}
35
36#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
37#[serde(rename_all = "lowercase")]
38pub enum PlatformConfig {
39    ESP32,
40    ESP32C2,
41    ESP32C3,
42    ESP32C6,
43    ESP32H2,
44    ESP32S2,
45    ESP32S3,
46}
47
48impl PlatformConfig {
49    pub fn target(&self) -> &str {
50        match self {
51            PlatformConfig::ESP32 => "xtensa-esp32-none-elf",
52            PlatformConfig::ESP32C2 => "riscv32imc-unknown-none-elf",
53            PlatformConfig::ESP32C3 => "riscv32imc-unknown-none-elf",
54            PlatformConfig::ESP32C6 => "riscv32imac-unknown-none-elf",
55            PlatformConfig::ESP32H2 => "riscv32imac-unknown-none-elf",
56            PlatformConfig::ESP32S2 => "xtensa-esp32s2-none-elf",
57            PlatformConfig::ESP32S3 => "xtensa-esp32s3-none-elf",
58        }
59    }
60}
61
62impl fmt::Display for PlatformConfig {
63    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64        match self {
65            PlatformConfig::ESP32 => write!(f, "esp32"),
66            PlatformConfig::ESP32C2 => write!(f, "esp32c2"),
67            PlatformConfig::ESP32C3 => write!(f, "esp32c3"),
68            PlatformConfig::ESP32C6 => write!(f, "esp32c6"),
69            PlatformConfig::ESP32H2 => write!(f, "esp32h2"),
70            PlatformConfig::ESP32S2 => write!(f, "esp32s2"),
71            PlatformConfig::ESP32S3 => write!(f, "esp32s3"),
72        }
73    }
74}
75