usbd_serial/lib.rs
1//! CDC-ACM USB serial port implementation for [usb-device](https://crates.io/crates/usb-device).
2//!
3//! CDC-ACM is a USB class that's supported out of the box by most operating systems and used for
4//! implementing modems and generic serial ports. The [`SerialPort`](crate::SerialPort) class
5//! implements a stream-like buffered serial port that can be used similarly to a normal UART.
6//!
7//! The crate also contains [`CdcAcmClass`](CdcAcmClass) which is a lower-level implementation that
8//! has less overhead, but requires more care to use correctly.
9//!
10//! Example
11//! =======
12//!
13//! A full example requires the use of a hardware-driver, but the hardware independent part is as
14//! follows:
15//!
16//! ```
17//! let mut serial = SerialPort::new(&usb_bus);
18//!
19//! let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
20//! .product("Serial port")
21//! .device_class(USB_CLASS_CDC)
22//! .build();
23//!
24//! loop {
25//! if !usb_dev.poll(&mut [&mut serial]) {
26//! continue;
27//! }
28//!
29//! let mut buf = [0u8; 64];
30//!
31//! match serial.read(&mut buf[..]) {
32//! Ok(count) => {
33//! // count bytes were read to &buf[..count]
34//! },
35//! Err(UsbError::WouldBlock) => // No data received
36//! Err(err) => // An error occurred
37//! };
38//!
39//! match serial.write(&[0x3a, 0x29]) {
40//! Ok(count) => {
41//! // count bytes were written
42//! },
43//! Err(UsbError::WouldBlock) => // No data could be written (buffers full)
44//! Err(err) => // An error occurred
45//! };
46//! }
47//! ```
48
49#![no_std]
50
51mod buffer;
52mod cdc_acm;
53mod io;
54mod serial_port;
55
56pub use crate::buffer::DefaultBufferStore;
57pub use crate::cdc_acm::*;
58pub use crate::serial_port::*;
59pub use embedded_io;
60pub use usb_device::{Result, UsbError};