pub type GpioBitfield = Field<u32, Register>;
Aliased Type§
struct GpioBitfield {
pub mask: u32,
pub shift: usize,
/* private fields */
}
Fields§
§mask: u32
§shift: usize
Implementations
Source§impl<T, R> Field<T, R>where
T: UIntLike,
R: RegisterLongName,
impl<T, R> Field<T, R>where
T: UIntLike,
R: RegisterLongName,
pub const fn new(mask: T, shift: usize) -> Field<T, R>
pub fn read(self, val: T) -> T
Sourcepub fn read_as_enum<E>(self, val: T) -> Option<E>where
E: TryFromValue<T, EnumType = E>,
pub fn read_as_enum<E>(self, val: T) -> Option<E>where
E: TryFromValue<T, EnumType = 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
);