lib.rs 1.9 KB
Newer Older
Astro's avatar
Astro committed
1
2
3
#![no_std]
#![feature(global_asm)]

4
5
use panic_abort as _;

Astro's avatar
Astro committed
6
7
8
9
global_asm!(include_str!("crt.s"));

/// Type check the user-supplied entry function.
#[macro_export]
Astro's avatar
Astro committed
10
macro_rules! main {
Astro's avatar
Astro committed
11
12
    ($path:path) => {
        #[export_name = "main"]
Astro's avatar
Astro committed
13
        pub unsafe fn __main() {
Astro's avatar
Astro committed
14
            // type check the given path
Astro's avatar
Astro committed
15
            let f: fn() = $path;
Astro's avatar
Astro committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

            f()
        }
    };
}

#[link_section = ".text.boot"]
#[no_mangle]
pub unsafe extern "C" fn Reset_Handler() -> ! {
    extern "C" {
        fn SystemInit();
        // Boundaries of the .bss section, provided by the linker script
        static mut __bss_start: u64;
        static mut __bss_end: u64;
    }

    // Zeroes the .bss section
    r0::zero_bss(&mut __bss_start, &mut __bss_end);
    SystemInit();

    extern "Rust" {
Astro's avatar
Astro committed
37
        fn main();
Astro's avatar
Astro committed
38
39
40
    }

    main();
Astro's avatar
Astro committed
41
42
43
44
45
46
    exit(0);
}

pub mod ctypes {
    #![allow(non_camel_case_types)]

Astro's avatar
Astro committed
47
48
    pub type c_short = i16;
    pub type c_ushort = u16;
Astro's avatar
Astro committed
49
50
51
52
53
54
55
    pub type c_int = i32;
    pub type c_uint = u32;
    pub type c_long = i32;
    pub type c_ulong = u32;
    pub type c_longlong = i64;
    pub type c_ulonglong = u64;
    pub type c_char = u8;
Astro's avatar
Astro committed
56
57
    pub type c_schar = i8;
    pub type c_uchar = u8;
Astro's avatar
Astro committed
58
59
60
61
62
63
64
65
66
67
68
    pub use core::ffi::c_void;
}

pub mod bindings {
    #![allow(non_upper_case_globals)]
    #![allow(non_camel_case_types)]
    #![allow(non_snake_case)]

    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

Astro's avatar
add os    
Astro committed
69
70
mod os;
pub use os::*;
Astro's avatar
Astro committed
71
mod display;
Astro's avatar
Astro committed
72
pub use display::{Display, Color, LineStyle, FillStyle};
Astro's avatar
Astro committed
73
74
mod buttons;
pub use buttons::Buttons;
Astro's avatar
Astro committed
75
76
pub mod uart;
pub const UART: uart::Uart = uart::Uart;
Astro's avatar
Astro committed
77
78
mod light_sensor;
pub use light_sensor::LightSensor;
Astro's avatar
Astro committed
79
pub mod vibra;
Astro's avatar
Astro committed
80
81
82
83
pub mod trng;
mod utime;
pub use utime::time;
mod fmt_buffer;
Astro's avatar
Astro committed
84
pub use fmt_buffer::{FmtBuffer, str_to_cstr};
Astro's avatar
Astro committed
85
86
mod bme680;
pub use bme680::BME680;
Astro's avatar
Astro committed
87
88
mod bhi160;
pub use bhi160::{Sensor as BHI160, Accelerometer, Orientation, Gyroscope, SensorData as BHI160Data};
Astro's avatar
add fs    
Astro committed
89
pub mod fs;