pub struct Class {
pub class: u8,
pub sub_class: u8,
pub protocol: u8,
}Expand description
USB interface class.
Fields§
§class: u8Class code.
sub_class: u8Subclass code.
protocol: u8Protocol code.
Implementations§
Source§impl Class
impl Class
Sourcepub const VENDOR_SPECIFIC: u8 = 0xff
pub const VENDOR_SPECIFIC: u8 = 0xff
Vendor specific class code.
Sourcepub const fn new(class: u8, sub_class: u8, protocol: u8) -> Self
pub const fn new(class: u8, sub_class: u8, protocol: u8) -> Self
Creates a new USB device or interface class.
Sourcepub const fn vendor_specific(sub_class: u8, protocol: u8) -> Self
pub const fn vendor_specific(sub_class: u8, protocol: u8) -> Self
Creates a new USB device or interface class with vendor-specific class code.
Examples found in repository?
More examples
examples/simple_host.rs (line 10)
9async fn main() -> std::io::Result<()> {
10 let class = Class::vendor_specific(0x01, 0);
11
12 // Find and open the USB device.
13 let dev_info = nusb::list_devices()
14 .await?
15 .find(|d| d.vendor_id() == 0x1209 && d.product_id() == 0x0001)
16 .expect("device not found");
17 let iface = find_interface(&dev_info, class)?;
18 let dev = dev_info.open().await?;
19
20 // Connect and exchange packets.
21 let (tx, mut rx) = connect(dev, iface, b"hello").await?;
22 tx.send(b"ping"[..].into()).await?;
23 let reply = rx.recv().await?;
24 println!("received: {:?}", reply);
25 Ok(())
26}examples/simple_device.rs (line 13)
12async fn main() -> std::io::Result<()> {
13 let class = Class::vendor_specific(0x01, 0);
14
15 // Create a USB gadget with a UPC function.
16 let (mut upc, hnd) =
17 UpcFunction::new(InterfaceId::new(class).with_guid(uuid!("3bf77270-42d2-42c6-a475-490227a9cc89")));
18 upc.set_info(b"my device".to_vec()).await;
19
20 let udc = default_udc().expect("no UDC available");
21 let gadget = Gadget::new(class.into(), Id::new(0x1209, 0x0001), Strings::new("mfr", "product", "serial"))
22 .with_config(Config::new("config").with_function(hnd))
23 .with_os_descriptor(OsDescriptor::microsoft());
24 let _reg = gadget.bind(&udc).expect("cannot bind to UDC");
25
26 // Accept a connection and exchange packets.
27 let (tx, mut rx) = upc.accept().await?;
28 if let Some(data) = rx.recv().await? {
29 println!("received: {:?}", data);
30 tx.send(b"pong"[..].into()).await?;
31 }
32
33 // Allow USB transport to flush before teardown.
34 tokio::time::sleep(Duration::from_secs(1)).await;
35 Ok(())
36}Trait Implementations§
Source§impl From<Class> for InterfaceId
impl From<Class> for InterfaceId
Source§impl Ord for Class
impl Ord for Class
Source§impl PartialOrd for Class
impl PartialOrd for Class
impl Copy for Class
impl Eq for Class
impl StructuralPartialEq for Class
Auto Trait Implementations§
impl Freeze for Class
impl RefUnwindSafe for Class
impl Send for Class
impl Sync for Class
impl Unpin for Class
impl UnsafeUnpin for Class
impl UnwindSafe for Class
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more