GithubHelp home page GithubHelp logo

muratursavas / usbd-serial Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rust-embedded-community/usbd-serial

0.0 0.0 0.0 40 KB

Work-in progress minimal CDC-ACM (USB serial port) class for usb-device

License: MIT License

Rust 100.00%

usbd-serial's Introduction

usbd-serial

CDC-ACM USB serial port implementation for usb-device.

CDC-ACM is a USB class that's supported out of the box by most operating systems and used for implementing modems and generic serial ports. The SerialPort class implements a stream-like buffered serial port that can be used similarly to a normal UART.

The crate also contains CdcAcmClass which is a lower-level implementation that has less overhead, but requires more care to use correctly.

Example

A full example requires the use of a hardware-driver, but the hardware independent part is as follows:

let mut serial = SerialPort::new(&usb_bus);

let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
    .product("Serial port")
    .device_class(USB_CLASS_CDC)
    .build();

loop {
    if !usb_dev.poll(&mut [&mut serial]) {
        continue;
    }

    let mut buf = [0u8; 64];

    match serial.read(&mut buf[..]) {
        Ok(count) => {
            // count bytes were read to &buf[..count]
        },
        Err(UsbError::WouldBlock) => // No data received
        Err(err) => // An error occurred
    };

    match serial.write(&[0x3a, 0x29]) {
        Ok(count) => {
            // count bytes were written
        },
        Err(UsbError::WouldBlock) => // No data could be written (buffers full)
        Err(err) => // An error occurred
    };
}

usbd-serial's People

Contributors

mvirkkunen avatar eldruin avatar dirbaio avatar disasm avatar atykhyy avatar conorpp avatar nickray avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.