Struct peripherals::Fields[][src]

pub struct Fields<R: RegisterValue, T = ()> { /* fields omitted */ }
Expand description

A set of register fields

Created by:

Usable with:

These fields be combined together with |, & and ^. For operators that returns the same type as their first operand, the “assign” form (i.e. |=, &= and ^=) can also be used.

Example

use peripherals::{register, Fields, Value};

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

// Obtain it with the `empty` method or by combining fields
let empty = Fields::<Register>::empty();
assert_eq!(empty.mask(), 0b0000);
let bits_12 = Register::BIT1 | Register::BIT2;
assert_eq!(bits_12.mask(), 0b0011);
let fields = Register::BIT1 | Register::TWO_BITS;
assert_eq!(fields.mask(), 0b1101);

// Combine fields together
assert_eq!(bits_12 | fields, Register::BIT1 | Register::BIT2 | Register::TWO_BITS);
assert_eq!(bits_12 & fields, Register::BIT1);
assert_eq!(bits_12 ^ fields, Register::BIT2 | Register::TWO_BITS);

assert_eq!(bits_12 | empty, bits_12);
assert_eq!(bits_12 & empty, empty);
assert_eq!(bits_12 ^ empty, bits_12);

let mut value = Value::reset();
assert_eq!(value.value(), 0b1001);

// Use it to read fields
let value_12 = value & (Register::BIT1 | Register::BIT2);
assert_eq!(value_12.bits(), 0b001);
assert_eq!((value & Register::TWO_BITS).bits(), 0b1000);

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

// Write back bits previously read
value |= value_12;
assert_eq!(value.value(), 0b1001);

Implementations

impl<R: RegisterValue, T> Fields<R, T>[src]

pub fn mask(self) -> R::Int[src]

Get the raw mask

pub unsafe fn from_raw(mask: R::Int) -> Fields<R, T>[src]

Build from raw mask

Safety

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

pub fn empty() -> Fields<R, T>[src]

An empty set with no fields

Trait Implementations

impl<R: RegisterValue, T: Into<Fields<R>>, U> BitAnd<T> for Fields<R, U> where
    T: Either<U>, 
[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> BitAndAssign<T> for Fields<R, U> where
    T: Either<U, Output = U>, 
[src]

fn bitand_assign(&mut self, other: T)[src]

Performs the &= operation. Read more

impl<R: RegisterValue, T: Into<Fields<R>>, U> BitOr<T> for Fields<R, U> where
    T: Both<U>, 
[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> BitOrAssign<T> for Fields<R, U> where
    T: Both<U, Output = U>, 
[src]

fn bitor_assign(&mut self, other: T)[src]

Performs the |= operation. Read more

impl<R: RegisterValue, T: Into<Fields<R>>, U> BitXor<T> for Fields<R, U> where
    T: Both<U>, 
[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: Into<Fields<R>>, U> BitXorAssign<T> for Fields<R, U> where
    T: Both<U, Output = U>, 
[src]

fn bitxor_assign(&mut self, other: T)[src]

Performs the ^= operation. Read more

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

fn clone(&self) -> Fields<R, T>[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 Fields<R, T>[src]

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

Formats the value using the given formatter. Read more

impl<R: RegisterValue, T> Default for Fields<R, T>[src]

fn default() -> Fields<R, T>[src]

Returns the “default value” for a type. 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> From<Fields<R, Toggle>> for Fields<R, ()>[src]

fn from(fields: Fields<R, Toggle>) -> Fields<R, ()>[src]

Performs the conversion.

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

type Toggle = T

Toggle if it can be toggled, () otherwise

impl<R: RegisterValue, T: Into<Fields<R>> + Copy, U> PartialEq<T> for Fields<R, U>[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 Fields<R, T>[src]

Auto Trait Implementations

impl<R, T> Send for Fields<R, T> where
    R: Send,
    T: Send,
    <R as RegisterValue>::Int: Send

impl<R, T> Sync for Fields<R, T> where
    R: Sync,
    T: Sync,
    <R as RegisterValue>::Int: Sync

impl<R, T> Unpin for Fields<R, T> where
    R: Unpin,
    T: Unpin,
    <R as RegisterValue>::Int: 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.