Type Alias GpioBitfield

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

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

Source

pub const fn val(&self, value: u32) -> FieldValue<u32, 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>