[−][src]Struct i2c_reg::I2cInterface
I2C interface
Example
use embedded_hal::blocking::i2c; use i2c_reg::*; use i2c_reg_derive::*; #[derive(Register, I2cReadRegister, I2cWriteRegister)] #[address = 0b1110] #[size = 4] struct ExampleRegister; type Raw = <ExampleRegister as Register>::Raw; #[derive(Debug, PartialEq)] struct Value(u32); impl Into<Raw> for Value { fn into(self) -> Raw { [ (self.0 >> 24) as u8, (self.0 >> 16) as u8, (self.0 >> 8) as u8, self.0 as u8, ] } } impl From<Raw> for Value { fn from(raw: Raw) -> Self { Value( ((raw[0] as u32) << 24) + ((raw[1] as u32) << 16) + ((raw[2] as u32) << 8) + raw[3] as u32, ) } } let mut interface = I2cInterface { i2c, address: 0b0110 }; interface.write_register(ExampleRegister, Value(0x89abcdef)).unwrap(); let value: Value = interface.read_register(ExampleRegister).unwrap(); assert_eq!(Value(0x89abcdef), value);
Fields
i2c: I2C
Slave device I2C
address: u8
Slave device address
Methods
impl<I2C> I2cInterface<I2C>
[src]
pub fn read_register<Raw, Value, Err>(
&mut self,
register: impl I2cReadRegister<Raw>
) -> Result<Value, Err> where
I2C: WriteRead<Error = Err>,
Raw: Into<Value>,
[src]
&mut self,
register: impl I2cReadRegister<Raw>
) -> Result<Value, Err> where
I2C: WriteRead<Error = Err>,
Raw: Into<Value>,
Read bytes from register and map output to Value
pub fn write_register<Raw, Err>(
&mut self,
register: impl I2cWriteRegister<Raw>,
value: impl Into<Raw>
) -> Result<(), Err> where
I2C: Write<Error = Err>,
[src]
&mut self,
register: impl I2cWriteRegister<Raw>,
value: impl Into<Raw>
) -> Result<(), Err> where
I2C: Write<Error = Err>,
Map value
to bytes and write to register
Trait Implementations
Auto Trait Implementations
impl<I2C> Send for I2cInterface<I2C> where
I2C: Send,
I2C: Send,
impl<I2C> Sync for I2cInterface<I2C> where
I2C: Sync,
I2C: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,