Struct I2c

Source
pub struct I2c<Device: MpsseCmdExecutor> { /* private fields */ }
Expand description

FTDI I2C interface.

This is created by calling FtHal::i2c.

Implementations§

Source§

impl<Device, E> I2c<Device>
where Device: MpsseCmdExecutor<Error = E>, E: Error, Error<E>: From<E>,

Source

pub fn set_stop_start_len(&mut self, start_stop_cmds: u8)

Set the length of start and stop conditions.

This is an advanced feature that most people will not need to touch. I2C start and stop conditions are generated with a number of MPSSE commands. This sets the number of MPSSE command generated for each stop and start condition. An increase in the number of MPSSE commands roughtly correlates to an increase in the duration.

§Example
use ftdi_embedded_hal as hal;

let device = libftd2xx::Ft2232h::with_description("Dual RS232-HS A")?;
let hal = hal::FtHal::init_freq(device, 3_000_000)?;
let mut i2c = hal.i2c()?;
i2c.set_stop_start_len(10);
Source

pub fn set_fast(&mut self, fast: bool)

Enable faster I2C transactions by sending commands in a single write.

This is disabled by default, and currently has no effect when using version 1 of the embedded-hal traits.

Normally the I2C methods will send commands with a delay after each slave ACK to read from the USB device. Enabling this will send I2C commands without a delay, but slave ACKs will only be checked at the end of each call to read, write, or write_read.

Additionally this changes the type of errors that can occur:

  • enabled: NAK errors will be reported as NoAcknowledgeSource::Unknown.
  • disabled: NAK errors will be reported as NoAcknowledgeSource::Address or NoAcknowledgeSource::Data.
§Example
use ftdi_embedded_hal as hal;

let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
    .interface(ftdi::Interface::A)
    .open()?;

let hal = hal::FtHal::init_freq(device, 3_000_000)?;
let mut i2c = hal.i2c()?;
i2c.set_fast(true);

Trait Implementations§

Source§

impl<Device: Debug + MpsseCmdExecutor> Debug for I2c<Device>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Device, E> ErrorType for I2c<Device>
where Device: MpsseCmdExecutor<Error = E>, E: Error, Error<E>: From<E>,

Source§

type Error = Error<E>

Error type
Source§

impl<Device, E> I2c for I2c<Device>
where Device: MpsseCmdExecutor<Error = E>, E: Error, Error<E>: From<E>,

Source§

fn transaction( &mut self, address: SevenBitAddress, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus. Read more
Source§

fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill read. Read more
Source§

fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address. Read more
Source§

fn write_read( &mut self, address: A, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill read in a single transaction. Read more
Source§

impl<Device, E> Read for I2c<Device>
where Device: MpsseCmdExecutor<Error = E>, E: Error, Error<E>: From<E>,

Source§

type Error = Error<E>

Error type
Source§

fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error<E>>

Reads enough bytes from slave with address to fill buffer Read more
Source§

impl<Device, E> Write for I2c<Device>
where Device: MpsseCmdExecutor<Error = E>, E: Error, Error<E>: From<E>,

Source§

type Error = Error<E>

Error type
Source§

fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error<E>>

Writes bytes to slave with address address Read more
Source§

impl<Device, E> WriteRead for I2c<Device>
where Device: MpsseCmdExecutor<Error = E>, E: Error, Error<E>: From<E>,

Source§

type Error = Error<E>

Error type
Source§

fn write_read( &mut self, address: u8, bytes: &[u8], buffer: &mut [u8], ) -> Result<(), Error<E>>

Writes bytes to slave with address address and then reads enough bytes to fill buffer in a single transaction Read more

Auto Trait Implementations§

§

impl<Device> Freeze for I2c<Device>

§

impl<Device> RefUnwindSafe for I2c<Device>

§

impl<Device> Send for I2c<Device>
where Device: Send,

§

impl<Device> Sync for I2c<Device>
where Device: Send,

§

impl<Device> Unpin for I2c<Device>

§

impl<Device> UnwindSafe for I2c<Device>

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.