tock_registers::fields

Struct Field

Source
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>

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: 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>

Source

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

Source§

impl<R: RegisterLongName> Field<u16, R>

Source

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

Source§

impl<R: RegisterLongName> Field<u32, R>

Source

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

Source§

impl<R: RegisterLongName> Field<u64, R>

Source

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

Source§

impl<R: RegisterLongName> Field<u128, R>

Source

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

Source§

impl<R: RegisterLongName> Field<usize, R>

Source

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

Trait Implementations§

Source§

impl<T: UIntLike, R: RegisterLongName> Clone for Field<T, R>

Source§

fn clone(&self) -> Self

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: 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>

§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.