summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjdlugosz963 <jdlugosz963@gmail.com>2024-06-25 03:46:19 +0200
committerjdlugosz963 <jdlugosz963@gmail.com>2024-06-25 04:02:40 +0200
commit7fb80a8b34473f81392303fc167819849a3899ff (patch)
tree9946b4a68464266c664a07711d2c727ab0856f82 /src
downloadrust-microbit-guix-template-7fb80a8b34473f81392303fc167819849a3899ff.tar.gz
rust-microbit-guix-template-7fb80a8b34473f81392303fc167819849a3899ff.zip
Initial commit!HEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/add_one.c1
-rw-r--r--src/main.rs37
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
4use core::{fmt::Write, ffi::c_int};
5use cortex_m_rt::entry;
6use microbit::{
7 hal::uart::{Uart, Baudrate, Parity},
8 Board,
9};
10
11extern crate panic_halt;
12extern crate microbit;
13extern "C" {
14 fn c_add_one(x: c_int) -> c_int;
15}
16
17pub fn add_one(x: i32) -> i32 {
18 unsafe {
19 c_add_one(x)
20 }
21}
22
23#[entry]
24fn 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}