1#![no_std]
23extern crate embedded_hal;
4use embedded_hal::blocking::delay::DelayMs;
56pub mod print;
78pub mod delay;
9use delay::WasmDelay;
1011#[cfg(feature = "logger")]
12pub mod logger;
1314pub mod prelude;
1516mod runtime;
1718/// Internal hardware singleton
19static mut ESP32: Option<Esp32> = Some(Esp32{
20 _extensible: (),
21});
2223/// ESP32 WASM API object
24pub struct Esp32 {
25// Block construction of this object outside of the library
26_extensible: (),
27}
2829#[link(wasm_import_module = "env")]
30extern {
31pub fn get_ticks(m: &u32);
32}
3334impl Esp32 {
35/// Take the ESP32 configuration object
36pub fn take() -> Option<Self> {
37// TODO: mutable static is not ideal, but at this point we only
38 // have one process within the WASM runtime so...
39unsafe { ESP32.take() }
40 }
4142/// Get the current tick count from the underlying OS
43pub fn get_ticks(&self) -> u32 {
44let mut v = 0;
45unsafe { get_ticks(&mut v) };
46 v as u32
47 }
48}
4950// Convenience implementation of delay
51impl DelayMs<u32> for Esp32 {
52fn delay_ms(&mut self, m: u32) {
53 WasmDelay::delay_ms(&mut WasmDelay, m);
54 }
55}
565758