Skip to content

Commit 9256f90

Browse files
committed
Rust: add print
1 parent 2fc7f78 commit 9256f90

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

examples_pio/Wasm_Advanced/wasm_apps/rust/app.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ mod arduino;
55
use arduino::*;
66

77
struct App {
8-
led: u32,
8+
led: u32,
99
}
1010

1111
impl App {
1212
fn new() -> Self {
13+
println("Rust is running");
14+
1315
let led = getPinLED();
1416
pinMode(led, OUTPUT);
1517
Self { led }
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
unsigned char app_wasm[] = {
22
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x11, 0x04, 0x60,
33
0x02, 0x7f, 0x7f, 0x00, 0x60, 0x00, 0x00, 0x60, 0x01, 0x7f, 0x00, 0x60,
4-
0x00, 0x01, 0x7f, 0x02, 0x4e, 0x04, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69,
4+
0x00, 0x01, 0x7f, 0x02, 0x5e, 0x05, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69,
55
0x6e, 0x6f, 0x05, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x00, 0x02, 0x07, 0x61,
66
0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x07, 0x70, 0x69, 0x6e, 0x4d, 0x6f,
77
0x64, 0x65, 0x00, 0x00, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f,
88
0x0c, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x57, 0x72, 0x69, 0x74,
99
0x65, 0x00, 0x00, 0x07, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x09,
10-
0x67, 0x65, 0x74, 0x50, 0x69, 0x6e, 0x4c, 0x45, 0x44, 0x00, 0x03, 0x03,
11-
0x02, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x0d, 0x02, 0x7f,
12-
0x00, 0x41, 0x80, 0x20, 0x0b, 0x7f, 0x00, 0x41, 0x80, 0x20, 0x0b, 0x07,
13-
0x2e, 0x04, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x0a,
14-
0x5f, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x65, 0x6e, 0x64, 0x03, 0x00,
15-
0x0b, 0x5f, 0x5f, 0x68, 0x65, 0x61, 0x70, 0x5f, 0x62, 0x61, 0x73, 0x65,
16-
0x03, 0x01, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x04, 0x0a,
17-
0x2a, 0x01, 0x28, 0x01, 0x01, 0x7f, 0x10, 0x03, 0x22, 0x00, 0x41, 0x01,
18-
0x10, 0x01, 0x03, 0x40, 0x20, 0x00, 0x41, 0x01, 0x10, 0x02, 0x41, 0xe4,
19-
0x00, 0x10, 0x00, 0x20, 0x00, 0x41, 0x00, 0x10, 0x02, 0x41, 0x84, 0x07,
20-
0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x0b
10+
0x67, 0x65, 0x74, 0x50, 0x69, 0x6e, 0x4c, 0x45, 0x44, 0x00, 0x03, 0x07,
11+
0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x05, 0x70, 0x72, 0x69, 0x6e,
12+
0x74, 0x00, 0x00, 0x03, 0x02, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01,
13+
0x06, 0x0d, 0x02, 0x7f, 0x00, 0x41, 0x90, 0x10, 0x0b, 0x7f, 0x00, 0x41,
14+
0x90, 0x10, 0x0b, 0x07, 0x2e, 0x04, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72,
15+
0x79, 0x02, 0x00, 0x0a, 0x5f, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x65,
16+
0x6e, 0x64, 0x03, 0x00, 0x0b, 0x5f, 0x5f, 0x68, 0x65, 0x61, 0x70, 0x5f,
17+
0x62, 0x61, 0x73, 0x65, 0x03, 0x01, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72,
18+
0x74, 0x00, 0x05, 0x0a, 0x38, 0x01, 0x36, 0x01, 0x01, 0x7f, 0x41, 0x81,
19+
0x10, 0x41, 0x0f, 0x10, 0x04, 0x41, 0x80, 0x10, 0x41, 0x01, 0x10, 0x04,
20+
0x10, 0x03, 0x22, 0x00, 0x41, 0x01, 0x10, 0x01, 0x03, 0x40, 0x20, 0x00,
21+
0x41, 0x01, 0x10, 0x02, 0x41, 0xe4, 0x00, 0x10, 0x00, 0x20, 0x00, 0x41,
22+
0x00, 0x10, 0x02, 0x41, 0x84, 0x07, 0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00,
23+
0x0b, 0x0b, 0x17, 0x01, 0x00, 0x41, 0x80, 0x10, 0x0b, 0x10, 0x0a, 0x52,
24+
0x75, 0x73, 0x74, 0x20, 0x69, 0x73, 0x20, 0x72, 0x75, 0x6e, 0x6e, 0x69,
25+
0x6e, 0x67
2126
};
22-
unsigned int app_wasm_len = 223;
27+
unsigned int app_wasm_len = 278;

examples_pio/Wasm_Advanced/wasm_apps/rust/arduino.rs

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern {
88
#[link_name = "pinMode"] fn _pinMode(pin: u32, mode: u32);
99
#[link_name = "digitalWrite"] fn _digitalWrite(pin: u32, value: u32);
1010
#[link_name = "getPinLED"] fn _getPinLED() -> u32;
11+
#[link_name = "getGreeting"] fn _getGreeting(utf8: * mut u8, maxlen: usize);
12+
#[link_name = "print"] fn _print(utf8: *const u8, len: usize);
1113
}
1214

1315
pub static LOW: u32 = 0;
@@ -23,6 +25,17 @@ pub fn pinMode (pin: u32, mode: u32) { unsafe { _pinMode(pin, mode) } }
2325
pub fn digitalWrite (pin: u32, value: u32) { unsafe { _digitalWrite(pin, value) } }
2426
pub fn getPinLED () -> u32 { unsafe { _getPinLED() } }
2527

28+
pub fn print(string: &str) {
29+
unsafe { _print(string.as_ptr(), string.len()) }
30+
}
31+
32+
pub fn println(string: &str) {
33+
print(string);
34+
print("\n");
35+
}
36+
37+
//TODO: getGreeting
38+
2639
#[panic_handler]
2740
fn handle_panic(_: &core::panic::PanicInfo) -> ! {
2841
unsafe { core::intrinsics::unreachable() }

examples_pio/Wasm_Advanced/wasm_apps/rust/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Compile
22
rustc -O --crate-type=cdylib \
33
--target=wasm32-unknown-unknown \
4-
-C link-arg=-zstack-size=4096 \
4+
-C link-arg=-zstack-size=2048 \
55
-C link-arg=-s \
66
-o app.wasm app.rs
77

0 commit comments

Comments
 (0)