Skip to content

move reset_value #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn render(
where
F: FnOnce(&mut W) -> &mut W
{
self.register.set(f(&mut W::reset_value()).bits);
self.register.set(f(&mut W { bits: Self::reset_value() }).bits);
}
});

Expand All @@ -104,13 +104,20 @@ pub fn render(
.map(util::hex)
.ok_or_else(|| format!("Register {} has no reset value", register.name))?;

w_impl_items.push(quote! {
reg_impl_items.push(quote! {
/// Reset value of the register
#[inline]
pub const fn reset_value() -> W {
W { bits: #rv }
pub const fn reset_value() -> #rty {
#rv
}
/// Writes the reset value to the register
#[inline]
pub fn reset(&self) {
self.register.set(Self::reset_value())
}
});

w_impl_items.push(quote! {
/// Writes raw bits to the register
#[inline]
pub #unsafety fn bits(&mut self, bits: #rty) -> &mut Self {
Expand All @@ -120,16 +127,6 @@ pub fn render(
});
}

if access == Access::ReadWrite {
reg_impl_items.push(quote! {
/// Writes the reset value to the register
#[inline]
pub fn reset(&self) {
self.write(|w| w)
}
})
}

mod_items.push(quote! {
impl super::#name_pc {
#(#reg_impl_items)*
Expand Down Expand Up @@ -372,7 +369,7 @@ pub fn fields(
#[doc = #description]
#[inline]
pub fn #sc(&self) -> #pc_r {
#pc_r::_from({ #value })
#pc_r::_from( #value )
}
});

Expand Down