diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe26557..6eb4b26b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] +- Add warning about indexing register arrays - Skip generating `.add(0)` and `1 *` in accessors - Bump MSRV of generated code to 1.76 - move `must_use` from methods to generic type diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 6a183557..9e3101ec 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -1052,6 +1052,10 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result`n` is the index of {0} in the array. `n == 0` corresponds to `{first_name}` {0}.", "cluster") + ); accessors.push( Accessor::Array(ArrayAccessor { doc, @@ -1060,6 +1064,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result`n` is the index of {0} in the array. `n == 0` corresponds to `{first_name}` {0}.", "register") + ); accessors.push( Accessor::Array(ArrayAccessor { doc, @@ -1242,6 +1251,7 @@ fn expand_register( offset: info.address_offset, dim: array_info.dim, increment: array_info.dim_increment, + note, }) .raw_if(!array_convertible), ); diff --git a/src/generate/peripheral/accessor.rs b/src/generate/peripheral/accessor.rs index 85f663d4..5bb91718 100644 --- a/src/generate/peripheral/accessor.rs +++ b/src/generate/peripheral/accessor.rs @@ -62,10 +62,15 @@ impl ToTokens for AccessType { } } } - Self::Ref(Accessor::Array(ArrayAccessor { doc, name, ty, .. })) => { + Self::Ref(Accessor::Array(ArrayAccessor { doc, name, ty, note, .. })) => { let name_iter = Ident::new(&format!("{name}_iter"), Span::call_site()); + let note = note.as_ref().map(|note| quote! { + #[doc = ""] + #[doc = #note] + }); quote! { #[doc = #doc] + #note #[inline(always)] pub const fn #name(&self, n: usize) -> &#ty { &self.#name[n] @@ -85,14 +90,20 @@ impl ToTokens for AccessType { offset, dim, increment, + note, })) => { let name_iter = Ident::new(&format!("{name}_iter"), Span::call_site()); let offset = (*offset != 0).then(|| unsuffixed(*offset)).map(|o| quote!(.add(#o))); let dim = unsuffixed(*dim); let increment = (*increment != 1).then(|| unsuffixed(*increment)).map(|i| quote!(#i *)); + let note = note.as_ref().map(|note| quote! { + #[doc = ""] + #[doc = #note] + }); let cast = quote! { unsafe { &*core::ptr::from_ref(self).cast::() #offset .add(#increment n).cast() } }; quote! { #[doc = #doc] + #note #[inline(always)] pub const fn #name(&self, n: usize) -> &#ty { #[allow(clippy::no_effect)] @@ -145,6 +156,7 @@ pub struct ArrayAccessor { pub offset: u32, pub dim: u32, pub increment: u32, + pub note: Option, } #[derive(Clone, Debug)]