#ftdi #usb

libftd2xx

Rust safe wrapper around the libftd2xx-ffi crate

41 releases (27 breaking)

0.28.0 Apr 4, 2021
0.27.0 Mar 27, 2021
0.26.0 Mar 20, 2021
0.24.0 Dec 28, 2020
0.7.1 Jul 27, 2020

#25 in Hardware support

Download history 22/week @ 2020-12-24 53/week @ 2020-12-31 19/week @ 2021-01-07 54/week @ 2021-01-14 48/week @ 2021-01-21 32/week @ 2021-01-28 10/week @ 2021-02-04 553/week @ 2021-02-11 129/week @ 2021-02-18 34/week @ 2021-02-25 38/week @ 2021-03-04 73/week @ 2021-03-11 100/week @ 2021-03-18 207/week @ 2021-03-25 127/week @ 2021-04-01 92/week @ 2021-04-08

451 downloads per month
Used in 2 crates (via ftd2xx-embedded-hal)

MIT license

190KB
2.5K SLoC

Maintenance crates.io docs.rs CI

libftd2xx

Rust safe wrapper for the FTDI D2XX drivers.

This takes the libftd2xx-ffi C bindings crate and extends it with rust safe wrappers.

Usage

Simply add this crate as a dependency in your Cargo.toml.

[dependencies.libftd2xx]
version = "~0.28.0"
# statically link the vendor library, defaults to dynamic if not set
# this will make things "just work" on Linux
# not recommended on Windows due to legacy library requirements
features = ["static"]

This is a basic example to get your started. Check the source code or documentation for more examples.

use libftd2xx::{Ftdi, FtdiCommon};

let mut ft = Ftdi::new()?;
let info = ft.device_info()?;
println!("Device information: {:?}", info);

This crate is just a wrapper around the FTD2XX driver; I2C, SPI, and GPIO examples using the embedded-hal traits can be found in ftd2xx-embedded-hal.

udev rules

To access the FTDI USB device as a regular user on Linux you need to update the udev rules.

Create a file called /etc/udev/rules.d/99-ftdi.rules with:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", MODE="0666"

Then, reload the rules:

sudo udevadm control --reload-rules
sudo udevadm trigger

Linking

By default this crate with use dynamic linking for the vendor library. Use the static feature flag to enable static linking.

Dynamic Linking on Linux

The shared object libftd2xx.so must exist on your system. See FTDI Drivers Installation Guide for Linux for instructions.

Static Linking on Linux

No special considerations are needed, the static library is distributed with permission from FTDI in the libftd2xx-ffi crate.

Dynamic Linking on Windows

The FTD2XX DLL must exist on your system PATH. The easiest way to install this is with the vendor provided setup executable.

Static Linking on Windows

You must set the "LIBMSVC_PATH" environment variable to link with legacy_stdio_definitions.lib (vendor library requirement). See libftd2xx-ffi for more information.

References

Troubleshooting

Unknown Device on Linux

Remove the VCP FTDI driver.

sudo rmmod ftdi_sio
sudo rmmod usbserial

See FTDI Drivers Installation Guide for Linux for more details.

Dependencies

~2MB
~36K SLoC