Struct libftd2xx::MpsseCmdBuilder [−][src]
FTDI Multi-Protocol Synchronous Serial Engine (MPSSE) command builder.
For details about the MPSSE read the FTDI MPSSE Basics.
This structure is a Vec<u8>
that the methods push bytewise commands onto.
These commands can then be written to the device with the write_all
method.
This is useful for creating commands that need to do multiple operations
quickly, since individual write_all
calls can be expensive.
For example, this can be used to set a GPIO low and clock data out for
SPI operations.
Implementations
impl MpsseCmdBuilder
[src]
pub const fn new() -> MpsseCmdBuilder
[src]
pub const fn with_vec(vec: Vec<u8>) -> MpsseCmdBuilder
[src]
Create a new command builder from a vector.
Example
use libftd2xx::MpsseCmdBuilder; MpsseCmdBuilder::with_vec(Vec::new());
pub fn as_slice(&self) -> &[u8]
[src]
Get the MPSSE command as a slice.
Example
use libftd2xx::{DeviceType, Ft232h, FtdiCommon, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new().set_clock(100_000, DeviceType::FT232H); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.write_all(cmd.as_slice())?;
pub fn set_clock(
mut self: Self,
frequency: u32,
device_type: DeviceType
) -> Self
[src]
mut self: Self,
frequency: u32,
device_type: DeviceType
) -> Self
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::{DeviceType, Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new() .set_clock(100_000, DeviceType::FT232H) .set_gpio_lower(0xFF, 0xFF); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?;
pub fn enable_loopback(mut self: Self) -> Self
[src]
Enable the MPSSE loopback state.
Example
use libftd2xx::{Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new().enable_loopback(); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?;
pub fn disable_loopback(mut self: Self) -> Self
[src]
Disable the MPSSE loopback state.
Example
use libftd2xx::{Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new().disable_loopback(); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?;
pub fn disable_3phase_data_clocking(mut self: Self) -> Self
[src]
Disable 3 phase data clocking.
This is only avaliable on FTx232H devices.
This will give a 2 stage data shift which is the default state.
It will appears as:
- Data setup for 1/2 clock period
- Pulse clock for 1/2 clock period
Example
use libftd2xx::{Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new().disable_3phase_data_clocking(); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?;
pub fn enable_3phase_data_clocking(mut self: Self) -> Self
[src]
Enable 3 phase data clocking.
This is only avaliable on FTx232H devices.
This will give a 3 stage data shift for the purposes of supporting interfaces such as I2C which need the data to be valid on both edges of the clock.
It will appears as:
- Data setup for 1/2 clock period
- Pulse clock for 1/2 clock period
- Data hold for 1/2 clock period
Example
use libftd2xx::{Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new().enable_3phase_data_clocking(); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?;
pub fn set_gpio_lower(mut self: Self, state: u8, direction: u8) -> Self
[src]
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, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new() .set_gpio_lower(0xFF, 0xFF) .set_gpio_lower(0x00, 0xFF); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?;
pub fn set_gpio_upper(mut self: Self, state: u8, direction: u8) -> Self
[src]
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.
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.
Example
use libftd2xx::{Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new() .set_gpio_upper(0xFF, 0xFF) .set_gpio_upper(0x00, 0xFF); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?;
pub fn gpio_lower(mut self: Self) -> Self
[src]
Get the pin state state of the lower byte (0-7) GPIO pins on the MPSSE interface.
Example
use libftd2xx::{Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new().gpio_lower().send_immediate(); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?; let mut buf: [u8; 1] = [0; 1]; ft.read_all(&mut buf)?; println!("GPIO lower state: 0x{:02X}", buf[0]);
pub fn gpio_upper(mut self: Self) -> Self
[src]
Get the pin state state of the upper byte (8-15) GPIO pins on the MPSSE interface.
See set_gpio_upper
for additional information about physical pin
mappings.
Example
use libftd2xx::{Ft232h, FtdiCommon, FtdiMpsse, MpsseCmdBuilder}; let cmd = MpsseCmdBuilder::new().gpio_upper().send_immediate(); let mut ft = Ft232h::with_serial_number("FT5AVX6B")?; ft.initialize_mpsse_default()?; ft.write_all(cmd.as_slice())?; let mut buf: [u8; 1] = [0; 1]; ft.read_all(&mut buf)?; println!("GPIO upper state: 0x{:02X}", buf[0]);
pub fn send_immediate(mut self: Self) -> Self
[src]
Send the preceding commands immediately.
Example
use libftd2xx::MpsseCmdBuilder; let cmd = MpsseCmdBuilder::new() .set_gpio_upper(0xFF, 0xFF) .set_gpio_upper(0x00, 0xFF) .send_immediate();
pub fn clock_data_out(mut self: Self, mode: ClockDataOut, data: &[u8]) -> Self
[src]
Clock data out.
This will clock out bytes on TDI/DO. No data is clocked into the device on TDO/DI.
This will panic for data lengths greater than u16::MAX + 1
.
pub fn clock_data_in(mut self: Self, mode: ClockDataIn, mut len: usize) -> Self
[src]
Clock data in.
This will clock in bytes on TDO/DI. No data is clocked out of the device on TDI/DO.
Arguments
mode
- Data clocking mode.len
- Number of bytes to clock in. This will panic for values greater thanu16::MAX + 1
.
pub fn clock_data(mut self: Self, mode: ClockData, data: &[u8]) -> Self
[src]
Clock data in and out simultaneously.
This will panic for data lengths greater than u16::MAX + 1
.
pub fn clock_bits_out(
mut self: Self,
mode: ClockBitsOut,
data: u8,
mut len: u8
) -> Self
[src]
mut self: Self,
mode: ClockBitsOut,
data: u8,
mut len: u8
) -> Self
Clock data bits out.
Arguments
mode
- Bit clocking mode.data
- Data bits.len
- Number of bits to clock out. This will panic for values greater than 8.
pub fn clock_bits_in(mut self: Self, mode: ClockBitsIn, mut len: u8) -> Self
[src]
Clock data bits in.
Arguments
mode
- Bit clocking mode.len
- Number of bits to clock in. This will panic for values greater than 8.
pub fn clock_bits(
mut self: Self,
mode: ClockBits,
data: u8,
mut len: u8
) -> Self
[src]
mut self: Self,
mode: ClockBits,
data: u8,
mut len: u8
) -> Self
Clock data bits in and out simultaneously.
Arguments
mode
- Bit clocking mode.len
- Number of bits to clock in. This will panic for values greater than 8.
Auto Trait Implementations
impl RefUnwindSafe for MpsseCmdBuilder
[src]
impl Send for MpsseCmdBuilder
[src]
impl Sync for MpsseCmdBuilder
[src]
impl Unpin for MpsseCmdBuilder
[src]
impl UnwindSafe for MpsseCmdBuilder
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,