This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
pre-script.rhai
113 lines (102 loc) · 2.92 KB
/
pre-script.rhai
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
let metadata = #{
// Xtensa devices:
esp32: #{
wokwi_board: "board-esp32-devkit-c-v4",
esp_wifi_init: "Wifi",
esp_wifi_feature: "wifi",
},
esp32s2: #{
wokwi_board: "board-esp32-s2-devkitm-1",
esp_wifi_init: "Wifi",
esp_wifi_feature: "wifi",
},
esp32s3: #{
wokwi_board: "board-esp32-s3-devkitc-1",
esp_wifi_init: "Wifi",
esp_wifi_feature: "wifi",
},
// RISC-V devices:
esp32c2: #{
extensions: "imc",
wokwi_board: "",
esp_wifi_init: "Wifi",
esp_wifi_feature: "wifi",
},
esp32c3: #{
extensions: "imc",
wokwi_board: "board-esp32-c3-devkitm-1",
esp_wifi_init: "Wifi",
esp_wifi_feature: "wifi",
},
esp32c6: #{
extensions: "imac",
wokwi_board: "board-esp32-c6-devkitc-1",
esp_wifi_init: "Wifi",
esp_wifi_feature: "wifi",
},
esp32h2: #{
extensions: "imac",
wokwi_board: "board-esp32-h2-devkitm-1",
esp_wifi_init: "Ble",
esp_wifi_feature: "ble",
},
};
let mcu = variable::get("mcu");
let meta = metadata.get(mcu);
variable::set("esp_wifi_feature", meta.get("esp_wifi_feature"));
variable::set("wokwi_board", meta.get("wokwi_board"));
if mcu in ["esp32", "esp32s2", "esp32s3"] {
// Xtensa devices:
variable::set("arch", "xtensa");
variable::set("gcc_target", `xtensa-${mcu}-elf`);
variable::set("rust_target", `xtensa-${mcu}-none-elf`);
variable::set("toolchain", "esp");
} else {
// RISC-V devices:
let extensions = meta.get("extensions");
variable::set("arch", "riscv");
variable::set("gcc_target", "riscv32-esp-elf");
variable::set("rust_target", `riscv32${extensions}-unknown-none-elf`);
variable::set("toolchain", "stable");
}
let advanced = variable::get("advanced");
if !advanced {
variable::set("alloc", false);
variable::set("ci", false);
variable::set("devcontainer", false);
variable::set("wokwi", false);
variable::set("wifi", false);
}
//
// Snippets - These should be short & self-contained, not depending on other snippets existing where possible.
//
// dependencies: none
variable::set("alloc_snippet",
`
extern crate alloc;
use core::mem::MaybeUninit;
fn init_heap() {
const HEAP_SIZE: usize = 32 * 1024;
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();
unsafe {
esp_alloc::HEAP.add_region(esp_alloc::HeapRegion::new(
HEAP.as_mut_ptr() as *mut u8,
HEAP_SIZE,
esp_alloc::MemoryCapability::Internal.into(),
));
}
}
`);
// depends on: `peripherals` being in scope
variable::set("esp_wifi_snippet",
`
let timg0 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0);
let _init = esp_wifi::init(
esp_wifi::EspWifiInitFor::${meta.esp_wifi_init},
timg0.timer0,
esp_hal::rng::Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
)
.unwrap();
`
);