Struct FtHal

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

FTxxx device.

Implementations§

Source§

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

Source

pub fn init_default(device: Device) -> Result<FtHal<Device>, Error<E>>

Initialize the FTDI MPSSE with sane defaults.

Default values:

  • Reset the FTDI device.
  • 4k USB transfer size.
  • 1s USB read timeout.
  • 1s USB write timeout.
  • 16ms latency timer.
  • 100kHz clock frequency.
§Example
use ftdi_embedded_hal as hal;

let device = libftd2xx::Ft232h::with_description("Single RS232-HS")?;
let hal = hal::FtHal::init_default(device)?;
Source

pub fn init_freq(device: Device, freq: u32) -> Result<FtHal<Device>, Error<E>>

Initialize the FTDI MPSSE with sane defaults and custom frequency

§Example
use ftdi_embedded_hal as hal;

let device = libftd2xx::Ft232h::with_description("Single RS232-HS")?;
let hal = hal::FtHal::init_freq(device, 3_000_000)?;
Source

pub fn init( device: Device, mpsse_settings: &MpsseSettings, ) -> Result<FtHal<Device>, E>

Initialize the FTDI MPSSE with custom values.

Note: The mask field of MpsseSettings is ignored for this function.

Note: The clock frequency will be 2/3 of the specified value when in I2C mode.

§Panics

Panics if the clock_frequency field of MpsseSettings is None.

§Example
use ftdi_embedded_hal as hal;
use ftdi_mpsse::MpsseSettings;
use std::time::Duration;

let mpsse = MpsseSettings {
    reset: false,
    in_transfer_size: 4096,
    read_timeout: Duration::from_secs(5),
    write_timeout: Duration::from_secs(5),
    latency_timer: Duration::from_millis(32),
    mask: 0x00,
    clock_frequency: Some(400_000),
};

let device = libftd2xx::Ft232h::with_description("Single RS232-HS")?;
let hal = hal::FtHal::init(device, &mpsse)?;
Source§

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

Source

pub fn with_device<T, F>(&mut self, f: F) -> T
where F: FnMut(&mut Device) -> T,

Executes the closure with the device.

Useful for accessing EEPROM, or other device-specific functionality.

§Example
use ftdi_embedded_hal as hal;
use hal::libftd2xx::FtdiEeprom;

let device = libftd2xx::Ft2232h::with_description("Dual RS232-HS A")?;
let mut hal = hal::FtHal::init_default(device)?;
let serial_number: String =
    hal.with_device(|d| d.eeprom_read().map(|(_, strings)| strings.serial_number()))?;
Source

pub fn spi(&self) -> Result<Spi<Device>, Error<E>>

Aquire the SPI peripheral for the FT232H.

Pin assignments:

  • AD0 => SCK
  • AD1 => MOSI
  • AD2 => MISO
§Panics

Panics if pin 0, 1, or 2 are already in use.

§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 spi = hal.spi()?;
Source

pub fn spi_device(&self, cs_idx: u8) -> Result<SpiDevice<Device>, Error<E>>

Aquire the SPI peripheral with a chip select pin.

This is specific to embedded-hal version 1.

Pin assignments:

  • AD0 => SCK
  • AD1 => MOSI
  • AD2 => MISO
§Panics

Panics if pin 0, 1, 2 or the CS pin are already in use.

§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 spi = hal.spi_device(3)?;
Source

pub fn i2c(&self) -> Result<I2c<Device>, Error<E>>

Aquire the I2C peripheral for the FT232H.

Pin assignments:

  • AD0 => SCL
  • AD1 => SDA
  • AD2 => SDA

Yes, AD1 and AD2 are both SDA. These pins must be shorted together for I2C operation.

§Panics

Panics if pin 0, 1, or 2 are already in use.

§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 i2c = hal.i2c()?;
Source

pub fn ad0(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 0 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi0(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 0 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ad1(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 1 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi1(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 1 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ad2(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 2 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi2(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 2 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ad3(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 3 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi3(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 3 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ad4(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 4 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi4(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 4 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ad5(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 5 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi5(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 5 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ad6(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 6 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi6(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 6 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ad7(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output pin 7 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn adi7(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input pin 7 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c0(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 0 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci0(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 0 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c1(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 1 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci1(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 1 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c2(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 2 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci2(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 2 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c3(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 3 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci3(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 3 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c4(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 4 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci4(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 4 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c5(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 5 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci5(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 5 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c6(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 6 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci6(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 6 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn c7(&self) -> Result<OutputPin<Device>, Error<E>>

Aquire the digital output upper pin 7 for the FT232H.

§Panics

Panics if the pin is already in-use.

Source

pub fn ci7(&self) -> Result<InputPin<Device>, Error<E>>

Aquire the digital input upper pin 7 for the FT232H.

§Panics

Panics if the pin is already in-use.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Device> Freeze for FtHal<Device>

§

impl<Device> RefUnwindSafe for FtHal<Device>

§

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

§

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

§

impl<Device> Unpin for FtHal<Device>

§

impl<Device> UnwindSafe for FtHal<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.