Skip to content
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
10 changes: 2 additions & 8 deletions src/generate/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ pub trait ResetValue {
fn reset_value() -> Self::Type;
}

///Converting enumerated values to bits
pub trait ToBits<N> {
///Conversion method
fn _bits(&self) -> N;
}

///This structure provides volatile access to register
pub struct Reg<U, REG> {
register: vcell::VolatileCell<U>,
Expand Down Expand Up @@ -181,11 +175,11 @@ where
impl<U, T, FI> PartialEq<FI> for R<U, T>
where
U: PartialEq,
FI: ToBits<U>
FI: Copy+Into<U>
{
#[inline(always)]
fn eq(&self, other: &FI) -> bool {
self.bits.eq(&other._bits())
self.bits.eq(&(*other).into())
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,8 @@ pub fn fields(
///Writes `variant` to the field
#[inline(always)]
pub fn variant(self, variant: #pc_w) -> &'a mut W {
use crate::ToBits;
#unsafety {
self.#bits(variant._bits())
self.#bits(variant.into())
}
}
});
Expand Down Expand Up @@ -657,10 +656,10 @@ fn add_from_variants(mod_items: &mut Vec<Tokens>, variants: &Vec<Variant>, pc: &
});

mod_items.push(quote! {
impl crate::ToBits<#fty> for #pc {
impl From<#pc> for #fty {
#[inline(always)]
fn _bits(&self) -> #fty {
match *self {
fn from(variant: #pc) -> Self {
match variant {
#(#arms),*
}
}
Expand Down