ft260hid

Crates.ioft260hid
lib.rsft260hid
version0.1.0
sourcesrc
created_at2024-05-19 09:06:15.082092
updated_at2024-05-19 09:06:15.082092
descriptionLibrary to control FT260 USB-I2C/UART bridge IC
homepage
repositoryhttps://github.com/kndysfm/ft260hid/
max_upload_size
id1244804
size92,538
Konda Yoshifumi (kndysfm)

documentation

README

ft260hid

This unofficial library controls FT260 USB-I2C/UART bridge IC made by FTDI.
The library depends on "hidapi" crate mainly.

About FT260

This USB device does not have virtual COM port. Instead, it has HID interface.
For example, HID Input/Output Reports are converted into I2C/UART communication between the FT260 and its external devices.

Examples

Unit tests are executed on the evaluation board UMFT260EV1A.

GPIO

use ft260hid::device;
use ft260hid::io::gpio::{Dir, Group, Pin, Val};
// . . .
    let dev = device::open(0).unwrap();
    let gpio = dev.gpio();
    gpio.enable_pin(Group::Gpio_0_1);
    gpio.set_dir(Pin::Gpio0, Dir::Out);
    gpio.write(Pin::Gpio0, Val::Low);
    gpio.set_dir(Pin::Gpio1, Dir::In);
    gpio.set_pull_up(Pin::Gpio1);

I2C

I2C EEPROM (AT24C02D_SOT23) is mounted on UMFT260EV1A board, and it can be used for unit tests.

use ft260hid::device;
use ft260hid::io::i2c;
// . . .
/// I2C address of EEPROM on UMFT260EV1A
const EEPROM_ADDRESS: u8 = 0x50;
/// page size of EEPROM
const EEPROM_PAGE_SIZE: usize = 8;
// . . .
    let dev = device::open(0).unwrap();
    let mut i2c = dev.i2c();
    i2c.init(i2c::KBPS_DEFAULT);
    // address value to read EEPROM page out
    let addr = [0u8];
    let mut data_read = [0u8; EEPROM_PAGE_SIZE];
    i2c.write_read(EEPROM_ADDRESS,
                &addr,
                1,
                &mut buf,
                EEPROM_PAGE_SIZE,
                i2c::DURATION_WAIT_DEFAULT
            );

UART

The TXD-RXD pins on UMFT260EV1A are shorted for unit tests.

use ft260hid::device;
use ft260hid::io::uart;
// . . .
    // interface number is `1` !!
    let dev = device::open(1).unwrap();
    let mut uart = dev.uart();
    uart.init();
    uart.set_config(&uart::Config::default());
    // UART TX
    let mut buf_tx = [0u8; 256];
    let size_sent = uart.write(&buf_tx, len).unwrap();
    // RX data in FIFO
    let size_to_read = uart.size_to_read();
    // UART RX
    let mut buf_rx = [0u8; 256];
    let size_rec = uart.read(&mut buf_rx, size_to_read, uart::DURATION_WAIT_DEFAULT).unwrap();
Commit count: 29

cargo fmt