diff --git a/CHANGELOG.md b/CHANGELOG.md index ff18bf37..30656bbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- split out register size type (`RawType`) from `ResetValue` trait + - `anyhow` crate is used for error handling - [breaking-change] Among other cleanups, MSP430 crates are now expected to diff --git a/src/generate/generic.rs b/src/generate/generic.rs index f327fb1c..749b7d51 100644 --- a/src/generate/generic.rs +++ b/src/generate/generic.rs @@ -12,16 +12,19 @@ pub trait Readable {} /// Registers marked with `Readable` can be also `modify`'ed. pub trait Writable {} + +/// Raw register type (autoimplemented for `Reg` type) +pub trait RawType { + /// Raw register type (`u8`, `u16`, `u32`, ...). + type Ux: Copy; +} /// Reset value of the register. /// /// This value is the initial value for the `write` method. It can also be directly written to the /// register by using the `reset` method. -pub trait ResetValue { - /// Raw register type (`u8`, `u16`, `u32`, ...). - type Type; - +pub trait ResetValue: RawType { /// Reset value of the register. - fn reset_value() -> Self::Type; + fn reset_value() -> Self::Ux; } /// This structure provides volatile access to registers. @@ -73,9 +76,16 @@ where } } +impl RawType for Reg +where + U: Copy, +{ + type Ux = U; +} + impl Reg where - Self: ResetValue + Writable, + Self: ResetValue + RawType + Writable, U: Copy, { /// Writes the reset value to `Writable` register. @@ -89,8 +99,8 @@ where impl Reg where - Self: ResetValue + Writable, - U: Copy, + Self: ResetValue + RawType + Writable, + U: Copy { /// Writes bits to a `Writable` register. /// diff --git a/src/generate/register.rs b/src/generate/register.rs index 148714bd..5bba775f 100644 --- a/src/generate/register.rs +++ b/src/generate/register.rs @@ -72,9 +72,8 @@ pub fn render( mod_items.extend(quote! { #[doc = #doc] impl crate::ResetValue for super::#name_pc { - type Type = #rty; #[inline(always)] - fn reset_value() -> Self::Type { #rv } + fn reset_value() -> Self::Ux { #rv } } }); methods.push("reset");