pub struct Fields<R: RegisterValue, T = ()> { /* private fields */ }
Expand description
A set of register fields
§Created by:
- Combining (with
|
) fields generated by the [periph!
] or the [register!
] macro. Default
orFields::empty
: a set with no fields.
§Usable with:
Reg::fields
orValue
&
Fields
: read someFieldValues
from the register. They can then be compared or written back.Reg::toggle
orValue
^
Fields
: toggle these fields (only for single-bit fields).
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§
Source§impl<R: RegisterValue, T> Fields<R, T>
impl<R: RegisterValue, T> Fields<R, T>
Trait Implementations§
Source§impl<R: RegisterValue, T, U> BitAnd<T> for Fields<R, U>
impl<R: RegisterValue, T, U> BitAnd<T> for Fields<R, U>
Source§impl<R: RegisterValue, T, U> BitAndAssign<T> for Fields<R, U>
impl<R: RegisterValue, T, U> BitAndAssign<T> for Fields<R, U>
Source§fn bitand_assign(&mut self, other: T)
fn bitand_assign(&mut self, other: T)
Performs the
&=
operation. Read moreSource§impl<R: RegisterValue, T, U> BitOr<T> for Fields<R, U>
impl<R: RegisterValue, T, U> BitOr<T> for Fields<R, U>
Source§impl<R: RegisterValue, T, U> BitOrAssign<T> for Fields<R, U>
impl<R: RegisterValue, T, U> BitOrAssign<T> for Fields<R, U>
Source§fn bitor_assign(&mut self, other: T)
fn bitor_assign(&mut self, other: T)
Performs the
|=
operation. Read moreSource§impl<R: RegisterValue, T, U> BitXor<T> for Fields<R, U>
impl<R: RegisterValue, T, U> BitXor<T> for Fields<R, U>
Source§impl<R: RegisterValue, T, U> BitXorAssign<T> for Fields<R, U>
impl<R: RegisterValue, T, U> BitXorAssign<T> for Fields<R, U>
Source§fn bitxor_assign(&mut self, other: T)
fn bitxor_assign(&mut self, other: T)
Performs the
^=
operation. Read moreSource§impl<R: RegisterValue, T> Clone for Fields<R, T>
impl<R: RegisterValue, T> Clone for Fields<R, T>
Source§impl<R: RegisterValue, T> Debug for Fields<R, T>
impl<R: RegisterValue, T> Debug for Fields<R, T>
Source§impl<R: RegisterValue, T> Default for Fields<R, T>
impl<R: RegisterValue, T> Default for Fields<R, T>
Source§impl<R: RegisterValue, T> From<Field<R, T, <R as RegisterValue>::Int>> for Fields<R, ()>
impl<R: RegisterValue, T> From<Field<R, T, <R as RegisterValue>::Int>> for Fields<R, ()>
Source§impl<R: RegisterValue, T: MayToggle<Toggle = Toggle>> From<Field<R, T, <R as RegisterValue>::Int>> for Fields<R, Toggle>
impl<R: RegisterValue, T: MayToggle<Toggle = Toggle>> From<Field<R, T, <R as RegisterValue>::Int>> for Fields<R, Toggle>
Source§impl<R: RegisterValue, T> MayToggle for Fields<R, T>
impl<R: RegisterValue, T> MayToggle for Fields<R, T>
impl<R: RegisterValue, T> Copy for Fields<R, T>
Auto Trait Implementations§
impl<R, T> Freeze for Fields<R, T>
impl<R, T> RefUnwindSafe for Fields<R, T>
impl<R, T> Send for Fields<R, T>
impl<R, T> Sync for Fields<R, T>
impl<R, T> Unpin for Fields<R, T>
impl<R, T> UnwindSafe for Fields<R, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more