From 7fb80a8b34473f81392303fc167819849a3899ff Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Tue, 25 Jun 2024 03:46:19 +0200 Subject: Initial commit! --- src/add_one.c | 1 + src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/add_one.c create mode 100644 src/main.rs (limited to 'src') 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 @@ +#![no_main] +#![no_std] + +use core::{fmt::Write, ffi::c_int}; +use cortex_m_rt::entry; +use microbit::{ + hal::uart::{Uart, Baudrate, Parity}, + Board, +}; + +extern crate panic_halt; +extern crate microbit; +extern "C" { + fn c_add_one(x: c_int) -> c_int; +} + +pub fn add_one(x: i32) -> i32 { + unsafe { + c_add_one(x) + } +} + +#[entry] +fn main() -> ! { + let board = Board::take().unwrap(); + let mut serial = Uart::new( + board.UART0, + board.uart.into(), + Parity::EXCLUDED, + Baudrate::BAUD115200, + ); + + let ten_plus_one = add_one(10); + writeln!(serial, "10 + 1 = {}\r", ten_plus_one).unwrap(); + + loop {} +} -- cgit v1.2.3