Skip to content

[rust] rewrite Rust example #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rewrite rust example without mut globals
  • Loading branch information
MaxGraey committed Jan 20, 2020
commit 812c9805e80e491f12871bd657deecc156120d61
36 changes: 17 additions & 19 deletions wasm_apps/rust/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@
mod arduino_api;
use arduino_api::*;

static mut LED: u32 = 0;

unsafe fn setup() {
LED = get_pin_led();
pin_mode(LED, OUTPUT);
struct App {
led: u32,
}

unsafe fn run() {
digital_write(LED, HIGH);
delay(100);
digital_write(LED, LOW);
delay(900);
impl App {
fn new() -> Self {
let env = App { led: get_pin_led() };
pin_mode(env.led, OUTPUT);
env
}

fn update(&self) {
digital_write(self.led, HIGH);
delay(100);
digital_write(self.led, LOW);
delay(900);
}
}

/*
* Entry point
*/
#[no_mangle]
pub extern fn _start() {
unsafe {
setup();
loop {
run();
}
}
let app = App::new();
loop { app.update() };
}

#[panic_handler]
Expand Down
Binary file modified wasm_apps/rust/app.wasm
Binary file not shown.
33 changes: 15 additions & 18 deletions wasm_apps/rust/app.wasm.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
unsigned char app_wasm[] = {
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x11, 0x04, 0x60,
0x00, 0x01, 0x7f, 0x60, 0x02, 0x7f, 0x7f, 0x00, 0x60, 0x01, 0x7f, 0x00,
0x01, 0x7f, 0x00, 0x60, 0x02, 0x7f, 0x7f, 0x00, 0x60, 0x00, 0x01, 0x7f,
0x60, 0x00, 0x00, 0x02, 0x4e, 0x04, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69,
0x6e, 0x6f, 0x09, 0x67, 0x65, 0x74, 0x50, 0x69, 0x6e, 0x4c, 0x45, 0x44,
0x00, 0x00, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x07, 0x70,
0x69, 0x6e, 0x4d, 0x6f, 0x64, 0x65, 0x00, 0x01, 0x07, 0x61, 0x72, 0x64,
0x75, 0x69, 0x6e, 0x6f, 0x0c, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c,
0x57, 0x72, 0x69, 0x74, 0x65, 0x00, 0x01, 0x07, 0x61, 0x72, 0x64, 0x75,
0x69, 0x6e, 0x6f, 0x05, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x00, 0x02, 0x03,
0x6e, 0x6f, 0x05, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x00, 0x00, 0x07, 0x61,
0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x07, 0x70, 0x69, 0x6e, 0x4d, 0x6f,
0x64, 0x65, 0x00, 0x01, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f,
0x0c, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x57, 0x72, 0x69, 0x74,
0x65, 0x00, 0x01, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x09,
0x67, 0x65, 0x74, 0x50, 0x69, 0x6e, 0x4c, 0x45, 0x44, 0x00, 0x02, 0x03,
0x02, 0x01, 0x03, 0x04, 0x05, 0x01, 0x70, 0x01, 0x01, 0x01, 0x05, 0x03,
0x01, 0x00, 0x01, 0x06, 0x13, 0x03, 0x7f, 0x01, 0x41, 0x80, 0x20, 0x0b,
0x7f, 0x00, 0x41, 0x84, 0x20, 0x0b, 0x7f, 0x00, 0x41, 0x84, 0x20, 0x0b,
0x7f, 0x00, 0x41, 0x80, 0x20, 0x0b, 0x7f, 0x00, 0x41, 0x80, 0x20, 0x0b,
0x07, 0x2e, 0x04, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00,
0x0a, 0x5f, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x65, 0x6e, 0x64, 0x03,
0x01, 0x0b, 0x5f, 0x5f, 0x68, 0x65, 0x61, 0x70, 0x5f, 0x62, 0x61, 0x73,
0x65, 0x03, 0x02, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x04,
0x0a, 0x5a, 0x01, 0x58, 0x01, 0x01, 0x7f, 0x41, 0x00, 0x10, 0x80, 0x80,
0x80, 0x80, 0x00, 0x22, 0x00, 0x36, 0x02, 0x80, 0xa0, 0x80, 0x80, 0x00,
0x20, 0x00, 0x41, 0x01, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x03, 0x40,
0x41, 0x00, 0x28, 0x02, 0x80, 0xa0, 0x80, 0x80, 0x00, 0x41, 0x01, 0x10,
0x82, 0x80, 0x80, 0x80, 0x00, 0x41, 0xe4, 0x00, 0x10, 0x83, 0x80, 0x80,
0x80, 0x00, 0x41, 0x00, 0x28, 0x02, 0x80, 0xa0, 0x80, 0x80, 0x00, 0x41,
0x00, 0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x41, 0x84, 0x07, 0x10, 0x83,
0x80, 0x80, 0x80, 0x00, 0x0c, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x01, 0x00,
0x41, 0x80, 0x20, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x00
0x0a, 0x41, 0x01, 0x3f, 0x01, 0x01, 0x7f, 0x10, 0x83, 0x80, 0x80, 0x80,
0x00, 0x22, 0x00, 0x41, 0x01, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x03,
0x40, 0x20, 0x00, 0x41, 0x01, 0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x41,
0xe4, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x00, 0x41, 0x00,
0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x41, 0x84, 0x07, 0x10, 0x80, 0x80,
0x80, 0x80, 0x00, 0x0c, 0x00, 0x0b, 0x0b
};
unsigned int app_wasm_len = 297;
unsigned int app_wasm_len = 259;