i2cdev::linux

Struct LinuxI2CDevice

Source
pub struct LinuxI2CDevice { /* private fields */ }
Expand description

Concrete linux I2C device

Implementations§

Source§

impl LinuxI2CDevice

Source

pub fn new<P: AsRef<Path>>( path: P, slave_address: u16, ) -> Result<LinuxI2CDevice, LinuxI2CError>

Create a new I2CDevice for the specified path

Source

pub unsafe fn force_new<P: AsRef<Path>>( path: P, slave_address: u16, ) -> Result<LinuxI2CDevice, LinuxI2CError>

Create a new I2CDevice for the specified path, without checking if the device is bound to a driver

§Safety

Using this can seriously confuse the original driver, and may cause all future communication to perform the wrong operations and/or return wrong results.

Source

pub fn set_slave_address( &mut self, slave_address: u16, ) -> Result<(), LinuxI2CError>

Set the slave address for this device

Typically the address is expected to be 7-bits but 10-bit addresses may be supported by the kernel driver in some cases. Little validation is done in Rust as the kernel is good at making sure things are valid.

Note that if you have created a device using I2Device::new(...) it is not necesasry to call this method (it is done internally). Calling this method is only necessary if you need to change the slave device and you do not want to create a new device.

Source

pub fn set_smbus_pec(&mut self, enable: bool) -> Result<(), LinuxI2CError>

Enable/Disable PEC support for this device

Used only for SMBus transactions. This request only has an effect if the the adapter has I2C_FUNC_SMBUS_PEC; it is still safe if not, it just doesn’t have any effect.

Trait Implementations§

Source§

impl AsRawFd for LinuxI2CDevice

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl I2CDevice for LinuxI2CDevice

Source§

fn read(&mut self, data: &mut [u8]) -> Result<(), LinuxI2CError>

Read data from the device to fill the provided slice

Source§

fn write(&mut self, data: &[u8]) -> Result<(), LinuxI2CError>

Write the provided buffer to the device

Source§

fn smbus_write_quick(&mut self, bit: bool) -> Result<(), LinuxI2CError>

This sends a single bit to the device, at the place of the Rd/Wr bit

Source§

fn smbus_read_byte(&mut self) -> Result<u8, LinuxI2CError>

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.

Source§

fn smbus_write_byte(&mut self, value: u8) -> Result<(), LinuxI2CError>

Write a single byte to a sdevice, without specifying a device register

This is the opposite operation as smbus_read_byte. As with read_byte, no register is specified.

Source§

fn smbus_read_byte_data(&mut self, register: u8) -> Result<u8, LinuxI2CError>

Read a single byte from a device, from a designated register

The register is specified through the Comm byte.

Source§

fn smbus_write_byte_data( &mut self, register: u8, value: u8, ) -> Result<(), LinuxI2CError>

Write a single byte to a specific register on a device

The register is specified through the Comm byte.

Source§

fn smbus_read_word_data(&mut self, register: u8) -> Result<u16, LinuxI2CError>

Read 2 bytes form a given register on a device

Source§

fn smbus_write_word_data( &mut self, register: u8, value: u16, ) -> Result<(), LinuxI2CError>

Write 2 bytes to a given register on a device

Source§

fn smbus_process_word( &mut self, register: u8, value: u16, ) -> Result<u16, LinuxI2CError>

Select a register, send 16 bits of data to it, and read 16 bits of data

Source§

fn smbus_read_block_data( &mut self, register: u8, ) -> Result<Vec<u8>, LinuxI2CError>

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.

Source§

fn smbus_read_i2c_block_data( &mut self, register: u8, len: u8, ) -> Result<Vec<u8>, LinuxI2CError>

Read a block of up to 32 bytes from a device via i2c_smbus_i2c_read_block_data

Source§

fn smbus_write_block_data( &mut self, register: u8, values: &[u8], ) -> Result<(), LinuxI2CError>

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.

Source§

fn smbus_write_i2c_block_data( &mut self, register: u8, values: &[u8], ) -> Result<(), LinuxI2CError>

Write a block of up to 32 bytes from a device via i2c_smbus_i2c_write_block_data

Source§

fn smbus_process_block( &mut self, register: u8, values: &[u8], ) -> Result<Vec<u8>, LinuxI2CError>

Select a register, send 1 to 31 bytes of data to it, and reads 1 to 31 bytes of data from it.

Source§

type Error = LinuxI2CError

Error type
Source§

impl<'a> I2CTransfer<'a> for LinuxI2CDevice

Source§

fn transfer( &mut self, messages: &'a mut [Self::Message], ) -> Result<u32, LinuxI2CError>

Issue the provided sequence of I2C transactions

Source§

type Error = LinuxI2CError

I2C transfer error type
Source§

type Message = i2c_msg

I2C transfer message type

Auto Trait Implementations§

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.