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 all commits
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
34 changes: 17 additions & 17 deletions wasm_apps/rust/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
mod arduino_api;
use arduino_api::*;

static LED: u32 = 19;

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

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

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

#[no_mangle]
pub extern fn _start() {
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.
41 changes: 23 additions & 18 deletions wasm_apps/rust/app.wasm.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
unsigned char app_wasm[] = {
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0d, 0x03, 0x60,
0x02, 0x7f, 0x7f, 0x00, 0x60, 0x00, 0x00, 0x60, 0x01, 0x7f, 0x00, 0x02,
0x3a, 0x03, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x05, 0x64,
0x65, 0x6c, 0x61, 0x79, 0x00, 0x02, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69,
0x6e, 0x6f, 0x07, 0x70, 0x69, 0x6e, 0x4d, 0x6f, 0x64, 0x65, 0x00, 0x00,
0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x0c, 0x64, 0x69, 0x67,
0x69, 0x74, 0x61, 0x6c, 0x57, 0x72, 0x69, 0x74, 0x65, 0x00, 0x00, 0x03,
0x02, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x0d, 0x02, 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, 0x00,
0x0b, 0x5f, 0x5f, 0x68, 0x65, 0x61, 0x70, 0x5f, 0x62, 0x61, 0x73, 0x65,
0x03, 0x01, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x03, 0x0a,
0x26, 0x01, 0x24, 0x00, 0x41, 0x13, 0x41, 0x01, 0x10, 0x01, 0x03, 0x40,
0x41, 0x13, 0x41, 0x01, 0x10, 0x02, 0x41, 0xe4, 0x00, 0x10, 0x00, 0x41,
0x13, 0x41, 0x00, 0x10, 0x02, 0x41, 0x84, 0x07, 0x10, 0x00, 0x0c, 0x00,
0x0b, 0x00, 0x0b
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x11, 0x04, 0x60,
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, 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, 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, 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 = 195;
unsigned int app_wasm_len = 259;
18 changes: 9 additions & 9 deletions wasm_apps/rust/arduino_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
extern {
#[link_name = "millis"] fn unsafe_millis() -> u32;
#[link_name = "delay"] fn unsafe_delay(ms: u32);
#[link_name = "pinMode"] fn unsafe_pinMode(pin:u32, mode:u32);
#[link_name = "digitalWrite"] fn unsafe_digitalWrite(pin:u32, value:u32);
#[link_name = "pinMode"] fn unsafe_pinMode(pin: u32, mode: u32);
#[link_name = "digitalWrite"] fn unsafe_digitalWrite(pin: u32, value: u32);

#[link_name = "getPinLED"] fn unsafe_getPinLED() -> u32;
}

pub static LOW:u32 = 0;
pub static HIGH:u32 = 1;
pub static LOW: u32 = 0;
pub static HIGH: u32 = 1;

pub static INPUT:u32 = 0x0;
pub static OUTPUT:u32 = 0x1;
pub static INPUT_PULLUP:u32 = 0x2;
pub static INPUT: u32 = 0x0;
pub static OUTPUT: u32 = 0x1;
pub static INPUT_PULLUP: u32 = 0x2;

pub fn millis () -> u32 { unsafe { unsafe_millis() } }
pub fn delay (ms: u32) { unsafe { unsafe_delay(ms); } }
pub fn pin_mode (pin:u32, mode:u32) { unsafe { unsafe_pinMode(pin, mode) } }
pub fn digital_write (pin:u32, value:u32) { unsafe { unsafe_digitalWrite(pin, value) } }
pub fn pin_mode (pin: u32, mode: u32) { unsafe { unsafe_pinMode(pin, mode) } }
pub fn digital_write (pin: u32, value: u32) { unsafe { unsafe_digitalWrite(pin, value) } }
pub fn get_pin_led () -> u32 { unsafe { unsafe_getPinLED() } }