BitStruct

Struct BitStruct 

Source
pub struct BitStruct<Interface: ?Sized, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> { /* private fields */ }
Expand description

Struct for representing registers of 0-8bits

Implementations§

Source§

impl<I, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> BitStruct<I, ADDRESS, BITS, SHIFT>
where I: Interface + ?Sized,

Source

pub fn new() -> Result<BitStruct<I, ADDRESS, BITS, SHIFT>, BitByteStructError<I::Error>>

Create a new BitStruct

Arguments:

  • register_address: u8 - The address of the register that contains the bits.
  • bits: u8 - The number of bits this struct can read and write.
  • shift: u8 - The number of bits from the start of the byte.
Source

pub fn read( &self, bus: &mut dyn Interface<Error = I::Error>, ) -> Result<u8, BitByteStructError<I::Error>>

Read the value from the peripheral

  • bus: &mut dyn Interface<Error = I::Error> - The interface to the bus over which to communicate with the peripheral.

This will read the register that contains the information and then mask and shit the value for you.

Source

pub fn write( &self, bus: &mut dyn Interface<Error = I::Error>, new_value: u8, ) -> Result<(), BitByteStructError<I::Error>>

Write the value to the peripheral

  • bus: &mut dyn Interface<Error = I::Error> - The interface to the bus over which to communicate with the peripheral.
  • new_value: u8 - The new value to send to the peripheral

This will read the register that contains the information and then mask and shit the new value and then write the full register back without effecting the other bits not covered by this structures bits.

If new_value is larger than the number of bits this structure covers then the function will return a BitByteStructError::InputToBig without interacting with the peripheral.

Auto Trait Implementations§

§

impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> Freeze for BitStruct<Interface, ADDRESS, BITS, SHIFT>
where Interface: ?Sized,

§

impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> RefUnwindSafe for BitStruct<Interface, ADDRESS, BITS, SHIFT>
where Interface: RefUnwindSafe + ?Sized,

§

impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> Send for BitStruct<Interface, ADDRESS, BITS, SHIFT>
where Interface: Send + ?Sized,

§

impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> Sync for BitStruct<Interface, ADDRESS, BITS, SHIFT>
where Interface: Sync + ?Sized,

§

impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> Unpin for BitStruct<Interface, ADDRESS, BITS, SHIFT>
where Interface: Unpin + ?Sized,

§

impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> UnwindSafe for BitStruct<Interface, ADDRESS, BITS, SHIFT>
where Interface: UnwindSafe + ?Sized,

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.