This repository contains a sketch of an embedded API described in Wit, and a simple example Wasm application that builds with it that blinks an LED, and a Wasmtime-based simulator that can run it. This is a super early demo, and hasn't been optimized at all for code size yet. Its purpose right now is to start some discussions.
The API is described in Wit interfaces in the wit directory, and is based off of the embedded-hal API.
The example application is in the guest directory. Building it currently requires cargo component 0.8. Build with cargo component build
.
$ cd guest
$ cargo component build --release
[...]
$ cd ..
That produces a component in guest/target/wasm32-wasi/release/hello_embedded.wasm
. We can examine it with wasm-tools
:
$ wasm-tools component wit guest/target/wasm32-wasi/release/hello_embedded.wasm
package root:component;
world root {
import sketch:embedded/[email protected];
import sketch:embedded/[email protected];
export sketch:embedded/[email protected];
}
Here we can see it's exporting the run
interface, which has the run
entrypoint function, and importing the digital
and delay
and interfaces, which it uses to set the led and control its speed, respectively.
Once the guest is built, it can be run in the host simulator:
$ cd host
$ cargo run
[...]
π‘
π‘
π‘
...
β The following is entirely untested at this time!!! β
If you can run this on a Linux board with a GPIO pin 0 wired up to an LED, and if luck smiles on us, this should run the guest which should make that LED blink:
$ cd linux-host
$ cargo run
[...]
This example also demonstrates Typed Main. The run
function takes two handle arguments, providing the component with exactly what it needs.