Skip to content

Commit ca576c3

Browse files
committed
const-generic feature
1 parent 541b7d7 commit ca576c3

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

.github/bors.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ status = [
1515
"ci-linux (stable, Spansion, x86_64-unknown-linux-gnu, linux)",
1616
"ci-linux (stable, STMicro, x86_64-unknown-linux-gnu, linux)",
1717
"ci-linux (stable, Toshiba, x86_64-unknown-linux-gnu, linux)",
18-
"ci-linux (1.51.0, Nordic, x86_64-unknown-linux-gnu, linux)",
18+
"ci-linux (1.40.0, Nordic, x86_64-unknown-linux-gnu, linux)",
1919
"ci-linux (stable, x86_64-apple-darwin, osx)",
2020
"ci-linux (stable, x86_64-pc-windows-msvc, windows)",
2121
]

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
include:
2727
# Test MSRV
28-
- rust: 1.51.0
28+
- rust: 1.40.0
2929
VENDOR: Nordic
3030
TARGET: x86_64-unknown-linux-gnu
3131
TRAVIS_OS_NAME: linux

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3030

3131
### Changed
3232

33-
- [breaking-change] support for "field arrays"
33+
- [breaking-change] support for "field arrays".
34+
With feature "const-generic" it also generates const generic variant of
35+
field arrat structure (requires rust 1.51)
3436

3537
- [breaking-change] remove `Variant<U, ENUM_A>`, use `Option<ENUM_A>` instead
3638

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ features = ["full","extra-traits"]
5252

5353
[features]
5454
strict = ["svd-parser/strict"]
55+
const-generic = []

src/generate/register.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ pub fn fields(
563563
if can_write {
564564
let new_pc_aw = Ident::new(&(name_pc.clone() + "_AW"), span);
565565
let name_pc_w = Ident::new(&(name_pc.clone() + "_W"), span);
566+
#[cfg(feature = "const-generic")]
566567
let name_pc_cgw = Ident::new(&(name_pc.clone() + "_CGW"), span);
567568

568569
let mut proxy_items = TokenStream::new();
@@ -641,6 +642,7 @@ pub fn fields(
641642
}
642643

643644
let mut proxy_items_fa = TokenStream::new();
645+
#[cfg(feature = "const-generic")]
644646
let mut proxy_items_cg = TokenStream::new();
645647
if field_dim.is_some() {
646648
proxy_items_fa.extend(quote! {
@@ -651,6 +653,7 @@ pub fn fields(
651653
self.w
652654
}
653655
});
656+
#[cfg(feature="const-generic")]
654657
proxy_items_cg.extend(quote! {
655658
///Writes raw bits to the field
656659
#inline
@@ -682,13 +685,17 @@ pub fn fields(
682685
});
683686
}
684687

688+
#[cfg(feature = "const-generic")]
685689
let mut cgdoc = String::new();
686690
let doc = if let Some((_, _, _, _, suffixes_str)) = &field_dim {
687-
cgdoc = format!(
688-
"Fields `{}` const generic writer - {}",
689-
util::replace_suffix(&f.name, suffixes_str),
690-
description
691-
);
691+
#[cfg(feature = "const-generic")]
692+
{
693+
cgdoc = format!(
694+
"Fields `{}` const generic writer - {}",
695+
util::replace_suffix(&f.name, suffixes_str),
696+
description
697+
);
698+
}
692699
format!(
693700
"Fields `{}` writer - {}",
694701
util::replace_suffix(&f.name, suffixes_str),
@@ -698,8 +705,8 @@ pub fn fields(
698705
format!("Field `{}` writer - {}", f.name, description)
699706
};
700707

701-
mod_items.extend(if field_dim.is_some() {
702-
quote! {
708+
if field_dim.is_some() {
709+
mod_items.extend(quote! {
703710
#[doc = #doc]
704711
pub struct #name_pc_w<'a> {
705712
w: &'a mut W,
@@ -710,7 +717,10 @@ pub fn fields(
710717
#proxy_items
711718
#proxy_items_fa
712719
}
720+
});
713721

722+
#[cfg(feature = "const-generic")]
723+
mod_items.extend(quote! {
714724
#[doc = #cgdoc]
715725
pub struct #name_pc_cgw<'a, const O: usize> {
716726
w: &'a mut W,
@@ -720,9 +730,9 @@ pub fn fields(
720730
#proxy_items
721731
#proxy_items_cg
722732
}
723-
}
733+
});
724734
} else {
725-
quote! {
735+
mod_items.extend(quote! {
726736
#[doc = #doc]
727737
pub struct #name_pc_w<'a> {
728738
w: &'a mut W,
@@ -731,8 +741,8 @@ pub fn fields(
731741
impl<'a> #name_pc_w<'a> {
732742
#proxy_items
733743
}
734-
}
735-
});
744+
});
745+
}
736746

737747
if let Some((first, dim, increment, suffixes, suffixes_str)) = &field_dim {
738748
let offset_calc = calculate_offset(*first, *increment, offset);
@@ -755,6 +765,15 @@ pub fn fields(
755765
&suffix,
756766
);
757767
let sub_offset = util::unsuffixed(sub_offset as u64);
768+
#[cfg(not(feature = "const-generic"))]
769+
w_impl_items.extend(quote! {
770+
#[doc = #doc]
771+
#inline
772+
pub fn #name_sc_n(&mut self) -> #name_pc_w {
773+
#name_pc_w { w: self, offset: #sub_offset }
774+
}
775+
});
776+
#[cfg(feature = "const-generic")]
758777
w_impl_items.extend(quote! {
759778
#[doc = #doc]
760779
#inline

0 commit comments

Comments
 (0)