Trait kernel::utilities::registers::interfaces::Readable

source ·
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>(&self, field: Field<Self::T, Self::R>) -> Option<E>
       where E: TryFromValue<Self::T, EnumType = 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§

source

fn get(&self) -> Self::T

Get the raw register value

Provided Methods§

source

fn read(&self, field: Field<Self::T, Self::R>) -> Self::T

Read the value of the given field

source

fn read_as_enum<E>(&self, field: Field<Self::T, Self::R>) -> Option<E>
where E: TryFromValue<Self::T, EnumType = 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!"),
};
source

fn extract(&self) -> LocalRegisterCopy<Self::T, Self::R>

Make a local copy of the register

source

fn is_set(&self, field: Field<Self::T, Self::R>) -> bool

Check if one or more bits in a field are set

source

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.

source

fn matches_all(&self, field: FieldValue<Self::T, Self::R>) -> bool

Check if all specified parts of a field match

source

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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, R> Readable for InMemoryRegister<T, R>

§

type T = T

§

type R = R

source§

impl<T, R> Readable for ReadOnly<T, R>

§

type T = T

§

type R = R

source§

impl<T, R> Readable for ReadWrite<T, R>

§

type T = T

§

type R = R

source§

impl<T, R, W> Readable for Aliased<T, R, W>

§

type T = T

§

type R = R