@@ -5,6 +5,7 @@ use std::fmt;
5
5
use svd_parser:: expand:: {
6
6
derive_cluster, derive_peripheral, derive_register, BlockPath , Index , RegisterPath ,
7
7
} ;
8
+ use syn:: LitInt ;
8
9
9
10
use crate :: config:: Config ;
10
11
use crate :: svd:: {
@@ -80,6 +81,60 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
80
81
}
81
82
} ;
82
83
84
+ let phtml = config. html_url . as_ref ( ) . map ( |url| {
85
+ let doc = format ! ( "See peripheral [structure]({url}#{})" , & path. peripheral) ;
86
+ quote ! ( #[ doc = "" ] #[ doc = #doc] )
87
+ } ) ;
88
+
89
+ let per_to_tokens = |out : & mut TokenStream ,
90
+ feature_attribute : & TokenStream ,
91
+ description : & str ,
92
+ p_ty : & Ident ,
93
+ doc_alias : Option < TokenStream > ,
94
+ address : LitInt | {
95
+ out. extend ( quote ! {
96
+ #[ doc = #description]
97
+ #phtml
98
+ #doc_alias
99
+ #feature_attribute
100
+ pub struct #p_ty { _marker: PhantomData <* const ( ) > }
101
+
102
+ #feature_attribute
103
+ unsafe impl Send for #p_ty { }
104
+
105
+ #feature_attribute
106
+ impl #p_ty {
107
+ ///Pointer to the register block
108
+ pub const PTR : * const #base:: RegisterBlock = #address as * const _;
109
+
110
+ ///Return the pointer to the register block
111
+ #[ inline( always) ]
112
+ pub const fn ptr( ) -> * const #base:: RegisterBlock {
113
+ Self :: PTR
114
+ }
115
+
116
+ #steal_fn
117
+ }
118
+
119
+ #feature_attribute
120
+ impl Deref for #p_ty {
121
+ type Target = #base:: RegisterBlock ;
122
+
123
+ #[ inline( always) ]
124
+ fn deref( & self ) -> & Self :: Target {
125
+ unsafe { & * Self :: PTR }
126
+ }
127
+ }
128
+
129
+ #feature_attribute
130
+ impl core:: fmt:: Debug for #p_ty {
131
+ fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
132
+ f. debug_struct( #name_str) . finish( )
133
+ }
134
+ }
135
+ } ) ;
136
+ } ;
137
+
83
138
match & p {
84
139
Peripheral :: Array ( p, dim) => {
85
140
let mut feature_names = Vec :: with_capacity ( dim. dim as _ ) ;
@@ -97,46 +152,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
97
152
feature_attribute_n. extend ( quote ! { #[ cfg( feature = #p_feature) ] } )
98
153
} ;
99
154
// Insert the peripherals structure
100
- out. extend ( quote ! {
101
- #[ doc = #description]
102
- #doc_alias
103
- #feature_attribute_n
104
- pub struct #p_ty { _marker: PhantomData <* const ( ) > }
105
-
106
- #feature_attribute_n
107
- unsafe impl Send for #p_ty { }
108
-
109
- #feature_attribute_n
110
- impl #p_ty {
111
- ///Pointer to the register block
112
- pub const PTR : * const #base:: RegisterBlock = #address as * const _;
113
-
114
- ///Return the pointer to the register block
115
- #[ inline( always) ]
116
- pub const fn ptr( ) -> * const #base:: RegisterBlock {
117
- Self :: PTR
118
- }
119
-
120
- #steal_fn
121
- }
122
-
123
- #feature_attribute_n
124
- impl Deref for #p_ty {
125
- type Target = #base:: RegisterBlock ;
126
-
127
- #[ inline( always) ]
128
- fn deref( & self ) -> & Self :: Target {
129
- unsafe { & * Self :: PTR }
130
- }
131
- }
132
-
133
- #feature_attribute_n
134
- impl core:: fmt:: Debug for #p_ty {
135
- fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
136
- f. debug_struct( #name_str) . finish( )
137
- }
138
- }
139
- } ) ;
155
+ per_to_tokens (
156
+ & mut out,
157
+ & feature_attribute_n,
158
+ description,
159
+ & p_ty,
160
+ doc_alias,
161
+ address,
162
+ ) ;
140
163
}
141
164
142
165
let feature_any_attribute = quote ! { #[ cfg( any( #( feature = #feature_names) , * ) ) ] } ;
@@ -159,45 +182,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
159
182
feature_attribute. extend ( quote ! { #[ cfg( feature = #p_feature) ] } )
160
183
} ;
161
184
// Insert the peripheral structure
162
- out. extend ( quote ! {
163
- #[ doc = #description]
164
- #feature_attribute
165
- pub struct #p_ty { _marker: PhantomData <* const ( ) > }
166
-
167
- #feature_attribute
168
- unsafe impl Send for #p_ty { }
169
-
170
- #feature_attribute
171
- impl #p_ty {
172
- ///Pointer to the register block
173
- pub const PTR : * const #base:: RegisterBlock = #address as * const _;
174
-
175
- ///Return the pointer to the register block
176
- #[ inline( always) ]
177
- pub const fn ptr( ) -> * const #base:: RegisterBlock {
178
- Self :: PTR
179
- }
180
-
181
- #steal_fn
182
- }
183
-
184
- #feature_attribute
185
- impl Deref for #p_ty {
186
- type Target = #base:: RegisterBlock ;
187
-
188
- #[ inline( always) ]
189
- fn deref( & self ) -> & Self :: Target {
190
- unsafe { & * Self :: PTR }
191
- }
192
- }
193
-
194
- #feature_attribute
195
- impl core:: fmt:: Debug for #p_ty {
196
- fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
197
- f. debug_struct( #name_str) . finish( )
198
- }
199
- }
200
- } ) ;
185
+ per_to_tokens (
186
+ & mut out,
187
+ & feature_attribute,
188
+ & description,
189
+ & p_ty,
190
+ None ,
191
+ address,
192
+ ) ;
201
193
202
194
// Derived peripherals may not require re-implementation, and will instead
203
195
// use a single definition of the non-derived version.
0 commit comments