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 theValue::reset
: the reset value of the register.
Usable with:
Reg::write
: write the value to the register.Value
&
Fields
extractsFieldValues
.
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]
impl<R: RegisterValue> Value<R>
[src]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]
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]pub fn test<B: Into<FieldValues<R>>>(self, bits: B) -> bool
[src]
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.
Trait Implementations
impl<R: RegisterValue, T: Into<FieldValues<R>>> BitOr<T> for Value<R>
[src]
impl<R: RegisterValue, T: Into<FieldValues<R>>> BitOr<T> for Value<R>
[src]impl<R: RegisterValue, T: Into<FieldValues<R>>> BitOrAssign<T> for Value<R>
[src]
impl<R: RegisterValue, T: Into<FieldValues<R>>> BitOrAssign<T> for Value<R>
[src]fn bitor_assign(&mut self, other: T)
[src]
fn bitor_assign(&mut self, other: T)
[src]Performs the |=
operation. Read more
impl<R: RegisterValue, T: Into<Fields<R, Toggle>>> BitXorAssign<T> for Value<R>
[src]
impl<R: RegisterValue, T: Into<Fields<R, Toggle>>> BitXorAssign<T> for Value<R>
[src]fn bitxor_assign(&mut self, other: T)
[src]
fn bitxor_assign(&mut self, other: T)
[src]Performs the ^=
operation. Read more
impl<R: RegisterValue> Clone for Value<R>
[src]
impl<R: RegisterValue> Clone for Value<R>
[src]impl<R: RegisterValue> Debug for Value<R>
[src]
impl<R: RegisterValue> Debug for Value<R>
[src]impl<R: RegisterValue> Default for Value<R>
[src]
impl<R: RegisterValue> Default for Value<R>
[src]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,
R: Send,
<R as RegisterValue>::Int: Send,
impl<R> Sync for Value<R> where
R: Sync,
<R as RegisterValue>::Int: Sync,
R: Sync,
<R as RegisterValue>::Int: Sync,
impl<R> Unpin for Value<R> where
R: Unpin,
<R as RegisterValue>::Int: Unpin,
R: Unpin,
<R as RegisterValue>::Int: Unpin,