Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rust-embedded-community/usbd-serial
Work-in progress minimal CDC-ACM (USB serial port) class for usb-device
https://github.com/rust-embedded-community/usbd-serial
Last synced: 4 months ago
JSON representation
Work-in progress minimal CDC-ACM (USB serial port) class for usb-device
- Host: GitHub
- URL: https://github.com/rust-embedded-community/usbd-serial
- Owner: rust-embedded-community
- License: mit
- Created: 2019-05-23T15:14:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-06T09:15:22.000Z (4 months ago)
- Last Synced: 2024-03-13T15:08:37.900Z (4 months ago)
- Language: Rust
- Size: 46.9 KB
- Stars: 99
- Watchers: 9
- Forks: 30
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Lists
- not-yet-awesome-embedded-rust - usbd-serial
README
usbd-serial
===========CDC-ACM USB serial port implementation for [usb-device](https://crates.io/crates/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:```rust
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
};
}
```