Skip to content

Enable code generation in the absence of register reset values. #175

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

Closed
Closed
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
63 changes: 33 additions & 30 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,19 +759,6 @@ pub fn register(
}

if access == Access::WriteOnly || access == Access::ReadWrite {
reg_impl_items.push(quote! {
/// Writes to the register
#[inline]
pub fn write<F>(&self, f: F)
where
F: FnOnce(&mut W) -> &mut W
{
let mut w = W::reset_value();
f(&mut w);
self.register.set(w.bits);
}
});

mod_items.push(quote! {
/// Value to write to the register
pub struct W {
Expand All @@ -782,16 +769,42 @@ pub fn register(
let rv = register
.reset_value
.or(defs.reset_value)
.map(|rv| util::hex(rv))
.ok_or_else(|| format!("Register {} has no reset value", register.name))?;
.map(|rv| util::hex(rv));

w_impl_items.push(quote! {
/// Reset value of the register
#[inline]
pub fn reset_value() -> W {
W { bits: #rv }
if let Some(rv) = rv {
reg_impl_items.push(quote! {
/// Writes to the register
#[inline]
pub fn write<F>(&self, f: F)
where
F: FnOnce(&mut W) -> &mut W
{
let mut w = W::reset_value();
f(&mut w);
self.register.set(w.bits);
}
});

w_impl_items.push(quote! {
/// Reset value of the register
#[inline]
pub fn reset_value() -> W {
W { bits: #rv }
}
});

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)
}
});
}
}

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

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