pub struct FtHal<Device: MpsseCmdExecutor> { /* private fields */ }
Expand description
FTxxx device.
Implementations§
Source§impl<Device, E> FtHal<Device>
impl<Device, E> FtHal<Device>
Sourcepub fn init_default(device: Device) -> Result<FtHal<Device>, Error<E>>
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)?;
Sourcepub fn init_freq(device: Device, freq: u32) -> Result<FtHal<Device>, Error<E>>
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)?;
Sourcepub fn init(
device: Device,
mpsse_settings: &MpsseSettings,
) -> Result<FtHal<Device>, E>
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>
impl<Device, E> FtHal<Device>
Sourcepub fn with_device<T, F>(&mut self, f: F) -> Twhere
F: FnMut(&mut Device) -> T,
pub fn with_device<T, F>(&mut self, f: F) -> Twhere
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()))?;
Sourcepub fn spi(&self) -> Result<Spi<Device>, Error<E>>
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()?;
Sourcepub fn spi_device(&self, cs_idx: u8) -> Result<SpiDevice<Device>, Error<E>>
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)?;
Sourcepub fn i2c(&self) -> Result<I2c<Device>, Error<E>>
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()?;