xwrust/
macros.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
76
77
//! XWOS RUST:宏
//! ========
//!

#[allow(unused_macros)]
macro_rules! xwos_struct {
    (
        $(#[$attr:meta])*
        pub struct $name:ident {
            $($field:tt)*
        }
    ) => (
        #[repr(C)]
        #[cfg_attr(target_pointer_width = "32", repr(align(8)))]
        #[cfg_attr(target_pointer_width = "64", repr(align(16)))]
        $(#[$attr])*
        pub struct $name {
            $($field)*
        }
    );

    (
        $(#[$attr:meta])*
        pub(crate) struct $name:ident {
            $($field:tt)*
        }
    ) => (
        #[repr(C)]
        #[cfg_attr(target_pointer_width = "32", repr(align(8)))]
        #[cfg_attr(target_pointer_width = "64", repr(align(16)))]
        $(#[$attr])*
        pub(crate) struct $name {
            $($field)*
        }
    );

    (
        $(#[$attr:meta])*
        struct $name:ident {
            $($field:tt)*
        }
    ) => (
        #[repr(C)]
        #[cfg_attr(target_pointer_width = "32", repr(align(8)))]
        #[cfg_attr(target_pointer_width = "64", repr(align(16)))]
        $(#[$attr])*
        struct $name {
            $($field)*
        }
    );
}

/// 生成GPIO PIN掩码的宏
///
/// # 示例
///
/// ```rust
/// let pinmsk: XwSq = pin!(0, 1, 2, 3); // 0b1111
/// ```
///
#[macro_export]
macro_rules! pin {
    ($($pos:expr),*) => ($((1 << $pos) | )* 0)
}

/// 生成位掩码的宏
///
/// # 示例
///
/// ```rust
/// let pinmsk: XwSq = bit!(0, 1, 2, 3); // 0b1111
/// ```
///
#[macro_export]
macro_rules! bit {
    ($($pos:expr),*) => ($((1 << $pos) | )* 0)
}