Skip to content

split out register size type from ResetValue trait #431

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
Jun 2, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 18 additions & 8 deletions src/generate/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -73,9 +76,16 @@ where
}
}

impl<U, REG> RawType for Reg<U, REG>
where
U: Copy,
{
type Ux = U;
}

impl<U, REG> Reg<U, REG>
where
Self: ResetValue<Type = U> + Writable,
Self: ResetValue + RawType<Ux = U> + Writable,
U: Copy,
{
/// Writes the reset value to `Writable` register.
Expand All @@ -89,8 +99,8 @@ where

impl<U, REG> Reg<U, REG>
where
Self: ResetValue<Type = U> + Writable,
U: Copy,
Self: ResetValue + RawType<Ux = U> + Writable,
U: Copy
{
/// Writes bits to a `Writable` register.
///
Expand Down
3 changes: 1 addition & 2 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down