pub trait Readable {
type T: UIntLike;
type R: RegisterLongName;
// Required method
fn get(&self) -> Self::T;
// Provided methods
fn read(&self, field: Field<Self::T, Self::R>) -> Self::T { ... }
fn read_as_enum<E: TryFromValue<Self::T, EnumType = E>>(
&self,
field: Field<Self::T, Self::R>,
) -> Option<E> { ... }
fn extract(&self) -> LocalRegisterCopy<Self::T, Self::R> { ... }
fn is_set(&self, field: Field<Self::T, Self::R>) -> bool { ... }
fn any_matching_bits_set(&self, field: FieldValue<Self::T, Self::R>) -> bool { ... }
fn matches_all(&self, field: FieldValue<Self::T, Self::R>) -> bool { ... }
fn matches_any(&self, fields: &[FieldValue<Self::T, Self::R>]) -> bool { ... }
}
Expand description
Readable register
Register which at least supports reading the current value. Only
Readable::get
must be implemented, as for other methods a
default implementation is provided.
A register that is both Readable
and Writeable
will also
automatically be ReadWriteable
, if the RegisterLongName
of
Readable
is the same as that of Writeable
(i.e. not for
Aliased
registers).
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn read_as_enum<E: TryFromValue<Self::T, EnumType = E>>(
&self,
field: Field<Self::T, Self::R>,
) -> Option<E>
fn read_as_enum<E: TryFromValue<Self::T, EnumType = E>>( &self, field: Field<Self::T, Self::R>, ) -> Option<E>
Set the raw register value
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(0) NUMBITS(2) [
Foo = 0,
Bar = 1,
Baz = 2,
],
],
];
let reg: InMemoryRegister<u8, EXAMPLEREG::Register> =
InMemoryRegister::new(2);
match reg.read_as_enum(EXAMPLEREG::TESTFIELD) {
Some(EXAMPLEREG::TESTFIELD::Value::Foo) => "Tock",
Some(EXAMPLEREG::TESTFIELD::Value::Bar) => "is",
Some(EXAMPLEREG::TESTFIELD::Value::Baz) => "awesome!",
None => panic!("boo!"),
};
Sourcefn extract(&self) -> LocalRegisterCopy<Self::T, Self::R>
fn extract(&self) -> LocalRegisterCopy<Self::T, Self::R>
Make a local copy of the register
Sourcefn is_set(&self, field: Field<Self::T, Self::R>) -> bool
fn is_set(&self, field: Field<Self::T, Self::R>) -> bool
Check if one or more bits in a field are set
Sourcefn any_matching_bits_set(&self, field: FieldValue<Self::T, Self::R>) -> bool
fn any_matching_bits_set(&self, field: FieldValue<Self::T, Self::R>) -> bool
Check if any bits corresponding to the mask in the passed FieldValue
are set.
This function is identical to is_set()
but operates on a FieldValue
rather
than a Field
, allowing for checking if any bits are set across multiple,
non-contiguous portions of a bitfield.
Sourcefn matches_all(&self, field: FieldValue<Self::T, Self::R>) -> bool
fn matches_all(&self, field: FieldValue<Self::T, Self::R>) -> bool
Check if all specified parts of a field match
Sourcefn matches_any(&self, fields: &[FieldValue<Self::T, Self::R>]) -> bool
fn matches_any(&self, fields: &[FieldValue<Self::T, Self::R>]) -> bool
Check if any of the passed parts of a field exactly match the contained value. This allows for matching on unset bits, or matching on specific values in multi-bit fields.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.