summaryrefslogtreecommitdiffstats
path: root/src/main.rs
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/main.rs
downloadrust-microbit-guix-template-master.tar.gz
rust-microbit-guix-template-master.zip
Initial commit!HEADmaster
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
1 files changed, 37 insertions, 0 deletions
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}