Struct peripherals::Field[][src]

pub struct Field<R, T, I> { /* fields omitted */ }

A single register field

Created by:

  • Associated constants on register defined with the periph! or the register! macros.

Usable with:

These fields be combined together with |, & and ^, producing Fields.

Example

use peripherals::{register, Value};

register! {
    Register: u8 = 0b1001 {
        BIT1: 0 = struct Bit1(bool);
        BIT2: 1 = struct Bit2(bool);
        TWO_BITS: 2..3 = struct TwoBits(u8);
    }
}

// Obtain it from the associated constants on the register
assert_eq!(Register::BIT1.mask(), 0b0001);
assert_eq!(Register::TWO_BITS.mask(), 0b1100);

// Use it to read fields
let mut value = Value::reset();
assert_eq!(value.value(), 0b1001);

assert_eq!(value.field(Register::BIT1), Bit1(true));
assert_eq!(value.field(Register::BIT2), Bit2(false));
assert_eq!(value.field(Register::TWO_BITS), TwoBits(0b10));

// Toggle single-bit fields
value ^= Register::BIT1;
assert_eq!(value.value(), 0b1000);
value ^= Register::BIT2;
assert_eq!(value.value(), 0b1010);

Implementations

impl<R, T, I> Field<R, T, I>[src]

pub fn mask(self) -> I[src]

Get the raw mask

pub fn offset(self) -> usize[src]

Get the field offset

pub const unsafe fn from_raw(mask: I, offset: usize) -> Field<R, T, I>[src]

Build from raw mask

Safety

You should ensure the mask is valid for the fields of the associated register.

Trait Implementations

impl<R: RegisterValue, T: Into<Fields<R>>, U: MayToggle> BitAnd<T> for Field<R, U, R::Int> where
    T: Either<U::Toggle>, 
[src]

type Output = Fields<R, T::Output>

The resulting type after applying the & operator.

fn bitand(self, other: T) -> Self::Output[src]

Performs the & operation. Read more

impl<R: RegisterValue, T: Into<Fields<R>>, U: MayToggle> BitOr<T> for Field<R, U, R::Int> where
    T: Both<U::Toggle>, 
[src]

type Output = Fields<R, T::Output>

The resulting type after applying the | operator.

fn bitor(self, other: T) -> Self::Output[src]

Performs the | operation. Read more

impl<R: RegisterValue, T: Into<Fields<R>>, U: MayToggle> BitXor<T> for Field<R, U, R::Int> where
    T: Both<U::Toggle>, 
[src]

type Output = Fields<R, T::Output>

The resulting type after applying the ^ operator.

fn bitxor(self, other: T) -> Self::Output[src]

Performs the ^ operation. Read more

impl<R: RegisterValue, T> Clone for Field<R, T, R::Int>[src]

fn clone(&self) -> Field<R, T, R::Int>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<R: RegisterValue, T> Debug for Field<R, T, R::Int>[src]

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<R: RegisterValue, T> From<Field<R, T, <R as RegisterValue>::Int>> for Fields<R, ()>[src]

fn from(field: Field<R, T, R::Int>) -> Fields<R, ()>[src]

Performs the conversion.

impl<R: RegisterValue, T: MayToggle<Toggle = Toggle>> From<Field<R, T, <R as RegisterValue>::Int>> for Fields<R, Toggle>[src]

fn from(field: Field<R, T, R::Int>) -> Fields<R, Toggle>[src]

Performs the conversion.

impl<R: RegisterValue, T: MayToggle> MayToggle for Field<R, T, R::Int>[src]

type Toggle = T::Toggle

Toggle if it can be toggled, () otherwise

impl<R: RegisterValue, T: Into<Fields<R>> + Copy, U> PartialEq<T> for Field<R, U, R::Int>[src]

fn eq(&self, other: &T) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<R: RegisterValue, T> Copy for Field<R, T, R::Int>[src]

impl<R: RegisterValue, T> Eq for Field<R, T, R::Int>[src]

Auto Trait Implementations

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.