Skip to content

Commit 081851e

Browse files
bors[bot]burrbull
andauthored
Merge #622
622: field writer's always generic r=Emilgardis a=burrbull Alternative to #621 Reverts [7606706](7606706) Advantages: - easier generation logic, identical for single fields and field arrays (less potential bugs) - easier to integrate #612 - less boilerplate, faster compilation Disadvantages: - as writer not attached to offsets, not obvious meaning of writer - bigger firmware in debug mode? (need check) Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents c8be313 + f5bfdd2 commit 081851e

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Make field writer always generic around bit offset
1011
- Make binary dependencies optional
1112
- Make JSON and YAML formats optional
1213
- Bump MSRV to 1.60

src/generate/register.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,6 @@ pub fn fields(
696696
}
697697

698698
if !derived {
699-
let (offset, gen_offset) = if field_dim.is_some() {
700-
(quote! { O }, quote! {, const O: u8 })
701-
} else {
702-
(util::unsuffixed(offset as u64), quote! {})
703-
};
704699
let proxy = if width == 1 {
705700
let wproxy = Ident::new(
706701
match mwv {
@@ -718,7 +713,7 @@ pub fn fields(
718713
},
719714
span,
720715
);
721-
quote! { crate::#wproxy<'a, #rty, #name_uc_spec, #name_pc_aw, #offset> }
716+
quote! { crate::#wproxy<'a, #rty, #name_uc_spec, #name_pc_aw, O> }
722717
} else {
723718
let wproxy = Ident::new(
724719
if unsafety {
@@ -729,25 +724,17 @@ pub fn fields(
729724
span,
730725
);
731726
let width = &util::unsuffixed(width as _);
732-
quote! { crate::#wproxy<'a, #rty, #name_uc_spec, #fty, #name_pc_aw, #width, #offset> }
727+
quote! { crate::#wproxy<'a, #rty, #name_uc_spec, #fty, #name_pc_aw, #width, O> }
733728
};
734729
mod_items.extend(quote! {
735730
#[doc = #writerdoc]
736-
pub type #name_pc_w<'a #gen_offset> = #proxy;
731+
pub type #name_pc_w<'a, const O: u8> = #proxy;
737732
});
738733
}
739734
if !proxy_items.is_empty() {
740-
mod_items.extend(if field_dim.is_some() {
741-
quote! {
742-
impl<'a, const O: u8> #name_pc_w<'a, O> {
743-
#proxy_items
744-
}
745-
}
746-
} else {
747-
quote! {
748-
impl<'a> #name_pc_w<'a> {
749-
#proxy_items
750-
}
735+
mod_items.extend(quote! {
736+
impl<'a, const O: u8> #name_pc_w<'a, O> {
737+
#proxy_items
751738
}
752739
});
753740
}
@@ -784,10 +771,11 @@ pub fn fields(
784771
}
785772
} else {
786773
let doc = description_with_bits(description_raw, offset, width);
774+
let offset = util::unsuffixed(offset as u64);
787775
w_impl_items.extend(quote! {
788776
#[doc = #doc]
789777
#inline
790-
pub fn #name_sc(&mut self) -> #name_pc_w {
778+
pub fn #name_sc(&mut self) -> #name_pc_w<#offset> {
791779
#name_pc_w::new(self)
792780
}
793781
});

0 commit comments

Comments
 (0)