Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation to match usb-device 0.3 #51

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ follows:
let mut serial = SerialPort::new(&usb_bus);

let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
.product("Serial port")
.strings(&[StringDescriptors::new(LangID::EN).product("Serial port")])
.expect("Failed to set strings")
.device_class(USB_CLASS_CDC)
.build();

Expand Down
23 changes: 15 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! 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`](crate::SerialPort) class
//! 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`](CdcAcmClass) which is a lower-level implementation that
//! The crate also contains [`CdcAcmClass`] which is a lower-level implementation that
//! has less overhead, but requires more care to use correctly.
//!
//! Example
Expand All @@ -13,11 +13,17 @@
//! A full example requires the use of a hardware-driver, but the hardware independent part is as
//! follows:
//!
//! ```
//! ```no_run
//! # use usb_device::class_prelude::*;
//! # fn dummy(usb_bus: UsbBusAllocator<impl UsbBus>) {
//! use usb_device::prelude::*;
//! use usbd_serial::{SerialPort, USB_CLASS_CDC};
//!
//! let mut serial = SerialPort::new(&usb_bus);
//!
//! let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
//! .product("Serial port")
//! .strings(&[StringDescriptors::new(LangID::EN).product("Serial port")])
//! .expect("Failed to set strings")
//! .device_class(USB_CLASS_CDC)
//! .build();
//!
Expand All @@ -32,18 +38,19 @@
//! Ok(count) => {
//! // count bytes were read to &buf[..count]
//! },
//! Err(UsbError::WouldBlock) => // No data received
//! Err(err) => // An error occurred
//! 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
//! Err(UsbError::WouldBlock) => { /* No data could be written (buffers full) */ },
//! Err(err) => { /* An error occurred */ },
//! };
//! }
//! # }
//! ```

#![no_std]
Expand Down
Loading