lib.rs 4.12 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
    pub use core::ffi::c_void;
}

rnd's avatar
rnd committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
pub mod errno {
    #![allow(non_snake_case)]
    use crate::ctypes::c_int;

    pub const EPERM: c_int = 1; // Operation not permitted
    pub const ENOENT: c_int = 2; // No such file or directory
    pub const ESRCH: c_int = 3; // No such process
    pub const EINTR: c_int = 4; // Interrupted system call
    pub const EIO: c_int = 5; // I/O error
    pub const ENXIO: c_int = 6; // No such device or address
    pub const E2BIG: c_int = 7; // Argument list too long
    pub const ENOEXEC: c_int = 8; // Exec format error
    pub const EBADF: c_int = 9; // Bad file number
    pub const ECHILD: c_int = 10; // No child processes
    pub const EAGAIN: c_int = 11; // Try again
    pub const ENOMEM: c_int = 12; //Out of memory
    pub const EACCES: c_int = 13; //Permission denied
    pub const EFAULT: c_int = 14; //Bad address
    pub const ENOTBLK: c_int = 15; //Block device required
    pub const EBUSY: c_int = 16; //Device or resource busy
    pub const EEXIST: c_int = 17; //File exists
    pub const EXDEV: c_int = 18; //Cross-device link
    pub const ENODEV: c_int = 19; //No such device
    pub const ENOTDIR: c_int = 20; //Not a directory
    pub const EISDIR: c_int = 21; //Is a directory
    pub const EINVAL: c_int = 22; //Invalid argument
    pub const ENFILE: c_int = 23; //File table overflow
    pub const EMFILE: c_int = 24; //Too many open files
    pub const ENOTTY: c_int = 25; //Not a typewriter
    pub const ETXTBSY: c_int = 26; //Text file busy
    pub const EFBIG: c_int = 27; //File too large
    pub const ENOSPC: c_int = 28; //No space left on device
    pub const ESPIPE: c_int = 29; //Illegal seek
    pub const EROFS: c_int = 30; //Read-only file system
    pub const EMLINK: c_int = 31; //Too many links
    pub const EPIPE: c_int = 32; //Broken pipe
    pub const EDOM: c_int = 33; //Math argument out of domain of func
    pub const ERANGE: c_int = 34; //Math result not representable
    pub const EAFNOSUPPORT: c_int = 97; //Address family not supported by protocol
    pub const ECONNRESET: c_int = 104; //Connection timed out
    pub const ETIMEDOUT: c_int = 110; //Connection timed out
    pub const EINPROGRESS: c_int = 115; //Operation now in progress
}

Astro's avatar
Astro committed
105
106
107
108
109
110
111
112
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
113
114
mod os;
pub use os::*;
Astro's avatar
Astro committed
115
mod display;
Astro's avatar
Astro committed
116
pub use display::{Display, Color, LineStyle, FillStyle};
Astro's avatar
Astro committed
117
pub mod framebuffer;
Astro's avatar
Astro committed
118
119
mod buttons;
pub use buttons::Buttons;
Astro's avatar
Astro committed
120
121
pub mod uart;
pub const UART: uart::Uart = uart::Uart;
Astro's avatar
Astro committed
122
123
mod light_sensor;
pub use light_sensor::LightSensor;
Astro's avatar
Astro committed
124
pub mod vibra;
Astro's avatar
Astro committed
125
pub mod trng;
Astro's avatar
Astro committed
126
127
mod rtc;
pub use rtc::{Seconds, MilliSeconds, Time};
Astro's avatar
Astro committed
128
mod fmt_buffer;
Astro's avatar
Astro committed
129
pub use fmt_buffer::{FmtBuffer, str_to_cstr};
Astro's avatar
Astro committed
130
131
mod bme680;
pub use bme680::BME680;
Astro's avatar
Astro committed
132
mod bhi160;
133
134
135
136
pub use bhi160::{
    Accelerometer, Error as BHI160Error, Gyroscope, Orientation, Sensor as BHI160,
    SensorData as BHI160Data,
};
Astro's avatar
add fs    
Astro committed
137
pub mod fs;