pub struct Reg<T, A: Access> { /* private fields */ }Implementations§
Source§impl<T, A> Reg<T, A>where
T: RegSpec,
A: Read,
impl<T, A> Reg<T, A>where
T: RegSpec,
A: Read,
Sourcepub unsafe fn read(&self) -> RegValueT<T>
pub unsafe fn read(&self) -> RegValueT<T>
Read register and return a register value
§Safety
Read operation could cause undefined behavior for some peripheral. Developer shall read device user manual. Register is Send and Sync to allow complete freedom. Developer is responsible of proper use in interrupt and thread.
§Example
// example with generic names
let reg = unsafe { TIMER.bitfield_reg().read() };
if reg.boolr().get() { /* ... */ }Source§impl<T, A> Reg<T, A>where
T: RegSpec,
A: Write,
impl<T, A> Reg<T, A>where
T: RegSpec,
A: Write,
Sourcepub unsafe fn write(&self, reg_value: RegValueT<T>)
pub unsafe fn write(&self, reg_value: RegValueT<T>)
Write register value back to register
§Arguments
reg_value- A string slice that holds the name of the person
§Safety
Write operation could cause undefined behavior for some peripheral. Developers shall read the device user manual. Register is Send and Sync to allow complete freedom. Developers are responsible of proper use in interrupt and thread.
§Example
// example with generic names
// write with a previously read value
let reg = unsafe { TIMER.bitfield_reg().read() };
// or start with a known value
let reg = timer::BitfieldReg::new(0).bitfieldw().set(0x55);
// or start with the register default
let reg = timer::BitfieldReg::default();
let reg = reg.bitfieldrw().set(0x77);
// no change has taken place to the register due to `set` calls - do that now by writing back the result
unsafe { TIMER.bitfield_reg().write(reg) }See also: Reg<T, A>::init which provides the default value to a closure
Sourcepub unsafe fn write_raw(&self, value: T::DataType)
pub unsafe fn write_raw(&self, value: T::DataType)
Write an arbitrary integer to register
Use this function when e.g. loading data to be written from a config-page.
For normal use prefer either Reg<T, A>::write if the value was read before, or Reg<T, A>::init,
both of which provide some restrictions available register fields, enums, etc.
§Arguments
value- The unchecked value to be written to the register
§Safety
Write operation could cause undefined behavior for some peripheral. Developers shall read the device user manual. Register is Send and Sync to allow complete freedom. Developers are responsible of proper use in interrupt and thread.
§Example
// example with generic names
unsafe { TIMER.bitfield_reg().write_raw(0xdead) }See also Reg<T, A>::init and Reg<T, A>::write both of which are the safe, preferred functions.
Source§impl<T, A> Reg<T, A>
impl<T, A> Reg<T, A>
Sourcepub unsafe fn init(&self, f: impl FnOnce(RegValueT<T>) -> RegValueT<T>)
pub unsafe fn init(&self, f: impl FnOnce(RegValueT<T>) -> RegValueT<T>)
Write register with register value built from default register value
§Arguments
f- Closure that receive as input a register value initialized with register value at Power On Reset.
§Safety
Write operation could cause undefined behavior for some peripheral. Developer shall read device user manual. Register is Send and Sync to allow complete freedom. Developer is responsible of proper use in interrupt and thread.
§Example
// example with generic names
TIMER
.bitfield_reg()
.init(|r| r.bitfieldw().set(0b1010).boolw().set(true));Write value computed by closure that receive as input the reset value of register
Source§impl<T, A> Reg<T, A>
impl<T, A> Reg<T, A>
Sourcepub unsafe fn modify(&self, f: impl FnOnce(RegValueT<T>) -> RegValueT<T>)
pub unsafe fn modify(&self, f: impl FnOnce(RegValueT<T>) -> RegValueT<T>)
Read/modify/write register
§Arguments
f- Closure that receive as input a register value read from register. The result of the closure is written back to the register.
§Safety
Write operation could cause undefined behavior for some peripheral. Developer shall read device user manual. Register is Send and Sync to allow complete freedom. Developer is responsible of proper use in interrupt and thread.
§Example
// example with generic names
TIMER
.bitfield_reg()
.modify(|r| r.boolrw().set(!r.boolrw().get()));