MSPM0L1306_HAL/
macros.rs

1//! Macros for generating functions from the PAC
2//! 
3//! 
4//! 
5//! 
6#[macro_export]
7macro_rules! generate_set_functions {
8    ($struct_name:ident, $($function:ident),*) => {
9        $(
10            impl $struct_name {
11                paste! {
12                
13               pub fn [<set_ $function >] (value: u32) {
14                    unsafe{
15                    pac::Peripherals::steal().$struct_name.$function.write(|w| w.bits(value));
16                    }
17                }
18
19            }
20
21            }
22        )*
23    };
24}
25
26#[macro_export]
27macro_rules! generate_get_functions {
28    ($struct_name:ident, $($function:ident),*) => {
29        $(
30            impl $struct_name {
31                paste! {
32                
33               pub fn [<get_ $function >] () -> u32 {
34                    unsafe{
35                    return pac::Peripherals::steal().$struct_name.$function.read().bits();
36                    }
37                }
38
39            }
40
41            }
42        )*
43    };
44}
45
46
47#[macro_export]
48macro_rules! generate_set_functions_list {
49    ($struct_name:ident, $($function:ident, $vall:expr),*) => {
50        $(
51            impl $struct_name {
52                paste! {
53                
54               pub fn [<set_ $function _ $vall>] (value: u32) {
55                    unsafe{
56                    pac::Peripherals::steal().$struct_name.$function [$vall].write(|w| w.bits(value));
57                    }
58                }
59
60            }
61
62            }
63        )*
64    };
65}
66
67#[macro_export]
68macro_rules! generate_get_functions_list {
69    ($struct_name:ident, $($function:ident, $vall:expr),*) => {
70        $(
71            impl $struct_name {
72                paste! {
73                
74               pub fn [<get_ $function _ $vall>] () -> u32 {
75                    unsafe{
76                    return pac::Peripherals::steal().$struct_name.$function [$vall].read().bits();
77                    }
78                }
79
80            }
81
82            }
83        )*
84    };
85}
86
87
88#[macro_export]
89macro_rules! generate_set_functions_list_specify {
90    ($struct_name:ident,$real_struct_name:ident, $($function:ident, $vall:expr),*) => {
91        $(
92            impl $struct_name {
93                paste! {
94                
95               pub fn [<set_ $function _ $vall>] (value: u32) {
96                    unsafe{
97                    pac::Peripherals::steal().$real_struct_name.$function [$vall].write(|w| w.bits(value));
98                    }
99                }
100
101            }
102
103            }
104        )*
105    };
106}
107
108#[macro_export]
109macro_rules! generate_get_functions_list_specify {
110    ($struct_name:ident,$real_struct_name:ident, $($function:ident, $vall:expr),*) => {
111        $(
112            impl $struct_name {
113                paste! {
114                
115               pub fn [<get_ $function _ $vall>] () -> u32 {
116                    unsafe{
117                    return pac::Peripherals::steal().$real_struct_name.$function [$vall].read().bits();
118                    }
119                }
120
121            }
122
123            }
124        )*
125    };
126}