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>
impl<I, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> BitStruct<I, ADDRESS, BITS, SHIFT>
Sourcepub fn new() -> Result<BitStruct<I, ADDRESS, BITS, SHIFT>, BitByteStructError<I::Error>>
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.
Sourcepub fn read(
&self,
bus: &mut dyn Interface<Error = I::Error>,
) -> Result<u8, BitByteStructError<I::Error>>
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.
Sourcepub fn write(
&self,
bus: &mut dyn Interface<Error = I::Error>,
new_value: u8,
) -> Result<(), BitByteStructError<I::Error>>
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>
impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> Sync for BitStruct<Interface, ADDRESS, BITS, SHIFT>
impl<Interface, const ADDRESS: u8, const BITS: u8, const SHIFT: u8> Unpin for BitStruct<Interface, ADDRESS, BITS, SHIFT>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more