diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2024-06-25 03:46:19 +0200 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2024-06-25 04:02:40 +0200 |
commit | 7fb80a8b34473f81392303fc167819849a3899ff (patch) | |
tree | 9946b4a68464266c664a07711d2c727ab0856f82 /src | |
download | rust-microbit-guix-template-master.tar.gz rust-microbit-guix-template-master.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/add_one.c | 1 | ||||
-rw-r--r-- | src/main.rs | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/add_one.c b/src/add_one.c new file mode 100644 index 0000000..74853d0 --- /dev/null +++ b/src/add_one.c | |||
@@ -0,0 +1 @@ | |||
int c_add_one(int x) { return x + 1; } | |||
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..3781a12 --- /dev/null +++ b/src/main.rs | |||
@@ -0,0 +1,37 @@ | |||
1 | #![no_main] | ||
2 | #![no_std] | ||
3 | |||
4 | use core::{fmt::Write, ffi::c_int}; | ||
5 | use cortex_m_rt::entry; | ||
6 | use microbit::{ | ||
7 | hal::uart::{Uart, Baudrate, Parity}, | ||
8 | Board, | ||
9 | }; | ||
10 | |||
11 | extern crate panic_halt; | ||
12 | extern crate microbit; | ||
13 | extern "C" { | ||
14 | fn c_add_one(x: c_int) -> c_int; | ||
15 | } | ||
16 | |||
17 | pub fn add_one(x: i32) -> i32 { | ||
18 | unsafe { | ||
19 | c_add_one(x) | ||
20 | } | ||
21 | } | ||
22 | |||
23 | #[entry] | ||
24 | fn main() -> ! { | ||
25 | let board = Board::take().unwrap(); | ||
26 | let mut serial = Uart::new( | ||
27 | board.UART0, | ||
28 | board.uart.into(), | ||
29 | Parity::EXCLUDED, | ||
30 | Baudrate::BAUD115200, | ||
31 | ); | ||
32 | |||
33 | let ten_plus_one = add_one(10); | ||
34 | writeln!(serial, "10 + 1 = {}\r", ten_plus_one).unwrap(); | ||
35 | |||
36 | loop {} | ||
37 | } | ||