diff --git a/src/generate/device.rs b/src/generate/device.rs index 76142fee..3d5335fc 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -192,6 +192,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Result Result { let p_name = util::name_of(p, config.ignore_groups); - let p_feature = config - .ident_formats - .get("peripheral_feature") - .unwrap() - .apply(&p_name); + let p_feature = feature_format.apply(&p_name); let p_ty = ident(&p_name, &config, "peripheral", span); let p_singleton = ident(&p_name, &config, "peripheral_sigleton", span); if config.feature_peripheral { @@ -259,11 +252,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result { for p_name in names(p, dim_element) { - let p_feature = config - .ident_formats - .get("peripheral_feature") - .unwrap() - .apply(&p_name); + let p_feature = feature_format.apply(&p_name); let p_ty = ident(&p_name, &config, "peripheral", span); let p_singleton = ident(&p_name, &config, "peripheral_sigleton", span); if config.feature_peripheral { diff --git a/src/generate/interrupt.rs b/src/generate/interrupt.rs index aa2d256c..1c48b06e 100644 --- a/src/generate/interrupt.rs +++ b/src/generate/interrupt.rs @@ -5,7 +5,7 @@ use crate::svd::Peripheral; use proc_macro2::{Span, TokenStream}; use quote::quote; -use crate::util::{self, ident, ToSanitizedCase}; +use crate::util::{self, ident}; use crate::{Config, Target}; use anyhow::Result; @@ -47,6 +47,7 @@ pub fn render( let mut pos = 0; let mut mod_items = TokenStream::new(); let span = Span::call_site(); + let feature_format = config.ident_formats.get("peripheral_feature").unwrap(); for interrupt in &interrupts { while pos < interrupt.0.value { elements.extend(quote!(Vector { _reserved: 0 },)); @@ -74,13 +75,13 @@ pub fn render( let mut feature_attribute = TokenStream::new(); let mut not_feature_attribute = TokenStream::new(); if config.feature_group && interrupt.1.is_some() { - let feature_name = interrupt.1.as_ref().unwrap().to_sanitized_snake_case(); + let feature_name = feature_format.apply(interrupt.1.as_ref().unwrap()); feature_attribute_flag = true; feature_attribute.extend(quote! { #[cfg(feature = #feature_name)] }); not_feature_attribute.extend(quote! { feature = #feature_name, }); } if config.feature_peripheral { - let feature_name = interrupt.2.to_sanitized_snake_case(); + let feature_name = feature_format.apply(&interrupt.2); feature_attribute_flag = true; feature_attribute.extend(quote! { #[cfg(feature = #feature_name)] }); not_feature_attribute.extend(quote! { feature = #feature_name, }); diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index fce6d18a..af97e8d2 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -51,8 +51,9 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result }; let mut feature_attribute = TokenStream::new(); + let feature_format = config.ident_formats.get("peripheral_feature").unwrap(); if config.feature_group && p.group_name.is_some() { - let feature_name = p.group_name.as_ref().unwrap().to_sanitized_snake_case(); + let feature_name = feature_format.apply(p.group_name.as_ref().unwrap()); feature_attribute.extend(quote! { #[cfg(feature = #feature_name)] }); }; @@ -85,11 +86,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result let name_str = p_ty.to_string(); let doc_alias = (&name_str != name).then(|| quote!(#[doc(alias = #name)])); let address = util::hex(pi.base_address + config.base_address_shift); - let p_feature = config - .ident_formats - .get("peripheral_feature") - .unwrap() - .apply(name); + let p_feature = feature_format.apply(name); feature_names.push(p_feature.to_string()); let mut feature_attribute_n = feature_attribute.clone(); if config.feature_peripheral { @@ -153,11 +150,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result } } Peripheral::Single(_) => { - let p_feature = config - .ident_formats - .get("peripheral_feature") - .unwrap() - .apply(&name); + let p_feature = feature_format.apply(&name); if config.feature_peripheral { feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] }) }; diff --git a/src/main.rs b/src/main.rs index 0dc05467..9cc3a5a8 100755 --- a/src/main.rs +++ b/src/main.rs @@ -335,11 +335,11 @@ Ignore this option if you are not building your own FPGA based soft-cores."), } if config.feature_peripheral { features.extend( - util::peripheral_names(&device) + util::peripheral_names(&device, &config) .iter() .map(|s| format!("{s} = []\n")), ); - let add_peripherals: Vec<_> = util::peripheral_names(&device) + let add_peripherals: Vec<_> = util::peripheral_names(&device, &config) .iter() .map(|s| format!("\"{s}\"")) .collect(); diff --git a/src/util.rs b/src/util.rs index aa4dd9bd..2a8795db 100644 --- a/src/util.rs +++ b/src/util.rs @@ -501,17 +501,16 @@ pub fn group_names(d: &Device) -> Vec> { v } -pub fn peripheral_names(d: &Device) -> Vec { +pub fn peripheral_names(d: &Device, config: &Config) -> Vec { let mut v = Vec::new(); + let feature_format = config.ident_formats.get("peripheral_feature").unwrap(); for p in &d.peripherals { match p { Peripheral::Single(info) => { - v.push(replace_suffix(&info.name.to_sanitized_snake_case(), "")); + v.push(replace_suffix(&feature_format.apply(&info.name), "")); } Peripheral::Array(info, dim) => { - v.extend( - svd_rs::array::names(info, dim).map(|n| n.to_sanitized_snake_case().into()), - ); + v.extend(svd_rs::array::names(info, dim).map(|n| feature_format.apply(&n).into())); } } }