pub trait FtdiMpsse: FtdiCommon {
Show 13 methods
// Provided methods
fn set_clock(&mut self, frequency: u32) -> Result<(), TimeoutError> { ... }
fn initialize_mpsse(
&mut self,
settings: &MpsseSettings
) -> Result<(), TimeoutError> { ... }
fn initialize_mpsse_default(&mut self) -> Result<(), TimeoutError> { ... }
fn synchronize_mpsse(&mut self) -> Result<(), TimeoutError> { ... }
fn enable_loopback(&mut self) -> Result<(), TimeoutError> { ... }
fn disable_loopback(&mut self) -> Result<(), TimeoutError> { ... }
fn set_gpio_lower(
&mut self,
state: u8,
direction: u8
) -> Result<(), TimeoutError> { ... }
fn gpio_lower(&mut self) -> Result<u8, TimeoutError> { ... }
fn set_gpio_upper(
&mut self,
state: u8,
direction: u8
) -> Result<(), TimeoutError> { ... }
fn gpio_upper(&mut self) -> Result<u8, TimeoutError> { ... }
fn clock_data_out(
&mut self,
mode: ClockDataOut,
data: &[u8]
) -> Result<(), TimeoutError> { ... }
fn clock_data_in(
&mut self,
mode: ClockDataIn,
data: &mut [u8]
) -> Result<(), TimeoutError> { ... }
fn clock_data(
&mut self,
mode: ClockData,
data: &mut [u8]
) -> Result<(), TimeoutError> { ... }
}
Expand description
FTDI Multi-Protocol Synchronous Serial Engine (MPSSE).
For details about the MPSSE read the FTDI MPSSE Basics.
Provided Methods§
sourcefn set_clock(&mut self, frequency: u32) -> Result<(), TimeoutError>
fn set_clock(&mut self, frequency: u32) -> Result<(), TimeoutError>
Set the clock frequency.
§Frequency Limits
Device Type | Minimum | Maximum |
---|---|---|
FT2232D | 92 Hz | 6 MHz |
FT4232H, FT2232H, FT232H | 92 Hz | 30 MHz |
Values outside of these limits will result in panic.
§Example
use libftd2xx::{Ft4232h, FtdiMpsse};
let mut ft = Ft4232h::with_serial_number("FT4PWSEOA")?;
ft.initialize_mpsse_default()?;
ft.set_clock(100_000)?;
sourcefn initialize_mpsse(
&mut self,
settings: &MpsseSettings
) -> Result<(), TimeoutError>
fn initialize_mpsse( &mut self, settings: &MpsseSettings ) -> Result<(), TimeoutError>
Initialize the MPSSE.
This method does the following:
- Optionally
reset
s the device. - Sets USB transfer sizes using values provided.
- Disables special characters.
- Sets the transfer timeouts using values provided.
- Sets latency timers using values provided.
- Sets the flow control to RTS CTS.
- Resets the bitmode, then sets it to MPSSE.
- Enables loopback.
- Synchronizes the MPSSE.
- Disables loopback.
- Optionally sets the clock frequency.
Upon failure cleanup is not guaranteed.
§Example
Initialize the MPSSE with a 5 second read timeout.
use ftdi_mpsse::MpsseSettings;
use libftd2xx::{Ft232h, FtdiMpsse};
use std::time::Duration;
let mut settings = MpsseSettings::default();
settings.read_timeout = Duration::from_secs(5);
let mut ft = Ft232h::with_serial_number("FT59UO4C")?;
ft.initialize_mpsse(&settings)?;
sourcefn initialize_mpsse_default(&mut self) -> Result<(), TimeoutError>
fn initialize_mpsse_default(&mut self) -> Result<(), TimeoutError>
Initializes the MPSSE to default settings.
This simply calles initialize_mpsse
with the default
MpsseSettings
.
§Example
use libftd2xx::{Ft232h, FtdiMpsse};
let mut ft = Ft232h::with_serial_number("FT59UO4C")?;
ft.initialize_mpsse_default()?;
sourcefn synchronize_mpsse(&mut self) -> Result<(), TimeoutError>
fn synchronize_mpsse(&mut self) -> Result<(), TimeoutError>
Synchronize the MPSSE port with the application.
There are various implementations of the synchronization flow, this uses the flow from FTDI MPSSE Basics.
sourcefn enable_loopback(&mut self) -> Result<(), TimeoutError>
fn enable_loopback(&mut self) -> Result<(), TimeoutError>
Enable the MPSSE loopback state.
§Example
use libftd2xx::{Ft4232h, FtdiMpsse};
let mut ft = Ft4232h::with_serial_number("FT4PWSEOA")?;
ft.initialize_mpsse_default()?;
ft.enable_loopback()?;
sourcefn disable_loopback(&mut self) -> Result<(), TimeoutError>
fn disable_loopback(&mut self) -> Result<(), TimeoutError>
Disable the MPSSE loopback state.
§Example
use libftd2xx::{Ft4232h, FtdiMpsse};
let mut ft = Ft4232h::with_serial_number("FT4PWSEOA")?;
ft.initialize_mpsse_default()?;
ft.disable_loopback()?;
sourcefn set_gpio_lower(
&mut self,
state: u8,
direction: u8
) -> Result<(), TimeoutError>
fn set_gpio_lower( &mut self, state: u8, direction: u8 ) -> Result<(), TimeoutError>
Set the pin direction and state of the lower byte (0-7) GPIO pins on the MPSSE interface.
The pins that this controls depends on the device.
- On the FT232H this will control the AD0-AD7 pins.
§Arguments
state
- GPIO state mask,0
is low (or input pin),1
is high.direction
- GPIO direction mask,0
is input,1
is output.
§Example
use libftd2xx::{Ft232h, FtdiMpsse};
let mut ft = Ft232h::with_serial_number("FT5AVX6B")?;
ft.initialize_mpsse_default()?;
ft.set_gpio_lower(0xFF, 0xFF)?;
ft.set_gpio_lower(0x00, 0xFF)?;
sourcefn gpio_lower(&mut self) -> Result<u8, TimeoutError>
fn gpio_lower(&mut self) -> Result<u8, TimeoutError>
Get the pin state state of the lower byte (0-7) GPIO pins on the MPSSE interface.
§Example
Set the first GPIO, without modify the state of the other GPIOs.
use libftd2xx::{Ft232h, FtdiMpsse};
let mut ft = Ft232h::with_serial_number("FT59UO4C")?;
ft.initialize_mpsse_default()?;
let mut gpio_state: u8 = ft.gpio_lower()?;
gpio_state |= 0x01;
ft.set_gpio_lower(gpio_state, 0xFF)?;
sourcefn set_gpio_upper(
&mut self,
state: u8,
direction: u8
) -> Result<(), TimeoutError>
fn set_gpio_upper( &mut self, state: u8, direction: u8 ) -> Result<(), TimeoutError>
Set the pin direction and state of the upper byte (8-15) GPIO pins on the MPSSE interface.
The pins that this controls depends on the device. This method may do nothing for some devices, such as the FT4232H that only have 8 pins per port.
See set_gpio_lower
for an example.
§Arguments
state
- GPIO state mask,0
is low (or input pin),1
is high.direction
- GPIO direction mask,0
is input,1
is output.
§FT232H Corner Case
On the FT232H only CBUS5, CBUS6, CBUS8, and CBUS9 can be controlled. These pins confusingly map to the first four bits in the direction and state masks.
sourcefn gpio_upper(&mut self) -> Result<u8, TimeoutError>
fn gpio_upper(&mut self) -> Result<u8, TimeoutError>
Get the pin state state of the upper byte (8-15) GPIO pins on the MPSSE interface.
See gpio_lower
for an example.
See set_gpio_upper
for additional information about physical pin
mappings.
sourcefn clock_data_out(
&mut self,
mode: ClockDataOut,
data: &[u8]
) -> Result<(), TimeoutError>
fn clock_data_out( &mut self, mode: ClockDataOut, data: &[u8] ) -> Result<(), TimeoutError>
Clock data out.
This will clock out bytes on TDI/DO. No data is clocked into the device on TDO/DI.
§Example
use ftdi_mpsse::ClockDataOut;
use libftd2xx::{Ft232h, FtdiMpsse};
let mut ft = Ft232h::with_serial_number("FT5AVX6B")?;
ft.initialize_mpsse_default()?;
ft.set_clock(100_000)?;
ft.set_gpio_lower(0xFA, 0xFB)?;
ft.set_gpio_lower(0xF2, 0xFB)?;
ft.clock_data_out(ClockDataOut::MsbNeg, &[0x12, 0x34, 0x56])?;
ft.set_gpio_lower(0xFA, 0xFB)?;
sourcefn clock_data_in(
&mut self,
mode: ClockDataIn,
data: &mut [u8]
) -> Result<(), TimeoutError>
fn clock_data_in( &mut self, mode: ClockDataIn, data: &mut [u8] ) -> Result<(), TimeoutError>
Clock data in.
This will clock in bytes on TDO/DI. No data is clocked out of the device on TDI/DO.
sourcefn clock_data(
&mut self,
mode: ClockData,
data: &mut [u8]
) -> Result<(), TimeoutError>
fn clock_data( &mut self, mode: ClockData, data: &mut [u8] ) -> Result<(), TimeoutError>
Clock data in and out at the same time.