Struct peripherals::Value[][src]

pub struct Value<R: RegisterValue> { /* fields omitted */ }
Expand description

A value read from or to be written to a register

Created by:

  • Reg::read: read the value from the register.
  • Default or the Value::reset: the reset value of the register.

Usable with:

Values can be modified with the | and ^ operators, and well as with |= and ^=.

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 with the `reset` method or by reading the register
let mut value = Value::<Register>::reset();
assert_eq!(value.value(), 0b1001);

/// Extract single field
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));

// Extract multiple fields
let fields_12 = value & (Register::BIT1 | Register::BIT2);
assert_eq!(fields_12.bits(), 0b001);
assert_eq!((value & Register::TWO_BITS).bits(), 0b1000);

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

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

// Modify fields
value |= Bit1(false);
assert_eq!(value.value(), 0b1000);
value |= TwoBits(0b01);
assert_eq!(value.value(), 0b0100);

Implementations

impl<R: RegisterValue> Value<R>[src]

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

Get the raw value

pub unsafe fn from_raw(value: R::Int) -> Value<R>[src]

Build from a raw value

Safety

You must ensure the value is valid for the associated register.

pub fn field<T>(self, field: Field<R, T, R::Int>) -> T where
    R::Int: TryInto<T>,
    <R::Int as TryInto<T>>::Error: Debug
[src]

Read the given field

This returns the value of a field defined with the periph! or register! macro.

pub fn test<B: Into<FieldValues<R>>>(self, bits: B) -> bool[src]

Test the given fields

This returns true if the field has the value given in parameter. It can also be used with more values, combined with |, in which case all fields must match.

pub fn reset() -> Value<R>[src]

Get the default / reset value

This returns to the value that the register has right right after a reset or a boot.

Trait Implementations

impl<R: RegisterValue, T: Into<Fields<R>> + MayToggle> BitAnd<T> for Value<R>[src]

type Output = FieldValues<R, T::Toggle>

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<FieldValues<R>>> BitOr<T> for Value<R>[src]

type Output = Value<R>

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<FieldValues<R>>> BitOrAssign<T> for Value<R>[src]

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

Performs the |= operation. Read more

impl<R: RegisterValue, T: Into<Fields<R, Toggle>>> BitXor<T> for Value<R>[src]

type Output = Value<R>

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, Toggle>>> BitXorAssign<T> for Value<R>[src]

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

Performs the ^= operation. Read more

impl<R: RegisterValue> Clone for Value<R>[src]

fn clone(&self) -> Value<R>[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> Debug for Value<R>[src]

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

Formats the value using the given formatter. Read more

impl<R: RegisterValue> Default for Value<R>[src]

fn default() -> Value<R>[src]

Returns the “default value” for a type. Read more

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

impl<R: RegisterValue> Eq for Value<R>[src]

Auto Trait Implementations

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

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

impl<R> Unpin for Value<R> where
    R: 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.