|
1 | 1 | //! CDC-ACM USB serial port implementation for [usb-device](https://crates.io/crates/usb-device). |
2 | 2 | //! |
3 | 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 |
| 4 | +//! implementing modems and generic serial ports. The [`SerialPort`] class |
5 | 5 | //! implements a stream-like buffered serial port that can be used similarly to a normal UART. |
6 | 6 | //! |
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 |
8 | 8 | //! has less overhead, but requires more care to use correctly. |
9 | 9 | //! |
10 | 10 | //! Example |
|
13 | 13 | //! A full example requires the use of a hardware-driver, but the hardware independent part is as |
14 | 14 | //! follows: |
15 | 15 | //! |
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 | +//! |
17 | 22 | //! let mut serial = SerialPort::new(&usb_bus); |
18 | 23 | //! |
19 | 24 | //! 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") |
21 | 27 | //! .device_class(USB_CLASS_CDC) |
22 | 28 | //! .build(); |
23 | 29 | //! |
|
32 | 38 | //! Ok(count) => { |
33 | 39 | //! // count bytes were read to &buf[..count] |
34 | 40 | //! }, |
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 */ }, |
37 | 43 | //! }; |
38 | 44 | //! |
39 | 45 | //! match serial.write(&[0x3a, 0x29]) { |
40 | 46 | //! Ok(count) => { |
41 | 47 | //! // count bytes were written |
42 | 48 | //! }, |
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 */ }, |
45 | 51 | //! }; |
46 | 52 | //! } |
| 53 | +//! # } |
47 | 54 | //! ``` |
48 | 55 |
|
49 | 56 | #![no_std] |
|
0 commit comments