@@ -92,7 +92,7 @@ pub fn device(
9292
9393 :: generate:: interrupt ( target, & d. peripherals , items) ;
9494
95- const CORE_PERIPHERALS : & ' static [ & ' static str ] = & [
95+ const CORE_PERIPHERALS : & [ & str ] = & [
9696 "CPUID" ,
9797 "DCB" ,
9898 "DWT" ,
@@ -106,13 +106,21 @@ pub fn device(
106106 "TPIU" ,
107107 ] ;
108108
109+ let mut fields = vec ! [ ] ;
110+ let mut exprs = vec ! [ ] ;
109111 if * target == Target :: CortexM {
110112 for p in CORE_PERIPHERALS {
111- let p = Ident :: new ( * p) ;
113+ let id = Ident :: new ( * p) ;
112114
113115 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
115122 } ) ;
123+ exprs. push ( quote ! ( #id: & * #id. get( ) ) ) ;
116124 }
117125 }
118126
@@ -125,8 +133,32 @@ pub fn device(
125133 }
126134
127135 :: 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( ) ) ) ;
128143 }
129144
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+
130162 Ok ( ( ) )
131163}
132164
0 commit comments