TAAFT
Free mode
100% free
Freemium
Free Trial
Deals

Hello Embedded! ๐Ÿ‘‹

sunfishcode / hello-embedded

Hello Embedded!

23 0 Language: Rust Updated: 1y ago

README

Hello Embedded! ๐Ÿ‘‹

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 Wits

The API is described in Wit interfaces in the wit directory, and is based off
of the embedded-hal API.

The guest

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.

The host simulator

Once the guest is built, it can be run in the host simulator:

$ cd host
$ cargo run
[...]
   ๐Ÿ’ก
   ๐Ÿ’ก
   ๐Ÿ’ก

...

The Linux host

โš  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
[...]

Bonus points

This example also demonstrates Typed Main. The run function takes
two handle arguments, providing the component with exactly what it
needs.

0 AIs selected
Clear selection
#
Name
Task