#[repr(transparent)]pub struct Reg<REG> where
REG: RegisterSpec, { /* private fields */ }
Expand description
This structure provides volatile access to registers.
Implementations
sourceimpl<REG> Reg<REG> where
REG: RegisterSpec,
impl<REG> Reg<REG> where
REG: RegisterSpec,
sourcepub fn as_ptr(&self) -> *mut <REG as RegisterSpec>::Ux
pub fn as_ptr(&self) -> *mut <REG as RegisterSpec>::Ux
Returns the underlying memory address of register.
let reg_ptr = periph.reg.as_ptr();
sourceimpl<REG> Reg<REG> where
REG: Readable,
impl<REG> Reg<REG> where
REG: Readable,
sourcepub fn read(&self) -> <REG as Readable>::Reader
pub fn read(&self) -> <REG as Readable>::Reader
Reads the contents of a Readable
register.
You can read the raw contents of a register by using bits
:
let bits = periph.reg.read().bits();
or get the content of a particular field of a register:
let reader = periph.reg.read();
let bits = reader.field1().bits();
let flag = reader.field2().bit_is_set();
sourceimpl<REG> Reg<REG> where
REG: Resettable + Writable,
impl<REG> Reg<REG> where
REG: Resettable + Writable,
sourcepub fn reset(&self)
pub fn reset(&self)
Writes the reset value to Writable
register.
Resets the register to its initial state.
sourcepub fn write<F>(&self, f: F) where
F: FnOnce(&mut <REG as Writable>::Writer) -> &mut W<REG>,
pub fn write<F>(&self, f: F) where
F: FnOnce(&mut <REG as Writable>::Writer) -> &mut W<REG>,
Writes bits to a Writable
register.
You can write raw bits into a register:
periph.reg.write(|w| unsafe { w.bits(rawbits) });
or write only the fields you need:
periph.reg.write(|w| w
.field1().bits(newfield1bits)
.field2().set_bit()
.field3().variant(VARIANT)
);
In the latter case, other fields will be set to their reset value.
sourceimpl<REG> Reg<REG> where
REG: Readable + Writable,
impl<REG> Reg<REG> where
REG: Readable + Writable,
sourcepub fn modify<F>(&self, f: F) where
F: for<'w> FnOnce(&<REG as Readable>::Reader, &'w mut <REG as Writable>::Writer) -> &'w mut W<REG>,
pub fn modify<F>(&self, f: F) where
F: for<'w> FnOnce(&<REG as Readable>::Reader, &'w mut <REG as Writable>::Writer) -> &'w mut W<REG>,
Modifies the contents of the register by reading and then writing it.
E.g. to do a read-modify-write sequence to change parts of a register:
periph.reg.modify(|r, w| unsafe { w.bits(
r.bits() | 3
) });
or
periph.reg.modify(|_, w| w
.field1().bits(newfield1bits)
.field2().set_bit()
.field3().variant(VARIANT)
);
Other fields will have the value they had before the call to modify
.
Trait Implementations
impl<REG> Send for Reg<REG> where
REG: RegisterSpec,
<REG as RegisterSpec>::Ux: Send,
Auto Trait Implementations
impl<REG> !RefUnwindSafe for Reg<REG>
impl<REG> !Sync for Reg<REG>
impl<REG> Unpin for Reg<REG> where
REG: Unpin,
<REG as RegisterSpec>::Ux: Unpin,
impl<REG> UnwindSafe for Reg<REG> where
REG: UnwindSafe,
<REG as RegisterSpec>::Ux: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcepub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcepub fn checked_cast_from(src: Src) -> Option<Dst>
pub fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
sourcepub fn lossless_try_into(self) -> Option<Dst>
pub fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
sourceimpl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
sourcepub fn lossy_into(self) -> Dst
pub fn lossy_into(self) -> Dst
Performs the conversion.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcepub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcepub fn overflowing_cast_from(src: Src) -> (Dst, bool)
pub fn overflowing_cast_from(src: Src) -> (Dst, bool)
OverflowingCasts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcepub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcepub fn saturating_cast_from(src: Src) -> Dst
pub fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcepub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcepub fn unwrapped_cast_from(src: Src) -> Dst
pub fn unwrapped_cast_from(src: Src) -> Dst
UnwrappedCasts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcepub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcepub fn wrapping_cast_from(src: Src) -> Dst
pub fn wrapping_cast_from(src: Src) -> Dst
WrappingCasts the value.