Add docs
This commit is contained in:
parent
38bfa6916f
commit
e3fe13e905
@ -1,6 +1,50 @@
|
||||
//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
|
||||
//! Example of using USB without a pre-defined class, but instead responding to
|
||||
//! raw USB control requests.
|
||||
//!
|
||||
//! This creates a USB serial port that echos.
|
||||
//! The host computer can either:
|
||||
//! * send a command, with a 16-bit request ID, a 16-bit value, and an optional data buffer
|
||||
//! * request some data, with a 16-bit request ID, a 16-bit value, and a length of data to receive
|
||||
//!
|
||||
//! For higher throughput data, you can add some bulk endpoints after creating the alternate,
|
||||
//! but for low rate command/response, plain control transfers can be very simple and effective.
|
||||
//!
|
||||
//! Example code to send/receive data using `nusb`:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! use futures_lite::future::block_on;
|
||||
//! use nusb::transfer::{ControlIn, ControlOut, ControlType, Recipient};
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let di = nusb::list_devices()
|
||||
//! .unwrap()
|
||||
//! .find(|d| d.vendor_id() == 0xc0de && d.product_id() == 0xcafe)
|
||||
//! .expect("no device found");
|
||||
//! let device = di.open().expect("error opening device");
|
||||
//! let interface = device.claim_interface(0).expect("error claiming interface");
|
||||
//!
|
||||
//! // Send "hello world" to device
|
||||
//! let result = block_on(interface.control_out(ControlOut {
|
||||
//! control_type: ControlType::Vendor,
|
||||
//! recipient: Recipient::Interface,
|
||||
//! request: 100,
|
||||
//! value: 200,
|
||||
//! index: 0,
|
||||
//! data: b"hello world",
|
||||
//! }));
|
||||
//! println!("{result:?}");
|
||||
//!
|
||||
//! // Receive "hello" from device
|
||||
//! let result = block_on(interface.control_in(ControlIn {
|
||||
//! control_type: ControlType::Vendor,
|
||||
//! recipient: Recipient::Interface,
|
||||
//! request: 101,
|
||||
//! value: 201,
|
||||
//! index: 0,
|
||||
//! length: 5,
|
||||
//! }));
|
||||
//! println!("{result:?}");
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
Loading…
Reference in New Issue
Block a user