Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jun 4, 2024
1 parent 9062ce0 commit e3895e8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
/// no stolen instances are passed to such software.
};

let per_to_tokens = |feature_attribute: &TokenStream,
let per_to_tokens = |out: &mut TokenStream,
feature_attribute: &TokenStream,
description: &str,
p_ty: &Ident,
doc_alias: Option<TokenStream>,
address: LitInt|
-> TokenStream {
let mut tokens = if config.raw_access {
address: LitInt| {
out.extend(if config.raw_access {
quote! {
#[doc = #description]
#doc_alias
Expand Down Expand Up @@ -149,16 +149,15 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
}
}
}
};
tokens.extend(quote! {
});
out.extend(quote! {
#feature_attribute
impl core::fmt::Debug for #p_ty {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct(#name_str).finish()
}
}
});
tokens
};

match &p {
Expand All @@ -178,13 +177,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
feature_attribute_n.extend(quote! { #[cfg(feature = #p_feature)] })
};
// Insert the peripherals structure
out.extend(per_to_tokens(
per_to_tokens(
&mut out,
&feature_attribute_n,
description,
&p_ty,
doc_alias,
address,
));
);
}

let feature_any_attribute = quote! {#[cfg(any(#(feature = #feature_names),*))]};
Expand All @@ -207,13 +207,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] })
};
// Insert the peripheral structure
out.extend(per_to_tokens(
per_to_tokens(
&mut out,
&feature_attribute,
&description,
&p_ty,
None,
address,
));
);

// Derived peripherals may not require re-implementation, and will instead
// use a single definition of the non-derived version.
Expand Down

0 comments on commit e3895e8

Please sign in to comment.