Reg

Struct Reg 

Source
pub struct Reg<T, A: Access> { /* private fields */ }

Implementations§

Source§

impl<T, A> Reg<T, A>
where T: RegSpec, A: Access,

Source

pub const fn ptr(&self) -> *mut T::DataType

Source

pub fn addr(&self) -> usize

Returns the address of the register.

Source§

impl<T, A> Reg<T, A>
where T: RegSpec, A: Read,

Source

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,

Source

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

Source

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>
where T: RegSpec, A: Write, RegValueT<T>: Default,

Source

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>
where T: RegSpec, A: Read + Write,

Source

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()));

Trait Implementations§

Source§

impl<T: Clone, A: Clone + Access> Clone for Reg<T, A>

Source§

fn clone(&self) -> Reg<T, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: PartialEq, A: PartialEq + Access> PartialEq for Reg<T, A>

Source§

fn eq(&self, other: &Reg<T, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy, A: Copy + Access> Copy for Reg<T, A>

Source§

impl<T: Eq, A: Eq + Access> Eq for Reg<T, A>

Source§

impl<T, A: Access> Send for Reg<T, A>

Source§

impl<T, A: Access> StructuralPartialEq for Reg<T, A>

Source§

impl<T, A: Access> Sync for Reg<T, A>

Auto Trait Implementations§

§

impl<T, A> Freeze for Reg<T, A>

§

impl<T, A> RefUnwindSafe for Reg<T, A>

§

impl<T, A> Unpin for Reg<T, A>

§

impl<T, A> UnwindSafe for Reg<T, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.