pub struct Field<T: UIntLike, R: RegisterLongName> {
pub mask: T,
pub shift: usize,
/* private fields */
}
Expand description
Specific section of a register.
For the Field, the mask is unshifted, ie. the LSB should always be set.
Fields§
§mask: T
§shift: usize
Implementations§
Source§impl<T: UIntLike, R: RegisterLongName> Field<T, R>
impl<T: UIntLike, R: RegisterLongName> Field<T, R>
pub const fn new(mask: T, shift: usize) -> Field<T, R>
pub fn read(self, val: T) -> T
Sourcepub fn read_as_enum<E: TryFromValue<T, EnumType = E>>(self, val: T) -> Option<E>
pub fn read_as_enum<E: TryFromValue<T, EnumType = E>>(self, val: T) -> Option<E>
Read value of the field as an enum member
This method expects to be passed the unasked and unshifted register
value, extracts the field value by calling Field::read
and
subsequently passes that value to the TryFromValue
implementation on
the passed enum type.
The register_bitfields!
macro will
generate an enum containing the various named field variants and
implementing the required TryFromValue
trait. It is accessible as
$REGISTER_NAME::$FIELD_NAME::Value
.
This method can be useful to symbolically represent read register field states throughout the codebase and to enforce exhaustive matches over all defined valid register field values.
§Usage Example
register_bitfields![u8,
EXAMPLEREG [
TESTFIELD OFFSET(3) NUMBITS(3) [
Foo = 2,
Bar = 3,
Baz = 6,
],
],
];
assert_eq!(
EXAMPLEREG::TESTFIELD.read_as_enum::<EXAMPLEREG::TESTFIELD::Value>(0x9C).unwrap(),
EXAMPLEREG::TESTFIELD::Value::Bar
);
Source§impl<R: RegisterLongName> Field<u8, R>
impl<R: RegisterLongName> Field<u8, R>
pub const fn val(&self, value: u8) -> FieldValue<u8, R>
Source§impl<R: RegisterLongName> Field<u16, R>
impl<R: RegisterLongName> Field<u16, R>
pub const fn val(&self, value: u16) -> FieldValue<u16, R>
Source§impl<R: RegisterLongName> Field<u32, R>
impl<R: RegisterLongName> Field<u32, R>
pub const fn val(&self, value: u32) -> FieldValue<u32, R>
Source§impl<R: RegisterLongName> Field<u64, R>
impl<R: RegisterLongName> Field<u64, R>
pub const fn val(&self, value: u64) -> FieldValue<u64, R>
Source§impl<R: RegisterLongName> Field<u128, R>
impl<R: RegisterLongName> Field<u128, R>
pub const fn val(&self, value: u128) -> FieldValue<u128, R>
Source§impl<R: RegisterLongName> Field<usize, R>
impl<R: RegisterLongName> Field<usize, R>
pub const fn val(&self, value: usize) -> FieldValue<usize, R>
Trait Implementations§
impl<T: UIntLike, R: RegisterLongName> Copy for Field<T, R>
Auto Trait Implementations§
impl<T, R> Freeze for Field<T, R>where
T: Freeze,
impl<T, R> RefUnwindSafe for Field<T, R>where
T: RefUnwindSafe,
R: RefUnwindSafe,
impl<T, R> Send for Field<T, R>
impl<T, R> Sync for Field<T, R>
impl<T, R> Unpin for Field<T, R>
impl<T, R> UnwindSafe for Field<T, R>where
T: UnwindSafe,
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more