pub struct Reg<T: Register, A: Access> { /* private fields */ }Expand description
Register abstraction used to read, write, and modify register values
Implementations§
Source§impl<T: Register, A: Read> Reg<T, A>
impl<T: Register, A: Read> Reg<T, A>
Sourcepub fn read(&self) -> T
pub fn read(&self) -> T
Read a register value.
If the register is to be modified (i.e., a read-modify-write), use the
Reg::modify method instead.
§Example
let reg1_val = registers.regfile().register1().read();
let field1_val = reg1_val.field1();
let field2_val = reg1_val.field2();Source§impl<T: Register, A: Write> Reg<T, A>
impl<T: Register, A: Write> Reg<T, A>
Sourcepub fn write_value(&self, val: T)
pub fn write_value(&self, val: T)
Write a register value.
Typically one would use Reg::write or Reg::modify to update a
register’s contents, but this method has a few different use cases such
as updating a register with a stored value, or updating one register with
the contents of another.
§Example
let reg0 = registers.regfile().reg_array()[0].read();
registers.regfile().reg_array()[1].write_value(reg0);Source§impl<T: Default + Register, A: Write> Reg<T, A>
impl<T: Default + Register, A: Write> Reg<T, A>
Sourcepub fn write<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
pub fn write<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
Write a register.
This method takes a closure. The input to the closure is a mutable reference to the default value of the register. It can be updated in the closure. The updated value is then written to the hardware register.
§Example
registers.regfile().register1().write(|r| {
// r contains the default (reset) value of the register
r.set_field1(0x1);
r.set_field2(0x0);
});Source§impl<T: Register, A: Read + Write> Reg<T, A>
impl<T: Register, A: Read + Write> Reg<T, A>
Sourcepub fn modify<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
pub fn modify<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
Modify a register.
This method takes a closure. The input to the closure is a mutable reference to the current value of the register. It can be updated in the closure. The updated value is then written back to the hardware register.
§Example
let orig_r = registers.regfile().register1().modify(|r| {
// r contains the current value of the register
orig_r = r.clone()
r.set_field1(r.field1());
r.set_field2(0x0);
// whatever value the closure returns is returned by the .modify() method
orig_r
});