cp211x_uart

HID-to-UART driver for CP2110/CP2114 chipset

6 releases

Uses old Rust 2015

0.2.2 Dec 31, 2017
0.2.0 Dec 6, 2017
0.1.3 Nov 11, 2017
0.1.0 Sep 28, 2017


Used in 2 crates (via ut181a)

MIT license

14KB
273 lines

cp211x_uart

Documentation License: MIT Build Status

HID-to-UART driver for CP2110/CP2114 chipset. It is wrapper around hid::Handle intrinsically.

See documentation for details.

Building

Linux

$ sudo apt-get install libudev-dev libhidapi-dev
$ cargo build

Usage

extern crate hid;
extern crate cp211x_uart;

use std::time::Duration;
use cp211x_uart::{HidUart, UartConfig, DataBits, StopBits, Parity, FlowControl};

fn run() -> Result<(), cp211x_uart::Error> {
    let manager = hid::init()?;
    for device in manager.find(Some(0x10C4), Some(0xEA80)) {
        let handle = device.open()?;
        let mut uart = HidUart::new(handle)?;

        let config = UartConfig {
            baud_rate: 9600,
            data_bits: DataBits::Bits8,
            stop_bits: StopBits::Short,
            parity: Parity::None,
            flow_control: FlowControl::None,
        };

        uart.set_config(&config)?;
        uart.set_read_timeout(Duration::from_millis(50));
        uart.set_write_timeout(Duration::from_millis(500));
        uart.flush_fifos(true, true)?;

        uart.write(&[0x01, 0x02, 0x03][..])?;
        let mut buf: [u8; 256] = [0; 256];
        uart.read(&mut buf)?;
    }
}

fn main() {
    match run() {
        Ok() => {}
        Err(err) => {
            eprintln!("ERROR: {}", err);
        }
    }
}

License

This library licensed under the following:

Dependencies

~2.4–8.5MB
~75K SLoC