Skip to content

Commit b0b589f

Browse files
authored
Merge pull request #51 from kpcyrd/docs
Fix documentation to match usb-device 0.3
2 parents 7331c49 + d1999b9 commit b0b589f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ follows:
2020
let mut serial = SerialPort::new(&usb_bus);
2121

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

src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! CDC-ACM USB serial port implementation for [usb-device](https://crates.io/crates/usb-device).
22
//!
33
//! 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
4+
//! implementing modems and generic serial ports. The [`SerialPort`] class
55
//! implements a stream-like buffered serial port that can be used similarly to a normal UART.
66
//!
7-
//! The crate also contains [`CdcAcmClass`](CdcAcmClass) which is a lower-level implementation that
7+
//! The crate also contains [`CdcAcmClass`] which is a lower-level implementation that
88
//! has less overhead, but requires more care to use correctly.
99
//!
1010
//! Example
@@ -13,11 +13,17 @@
1313
//! A full example requires the use of a hardware-driver, but the hardware independent part is as
1414
//! follows:
1515
//!
16-
//! ```
16+
//! ```no_run
17+
//! # use usb_device::class_prelude::*;
18+
//! # fn dummy(usb_bus: UsbBusAllocator<impl UsbBus>) {
19+
//! use usb_device::prelude::*;
20+
//! use usbd_serial::{SerialPort, USB_CLASS_CDC};
21+
//!
1722
//! let mut serial = SerialPort::new(&usb_bus);
1823
//!
1924
//! let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
20-
//! .product("Serial port")
25+
//! .strings(&[StringDescriptors::new(LangID::EN).product("Serial port")])
26+
//! .expect("Failed to set strings")
2127
//! .device_class(USB_CLASS_CDC)
2228
//! .build();
2329
//!
@@ -32,18 +38,19 @@
3238
//! Ok(count) => {
3339
//! // count bytes were read to &buf[..count]
3440
//! },
35-
//! Err(UsbError::WouldBlock) => // No data received
36-
//! Err(err) => // An error occurred
41+
//! Err(UsbError::WouldBlock) => { /* No data received */ },
42+
//! Err(err) => { /* An error occurred */ },
3743
//! };
3844
//!
3945
//! match serial.write(&[0x3a, 0x29]) {
4046
//! Ok(count) => {
4147
//! // count bytes were written
4248
//! },
43-
//! Err(UsbError::WouldBlock) => // No data could be written (buffers full)
44-
//! Err(err) => // An error occurred
49+
//! Err(UsbError::WouldBlock) => { /* No data could be written (buffers full) */ },
50+
//! Err(err) => { /* An error occurred */ },
4551
//! };
4652
//! }
53+
//! # }
4754
//! ```
4855
4956
#![no_std]

0 commit comments

Comments
 (0)