#usb-device #ftdi #usb #hal #io

ftdi-embedded-hal

embedded-hal implementation for FTDI USB devices

17 releases (breaking)

Uses new Rust 2024

0.23.0 Mar 9, 2025
0.22.1 Dec 25, 2024
0.22.0 May 7, 2024
0.21.1 Mar 27, 2024
0.10.0 Nov 9, 2021

#76 in Embedded development

Download history 294/week @ 2024-12-04 685/week @ 2024-12-11 445/week @ 2024-12-18 194/week @ 2024-12-25 1645/week @ 2025-01-01 9420/week @ 2025-01-08 11575/week @ 2025-01-15 12138/week @ 2025-01-22 12300/week @ 2025-01-29 9038/week @ 2025-02-05 13812/week @ 2025-02-12 12272/week @ 2025-02-19 12671/week @ 2025-02-26 12153/week @ 2025-03-05 9197/week @ 2025-03-12 9886/week @ 2025-03-19

46,805 downloads per month
Used in 10 crates (8 directly)

MIT and maybe LGPL-2.1 AND MIT

89KB
1.5K SLoC

crates.io docs.rs Build Status

ftdi-embedded-hal

This is an embedded-hal implementation for the FTDI chips that can use various drivers including libftd2xx and ftdi-rs.

This enables development of embedded device drivers without the use of a microcontroller. The FTDI devices interface with PC via USB, and provide a multi-protocol synchronous serial engine to interface with most GPIO, SPI, I2C embedded devices.

Note: This is strictly a development tool. The crate contains runtime borrow checks and explicit panics to adapt the FTDI device into the embedded-hal traits.

Quickstart

  • Enable the "libftd2xx-static" feature flag to use static linking with libftd2xx driver.
  • Linux users only: Add udev rules.
[dependencies.ftdi-embedded-hal]
version = "0.23.0"
features = ["libftd2xx", "libftd2xx-static"]

Limitations

  • Limited trait support: SPI, I2C, Delay, InputPin, and OutputPin traits are implemented.
  • Limited device support: FT232H, FT2232H, FT4232H.
  • Limited SPI modes support: MODE0, MODE2.

Examples

SPI

Pin setup:

  • D0 - SCK
  • D1 - SDO (MOSI)
  • D2 - SDI (MISO)
  • D3..D7 - Available for CS

Communicate with SPI devices using ftdi-rs driver:

use ftdi_embedded_hal as hal;

let device = ftdi::find_by_vid_pid(0x0403, 0x6010)
    .interface(ftdi::Interface::A)
    .open()?;

let hal = hal::FtHal::init_freq(device, 3_000_000)?;
let spi = hal.spi()?;

Communicate with SPI devices using libftd2xx driver:

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()?;

I2C

Communicate with I2C devices using ftdi-rs driver:

use ftdi_embedded_hal as hal;

let device = ftdi::find_by_vid_pid(0x0403, 0x6010)
    .interface(ftdi::Interface::A)
    .open()?;

let hal = hal::FtHal::init_freq(device, 400_000)?;
let i2c = hal.i2c()?;

Communicate with I2C devices using libftd2xx driver:

use ftdi_embedded_hal as hal;

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

let hal = hal::FtHal::init_freq(device, 400_000)?;
let i2c = hal.i2c()?;

GPIO

Control GPIO pins using libftd2xx driver:

use ftdi_embedded_hal as hal;

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

let hal = hal::FtHal::init_default(device)?;
let gpio = hal.ad6();

Control GPIO pins using ftdi-rs driver:

use ftdi_embedded_hal as hal;

let device = ftdi::find_by_vid_pid(0x0403, 0x6010)
    .interface(ftdi::Interface::A)
    .open()?;

let hal = hal::FtHal::init_default(device)?;
let gpio = hal.ad6();

More examples

Dependencies

~0.2–1.7MB
~20K SLoC