Skip to content

Commit

Permalink
Merge pull request #51 from kpcyrd/docs
Browse files Browse the repository at this point in the history
Fix documentation to match usb-device 0.3
  • Loading branch information
eldruin authored Jan 21, 2025
2 parents 7331c49 + d1999b9 commit b0b589f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
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

0 comments on commit b0b589f

Please sign in to comment.