Struct kernel::utilities::registers::Field

source ·
pub struct Field<T, R>{
    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, R> Field<T, R>

source

pub const fn new(mask: T, shift: usize) -> Field<T, R>

source

pub fn read(self, val: T) -> T

source

pub fn is_set(self, val: T) -> bool

Check if one or more bits in a field are set

source

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
);
source§

impl<R> Field<u8, R>

source

pub const fn val(&self, value: u8) -> FieldValue<u8, R>

source§

impl<R> Field<u16, R>

source

pub const fn val(&self, value: u16) -> FieldValue<u16, R>

source§

impl<R> Field<u32, R>

source

pub const fn val(&self, value: u32) -> FieldValue<u32, R>

source§

impl<R> Field<u64, R>

source

pub const fn val(&self, value: u64) -> FieldValue<u64, R>

source§

impl<R> Field<u128, R>

source

pub const fn val(&self, value: u128) -> FieldValue<u128, R>

source§

impl<R> Field<usize, R>

source

pub const fn val(&self, value: usize) -> FieldValue<usize, R>

Trait Implementations§

source§

impl<T, R> Clone for Field<T, R>

source§

fn clone(&self) -> Field<T, R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, R> 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>

§

impl<T, R> Send for Field<T, R>
where T: Send, R: Send,

§

impl<T, R> Sync for Field<T, R>
where T: Sync, R: Sync,

§

impl<T, R> Unpin for Field<T, R>
where T: Unpin, R: Unpin,

§

impl<T, R> UnwindSafe for Field<T, R>
where T: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> SizedTypeProperties for T

source§

#[doc(hidden)] const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.