Skip to content

Commit

Permalink
Cache bus clock register and support clock source
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Jan 6, 2025
1 parent 39da533 commit 681f048
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 126 deletions.
27 changes: 23 additions & 4 deletions esp-hal-procmacros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
/// ```
///
/// [Builder Lite]: https://matklad.github.io/2022/05/29/builder-lite.html
#[proc_macro_derive(BuilderLite)]
#[proc_macro_derive(BuilderLite, attributes(builder_lite_into))]
pub fn builder_lite_derive(item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::DeriveInput);

Expand All @@ -455,10 +455,29 @@ pub fn builder_lite_derive(item: TokenStream) -> TokenStream {
_ => None,
});

let (field_type, field_assigns) = if let Some(inner_type) = maybe_path_type {
(inner_type, quote! { Some(#field_ident) })
let convert_parameter = field
.attrs
.iter()
.any(|attr| attr.path().is_ident("builder_lite_into"));

let (field_type, field_assigns) = if convert_parameter {
if let Some(inner_type) = maybe_path_type {
(
quote! { impl Into<#inner_type> },
quote! { Some(#field_ident .into()) },
)
} else {
(
quote! { impl Into<#field_type> },
quote! { #field_ident .into() },
)
}
} else {
(field_type, quote! { #field_ident })
if let Some(inner_type) = maybe_path_type {
(quote! { #inner_type }, quote! { Some(#field_ident) })
} else {
(quote! { #field_type }, quote! { #field_ident })
}
};

fns.push(quote! {
Expand Down
Loading

0 comments on commit 681f048

Please sign in to comment.