pub struct Reg<'io, R: Register, IO: RegisterIO = PtrIO> { /* private fields */ }Expand description
Register abstraction used to read, write, and modify register values.
This is generic over both the Register to access and the RegisterIO type
used to access the register.
The Register trait has associated types defining the register width,
access controls, and endianness which are used to customize the read/write
implementation for each register.
RegisterIO defaults to regular volatile pointer
I/O and is only needed for advanced use cases like tunneled registers.
Implementations§
Source§impl<'io, R: Register, IO: RegisterIO> Reg<'io, R, IO>
impl<'io, R: Register, IO: RegisterIO> Reg<'io, R, IO>
Source§impl<R: Register, IO: RegisterIO> Reg<'_, R, IO>
impl<R: Register, IO: RegisterIO> Reg<'_, R, IO>
Sourcepub fn try_read(&self) -> Result<R, IO::Error>
pub fn try_read(&self) -> Result<R, IO::Error>
Try to 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().try_read().unwrap();
let field1_val = reg1_val.field1();
let field2_val = reg1_val.field2();Source§impl<R: Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
impl<R: Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
Sourcepub fn read(&self) -> R
pub fn read(&self) -> R
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<R: Register, IO: RegisterIO> Reg<'_, R, IO>
impl<R: Register, IO: RegisterIO> Reg<'_, R, IO>
Sourcepub fn try_write_value(&self, val: R) -> Result<(), IO::Error>
pub fn try_write_value(&self, val: R) -> Result<(), IO::Error>
Try to write a register value.
Typically one would use Reg::try_write or Reg::try_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].try_read().unwrap();
registers.regfile().reg_array()[1].try_write_value(reg0).unwrap();Source§impl<R: Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
impl<R: Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
Sourcepub fn write_value(&self, val: R)
pub fn write_value(&self, val: R)
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<R: Default + Register, IO: RegisterIO> Reg<'_, R, IO>
impl<R: Default + Register, IO: RegisterIO> Reg<'_, R, IO>
Sourcepub fn try_write<T>(&self, f: impl FnOnce(&mut R) -> T) -> Result<T, IO::Error>
pub fn try_write<T>(&self, f: impl FnOnce(&mut R) -> T) -> Result<T, IO::Error>
Try to 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().try_write(|r| {
// r contains the default (reset) value of the register
r.set_field1(0x1);
r.set_field2(0x0);
}).unwrap();Source§impl<R: Default + Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
impl<R: Default + Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
Sourcepub fn write<T>(&self, f: impl FnOnce(&mut R) -> T) -> T
pub fn write<T>(&self, f: impl FnOnce(&mut R) -> T) -> T
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<R: Register, IO: RegisterIO> Reg<'_, R, IO>
impl<R: Register, IO: RegisterIO> Reg<'_, R, IO>
Sourcepub fn try_modify<T>(&self, f: impl FnOnce(&mut R) -> T) -> Result<T, IO::Error>
pub fn try_modify<T>(&self, f: impl FnOnce(&mut R) -> T) -> Result<T, IO::Error>
Try to 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().try_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 .try_modify() method
orig_r
}).unwrap();Source§impl<R: Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
impl<R: Register, IO: RegisterIO<Error = Infallible>> Reg<'_, R, IO>
Sourcepub fn modify<T>(&self, f: impl FnOnce(&mut R) -> T) -> T
pub fn modify<T>(&self, f: impl FnOnce(&mut R) -> T) -> T
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
});