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
#![no_std]
extern crate embedded_hal;
use embedded_hal::blocking::delay::DelayMs;
pub mod print;
pub mod delay;
use delay::WasmDelay;
#[cfg(feature = "logger")]
pub mod logger;
pub mod prelude;
mod runtime;
static mut ESP32: Option<Esp32> = Some(Esp32{
_extensible: (),
});
pub struct Esp32 {
_extensible: (),
}
#[link(wasm_import_module = "env")]
extern {
pub fn get_ticks(m: &u32);
}
impl Esp32 {
pub fn take() -> Option<Self> {
unsafe { ESP32.take() }
}
pub fn get_ticks(&self) -> u32 {
let mut v = 0;
unsafe { get_ticks(&mut v) };
v as u32
}
}
impl DelayMs<u32> for Esp32 {
fn delay_ms(&mut self, m: u32) {
WasmDelay::delay_ms(&mut WasmDelay, m);
}
}