@@ -92,7 +92,7 @@ pub fn device(
92
92
93
93
:: generate:: interrupt ( target, & d. peripherals , items) ;
94
94
95
- const CORE_PERIPHERALS : & ' static [ & ' static str ] = & [
95
+ const CORE_PERIPHERALS : & [ & str ] = & [
96
96
"CPUID" ,
97
97
"DCB" ,
98
98
"DWT" ,
@@ -106,13 +106,21 @@ pub fn device(
106
106
"TPIU" ,
107
107
] ;
108
108
109
+ let mut fields = vec ! [ ] ;
110
+ let mut exprs = vec ! [ ] ;
109
111
if * target == Target :: CortexM {
110
112
for p in CORE_PERIPHERALS {
111
- let p = Ident :: new ( * p) ;
113
+ let id = Ident :: new ( * p) ;
112
114
113
115
items. push ( quote ! {
114
- pub use cortex_m:: peripheral:: #p;
116
+ pub use cortex_m:: peripheral:: #id;
117
+ } ) ;
118
+
119
+ fields. push ( quote ! {
120
+ #[ doc = #p]
121
+ pub #id: & ' a #id
115
122
} ) ;
123
+ exprs. push ( quote ! ( #id: & * #id. get( ) ) ) ;
116
124
}
117
125
}
118
126
@@ -125,8 +133,32 @@ pub fn device(
125
133
}
126
134
127
135
:: generate:: peripheral ( p, & d. peripherals , items, & d. defaults ) ?;
136
+ let p = & * p. name ;
137
+ let id = Ident :: new ( & * p) ;
138
+ fields. push ( quote ! {
139
+ #[ doc = #p]
140
+ pub #id: & ' a #id
141
+ } ) ;
142
+ exprs. push ( quote ! ( #id: & * #id. get( ) ) ) ;
128
143
}
129
144
145
+ items. push ( quote ! {
146
+ /// All the peripherals
147
+ #[ allow( non_snake_case) ]
148
+ pub struct Peripherals <' a> {
149
+ #( #fields, ) *
150
+ }
151
+
152
+ impl <' a> Peripherals <' a> {
153
+ /// Grants access to all the peripherals
154
+ pub unsafe fn all( ) -> Self {
155
+ Peripherals {
156
+ #( #exprs, ) *
157
+ }
158
+ }
159
+ }
160
+ } ) ;
161
+
130
162
Ok ( ( ) )
131
163
}
132
164
0 commit comments