pub struct Reg<REG: RegisterSpec> { /* private fields */ }Expand description
This structure provides volatile access to registers.
Implementations§
Source§impl<REG: Readable + Writable> Reg<REG>where
    REG::Ux: AtomicOperations,
 
impl<REG: Readable + Writable> Reg<REG>where
    REG::Ux: AtomicOperations,
Sourcepub unsafe fn set_bits<F>(&self, f: F)
 
pub unsafe fn set_bits<F>(&self, f: F)
Set high every bit in the register that was set in the write proxy. Leave other bits untouched. The write is done in a single atomic instruction.
§Safety
The resultant bit pattern may not be valid for the register.
Sourcepub unsafe fn clear_bits<F>(&self, f: F)
 
pub unsafe fn clear_bits<F>(&self, f: F)
Clear every bit in the register that was cleared in the write proxy. Leave other bits untouched. The write is done in a single atomic instruction.
§Safety
The resultant bit pattern may not be valid for the register.
Sourcepub unsafe fn toggle_bits<F>(&self, f: F)
 
pub unsafe fn toggle_bits<F>(&self, f: F)
Toggle every bit in the register that was set in the write proxy. Leave other bits untouched. The write is done in a single atomic instruction.
§Safety
The resultant bit pattern may not be valid for the register.
Source§impl<REG: RegisterSpec> Reg<REG>
 
impl<REG: RegisterSpec> Reg<REG>
Source§impl<REG: Readable> Reg<REG>
 
impl<REG: Readable> Reg<REG>
Sourcepub fn read(&self) -> R<REG>
 
pub fn read(&self) -> R<REG>
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();Source§impl<REG: Resettable + Writable> Reg<REG>
 
impl<REG: Resettable + Writable> Reg<REG>
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) -> REG::Ux
 
pub fn write<F>(&self, f: F) -> REG::Ux
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)
);or an alternative way of saying the same:
periph.reg.write(|w| {
    w.field1().bits(newfield1bits);
    w.field2().set_bit();
    w.field3().variant(VARIANT)
});In the latter case, other fields will be set to their reset value.
Sourcepub fn from_write<F, T>(&self, f: F) -> T
 
pub fn from_write<F, T>(&self, f: F) -> T
Writes bits to a Writable register and produce a value.
You can write raw bits into a register:
periph.reg.write_and(|w| unsafe { w.bits(rawbits); });or write only the fields you need:
periph.reg.write_and(|w| {
    w.field1().bits(newfield1bits)
        .field2().set_bit()
        .field3().variant(VARIANT);
});or an alternative way of saying the same:
periph.reg.write_and(|w| {
    w.field1().bits(newfield1bits);
    w.field2().set_bit();
    w.field3().variant(VARIANT);
});In the latter case, other fields will be set to their reset value.
Values can be returned from the closure:
let state = periph.reg.write_and(|w| State::set(w.field1()));Source§impl<REG: Writable> Reg<REG>
 
impl<REG: Writable> Reg<REG>
Sourcepub unsafe fn write_with_zero<F>(&self, f: F) -> REG::Ux
 
pub unsafe fn write_with_zero<F>(&self, f: F) -> REG::Ux
Writes 0 to a Writable register.
Similar to write, but unused bits will contain 0.
§Safety
Unsafe to use with registers which don’t allow to write 0.
Sourcepub unsafe fn from_write_with_zero<F, T>(&self, f: F) -> T
 
pub unsafe fn from_write_with_zero<F, T>(&self, f: F) -> T
Writes 0 to a Writable register and produces a value.
Similar to write, but unused bits will contain 0.
§Safety
Unsafe to use with registers which don’t allow to write 0.
Source§impl<REG: Readable + Writable> Reg<REG>
 
impl<REG: Readable + Writable> Reg<REG>
Sourcepub fn modify<F>(&self, f: F) -> REG::Ux
 
pub fn modify<F>(&self, f: F) -> REG::Ux
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)
);or an alternative way of saying the same:
periph.reg.modify(|_, w| {
    w.field1().bits(newfield1bits);
    w.field2().set_bit();
    w.field3().variant(VARIANT)
});Other fields will have the value they had before the call to modify.
Sourcepub fn from_modify<F, T>(&self, f: F) -> T
 
pub fn from_modify<F, T>(&self, f: F) -> T
Modifies the contents of the register by reading and then writing it and produces a value.
E.g. to do a read-modify-write sequence to change parts of a register:
let bits = periph.reg.modify(|r, w| {
    let new_bits = r.bits() | 3;
    unsafe {
        w.bits(new_bits);
    }
    new_bits
});or
periph.reg.modify(|_, w| {
    w.field1().bits(newfield1bits)
        .field2().set_bit()
        .field3().variant(VARIANT);
});or an alternative way of saying the same:
periph.reg.modify(|_, w| {
    w.field1().bits(newfield1bits);
    w.field2().set_bit();
    w.field3().variant(VARIANT);
});Other fields will have the value they had before the call to modify.