pub trait I2CDevice {
type Error: Error;
Show 15 methods
// Required methods
fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error>;
fn write(&mut self, data: &[u8]) -> Result<(), Self::Error>;
fn smbus_write_quick(&mut self, bit: bool) -> Result<(), Self::Error>;
fn smbus_read_block_data(
&mut self,
register: u8,
) -> Result<Vec<u8>, Self::Error>;
fn smbus_read_i2c_block_data(
&mut self,
register: u8,
len: u8,
) -> Result<Vec<u8>, Self::Error>;
fn smbus_write_block_data(
&mut self,
register: u8,
values: &[u8],
) -> Result<(), Self::Error>;
fn smbus_write_i2c_block_data(
&mut self,
register: u8,
values: &[u8],
) -> Result<(), Self::Error>;
fn smbus_process_block(
&mut self,
register: u8,
values: &[u8],
) -> Result<Vec<u8>, Self::Error>;
// Provided methods
fn smbus_read_byte(&mut self) -> Result<u8, Self::Error> { ... }
fn smbus_write_byte(&mut self, value: u8) -> Result<(), Self::Error> { ... }
fn smbus_read_byte_data(&mut self, register: u8) -> Result<u8, Self::Error> { ... }
fn smbus_write_byte_data(
&mut self,
register: u8,
value: u8,
) -> Result<(), Self::Error> { ... }
fn smbus_read_word_data(&mut self, register: u8) -> Result<u16, Self::Error> { ... }
fn smbus_write_word_data(
&mut self,
register: u8,
value: u16,
) -> Result<(), Self::Error> { ... }
fn smbus_process_word(
&mut self,
register: u8,
value: u16,
) -> Result<u16, Self::Error> { ... }
}
Expand description
Interface to an I2C Slave Device from an I2C Master
Typical implementations will store state with references to the bus in use and the address of the slave device. The trait is based on the Linux i2cdev interface.
Required Associated Types§
Required Methods§
Sourcefn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error>
fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error>
Read data from the device to fill the provided slice
Sourcefn write(&mut self, data: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, data: &[u8]) -> Result<(), Self::Error>
Write the provided buffer to the device
Sourcefn smbus_write_quick(&mut self, bit: bool) -> Result<(), Self::Error>
fn smbus_write_quick(&mut self, bit: bool) -> Result<(), Self::Error>
This sends a single bit to the device, at the place of the Rd/Wr bit
Sourcefn smbus_read_block_data(
&mut self,
register: u8,
) -> Result<Vec<u8>, Self::Error>
fn smbus_read_block_data( &mut self, register: u8, ) -> Result<Vec<u8>, Self::Error>
Read a block of up to 32 bytes from a device
The actual number of bytes available to read is returned in the count byte. This code returns a correctly sized vector containing the count bytes read from the device.
Sourcefn smbus_read_i2c_block_data(
&mut self,
register: u8,
len: u8,
) -> Result<Vec<u8>, Self::Error>
fn smbus_read_i2c_block_data( &mut self, register: u8, len: u8, ) -> Result<Vec<u8>, Self::Error>
Read a block of up to 32 bytes from a device
Uses read_i2c_block_data instead read_block_data.
Sourcefn smbus_write_block_data(
&mut self,
register: u8,
values: &[u8],
) -> Result<(), Self::Error>
fn smbus_write_block_data( &mut self, register: u8, values: &[u8], ) -> Result<(), Self::Error>
Write a block of up to 32 bytes to a device
The opposite of the Block Read command, this writes up to 32 bytes to a device, to a designated register that is specified through the Comm byte. The amount of data is specified in the Count byte.
Provided Methods§
Sourcefn smbus_read_byte(&mut self) -> Result<u8, Self::Error>
fn smbus_read_byte(&mut self) -> Result<u8, Self::Error>
Read a single byte from a device, without specifying a device register
Some devices are so simple that this interface is enough; for others, it is a shorthand if you want to read the same register as in the previous SMBus command.
Sourcefn smbus_write_byte(&mut self, value: u8) -> Result<(), Self::Error>
fn smbus_write_byte(&mut self, value: u8) -> Result<(), Self::Error>
Write a single byte to a device, without specifying a device register
This is the opposite operation as smbus_read_byte. As with read_byte, no register is specified.
Sourcefn smbus_read_byte_data(&mut self, register: u8) -> Result<u8, Self::Error>
fn smbus_read_byte_data(&mut self, register: u8) -> Result<u8, Self::Error>
Read a single byte from a device, from a designated register
The register is specified through the Comm byte.
Sourcefn smbus_write_byte_data(
&mut self,
register: u8,
value: u8,
) -> Result<(), Self::Error>
fn smbus_write_byte_data( &mut self, register: u8, value: u8, ) -> Result<(), Self::Error>
Write a single byte to a specific register on a device
The register is specified through the Comm byte.
Sourcefn smbus_read_word_data(&mut self, register: u8) -> Result<u16, Self::Error>
fn smbus_read_word_data(&mut self, register: u8) -> Result<u16, Self::Error>
Read 2 bytes from a given register on a device (lsb first)