Struct Reg

Source
pub struct Reg<R, P> { /* private fields */ }
Expand description

Base struct for all registers

This is the struct that allows to read and write registers. It is created as part of the peripheral struct generated by the [periph!] macro. The type parameters indicate the actual register and the peripheral it belongs to.

Implementations§

Source§

impl<R: Register, P: Peripheral> Reg<R, P>

Source

pub fn ptr(&self) -> *const R::Int

Get a raw pointer to the register

Source

pub fn ptr_mut(&mut self) -> *mut R::Int

Get a mutable raw pointer to the register

Source

pub fn into_dyn(self) -> &'static mut DynReg<R>

Erase peripheral information

This allows to choose at runtime which instance of a peripheral to use.

Source§

impl<R: ReadRegister, P: Peripheral> Reg<R, P>

Source

pub fn read(&self) -> Value<R::Value>

Read the current value of this register

This returns a Value, which can be used to read fields or modified and written back.

Source

pub fn field<T>(&self, field: Field<R::Value, T, R::Int>) -> T
where R::Int: TryInto<T>, <R::Int as TryInto<T>>::Error: Debug,

Read the given field

Same as register.read().field(fields). See Value::field for more details.

Source

pub fn fields<F: Into<Fields<R::Value>> + MayToggle>( &self, fields: F, ) -> FieldValues<R::Value, F::Toggle>

Read the given fields

Same as register.read() & fields. See Value for more details.

Source

pub fn test<B: Into<FieldValues<R::Value>>>(&self, bits: B) -> bool

Test the value of the given fields

Same as register.read().test(bits). See Value::test for more details.

Source§

impl<R: WriteRegister, P: Peripheral> Reg<R, P>

Source

pub fn write(&mut self, value: Value<R::Value>)

Write a value to this register

This takes a Value, which can be read from a register or created with Default.

Source

pub fn reset(&mut self)

Reset this register

This set the register to the value it has right after a reset or a boot.

Source§

impl<R: ReadRegister + WriteRegister, P: Peripheral> Reg<R, P>

Source

pub fn modify<B: Into<FieldValues<R::Value>>>(&mut self, bits: B)

Modify the given fields

This takes any field defined for this register by the [periph!] macro. These fields can also be combined with the | operator.

Source

pub fn toggle<F: Into<Fields<R::Value, Toggle>>>(&mut self, fields: F)

Toggle the given fields

This takes a toggleable field defined for this register by the [periph!] macro. These fields can also be combined with the | operator.

Trait Implementations§

Source§

impl<R: Register, P: Peripheral> Debug for Reg<R, P>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, P> Freeze for Reg<R, P>

§

impl<R, P> RefUnwindSafe for Reg<R, P>

§

impl<R, P> Send for Reg<R, P>
where P: Send, R: Send,

§

impl<R, P> Sync for Reg<R, P>
where P: Sync, R: Sync,

§

impl<R, P> Unpin for Reg<R, P>
where P: Unpin, R: Unpin,

§

impl<R, P> UnwindSafe for Reg<R, P>
where P: UnwindSafe, R: UnwindSafe,

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> 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.