flipperzero_sys/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Low-level bindings for the Flipper Zero.

#![no_std]
#![deny(rustdoc::broken_intra_doc_links)]

// Features that identify thumbv7em-none-eabihf.
// NOTE: `arm_target_feature` is currently unstable (see rust-lang/rust#44839)
#[cfg(not(any(
    all(
        target_arch = "arm",
        //target_feature = "thumb2",
        //target_feature = "v7",
        //target_feature = "dsp",
        target_os = "none",
        target_abi = "eabihf",
    ),
    miri
)))]
core::compile_error!("This crate requires `--target thumbv7em-none-eabihf`");

pub mod furi;
mod inlines;

#[allow(
    non_upper_case_globals,
    non_camel_case_types,
    non_snake_case,
    clippy::missing_safety_doc,
    clippy::transmute_int_to_bool,
    clippy::useless_transmute,
    rustdoc::broken_intra_doc_links
)]
mod bindings;

/// Crash the system.
///
/// The only argument is a message with which the system should crash
/// which should contain no NULs. The following will not compile:
///
/// ```compile_fail
/// flipperzero_sys::crash!("Has a \0 NUL");
/// ```
///
/// # Examples
///
/// Crash the system with a *"Hello world!"* message:
///
/// ```
/// flipperzero_sys::crash!("Hello world!");
/// ```
#[macro_export]
macro_rules! crash {
    ($msg:expr $(,)?) => {{
        const MESSAGE: *const ::core::primitive::i8 =
            match ::core::ffi::CStr::from_bytes_with_nul(
                ::core::concat!($msg, "\0").as_bytes(),
            ) {
                Ok(cstr) => cstr.as_ptr(),
                Err(error) => panic!("message contains NULs"),
            };
        unsafe {
            // Crash message is passed via r12
            ::core::arch::asm!("", in("r12") MESSAGE, options(nomem, nostack));

            $crate::__furi_crash_implementation();
            ::core::hint::unreachable_unchecked();
        }
    }};
}

// Re-export bindings
pub use bindings::*;

// Definition of inline functions
pub use inlines::furi_hal_gpio::*;