aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/src/bin/usb_raw.rs48
1 files changed, 46 insertions, 2 deletions
diff --git a/examples/rp/src/bin/usb_raw.rs b/examples/rp/src/bin/usb_raw.rs
index 044e728a0..f59262e5c 100644
--- a/examples/rp/src/bin/usb_raw.rs
+++ b/examples/rp/src/bin/usb_raw.rs
@@ -1,6 +1,50 @@
1//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip. 1//! Example of using USB without a pre-defined class, but instead responding to
2//! raw USB control requests.
2//! 3//!
3//! This creates a USB serial port that echos. 4//! The host computer can either:
5//! * send a command, with a 16-bit request ID, a 16-bit value, and an optional data buffer
6//! * request some data, with a 16-bit request ID, a 16-bit value, and a length of data to receive
7//!
8//! For higher throughput data, you can add some bulk endpoints after creating the alternate,
9//! but for low rate command/response, plain control transfers can be very simple and effective.
10//!
11//! Example code to send/receive data using `nusb`:
12//!
13//! ```ignore
14//! use futures_lite::future::block_on;
15//! use nusb::transfer::{ControlIn, ControlOut, ControlType, Recipient};
16//!
17//! fn main() {
18//! let di = nusb::list_devices()
19//! .unwrap()
20//! .find(|d| d.vendor_id() == 0xc0de && d.product_id() == 0xcafe)
21//! .expect("no device found");
22//! let device = di.open().expect("error opening device");
23//! let interface = device.claim_interface(0).expect("error claiming interface");
24//!
25//! // Send "hello world" to device
26//! let result = block_on(interface.control_out(ControlOut {
27//! control_type: ControlType::Vendor,
28//! recipient: Recipient::Interface,
29//! request: 100,
30//! value: 200,
31//! index: 0,
32//! data: b"hello world",
33//! }));
34//! println!("{result:?}");
35//!
36//! // Receive "hello" from device
37//! let result = block_on(interface.control_in(ControlIn {
38//! control_type: ControlType::Vendor,
39//! recipient: Recipient::Interface,
40//! request: 101,
41//! value: 201,
42//! index: 0,
43//! length: 5,
44//! }));
45//! println!("{result:?}");
46//! }
47//! ```
4 48
5#![no_std] 49#![no_std]
6#![no_main] 50#![no_main]