@@ -108,6 +108,7 @@ pub fn render(
108108 return Err ( anyhow ! ( "Incorrect access of register {}" , register. name) ) ;
109109 } ;
110110
111+ let rpath = path. new_register ( & register. name ) ;
111112 let mut alias_doc = format ! (
112113 "{name} ({accs}) register accessor: {description}{}{}" ,
113114 api_docs(
@@ -116,6 +117,9 @@ pub fn render(
116117 register. properties. reset_value. is_some( ) ,
117118 & mod_ty,
118119 false ,
120+ & register,
121+ & rpath,
122+ config,
119123 ) ?,
120124 read_action_docs( access. can_read( ) , register. read_action) ,
121125 ) ;
@@ -128,13 +132,7 @@ pub fn render(
128132 #doc_alias
129133 pub type #reg_ty = crate :: Reg <#mod_ty:: #regspec_ty>;
130134 } ) ;
131- let mod_items = render_register_mod (
132- register,
133- access,
134- & path. new_register ( & register. name ) ,
135- index,
136- config,
137- ) ?;
135+ let mod_items = render_register_mod ( register, access, & rpath, index, config) ?;
138136
139137 out. extend ( quote ! {
140138 #[ doc = #description]
@@ -170,6 +168,9 @@ fn api_docs(
170168 can_reset : bool ,
171169 module : & Ident ,
172170 inmodule : bool ,
171+ register : & Register ,
172+ rpath : & RegisterPath ,
173+ config : & Config ,
173174) -> Result < String , std:: fmt:: Error > {
174175 fn method ( s : & str ) -> String {
175176 format ! ( "[`{s}`](crate::Reg::{s})" )
@@ -211,13 +212,35 @@ fn api_docs(
211212
212213 doc. push_str ( "See [API](https://docs.rs/svd2rust/#read--modify--write-api)." ) ;
213214
215+ if let Some ( url) = config. html_url . as_ref ( ) {
216+ let first_idx = if let Register :: Array ( _, dim) = & register {
217+ dim. indexes ( ) . next ( )
218+ } else {
219+ None
220+ } ;
221+ let rname = if let Some ( idx) = first_idx {
222+ let idx = format ! ( "[{idx}]" ) ;
223+ rpath. name . replace ( "[%s]" , & idx) . replace ( "%s" , & idx)
224+ } else {
225+ rpath. name . to_string ( )
226+ } ;
227+ // TODO: support html_urls for registers in cluster
228+ if rpath. block . path . is_empty ( ) {
229+ doc. push_str ( & format ! (
230+ "\n \n See register [structure]({url}#{}:{})" ,
231+ rpath. peripheral( ) ,
232+ rname
233+ ) ) ;
234+ }
235+ }
236+
214237 Ok ( doc)
215238}
216239
217240pub fn render_register_mod (
218241 register : & Register ,
219242 access : Access ,
220- path : & RegisterPath ,
243+ rpath : & RegisterPath ,
221244 index : & Index ,
222245 config : & Config ,
223246) -> Result < TokenStream > {
@@ -312,7 +335,7 @@ pub fn render_register_mod(
312335 access,
313336 properties,
314337 & mut mod_items,
315- path ,
338+ rpath ,
316339 index,
317340 config,
318341 ) ?;
@@ -361,7 +384,7 @@ pub fn render_register_mod(
361384
362385 let doc = format ! (
363386 "{description}{}{}" ,
364- api_docs( can_read, can_write, can_reset, & mod_ty, true ) ?,
387+ api_docs( can_read, can_write, can_reset, & mod_ty, true , register , rpath , config ) ?,
365388 read_action_docs( access. can_read( ) , register. read_action) ,
366389 ) ;
367390
0 commit comments