Trait kernel::usb::Driver

source ·
pub trait Driver {
    type IdInfo: 'static;

    const ID_TABLE: IdTable<Self::IdInfo>;

    // Required methods
    fn probe(
        interface: &Interface<Core>,
        id: &DeviceId,
        id_info: &Self::IdInfo
    ) -> impl PinInit<Self, Error>;
    fn disconnect(interface: &Interface<Core>, data: Pin<&Self>);
}
Expand description

The USB driver trait.

§Examples

 use kernel::prelude::*;

 struct MyDriver;

 kernel::usb_device_table!(
     USB_TABLE,
     MODULE_USB_TABLE,
     <MyDriver as usb::Driver>::IdInfo,
     [
         (usb::DeviceId::from_id(0x1234, 0x5678), ()),
         (usb::DeviceId::from_id(0xabcd, 0xef01), ()),
     ]
 );

 impl usb::Driver for MyDriver {
     type IdInfo = ();
     const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;

     fn probe(
         _interface: &usb::Interface<Core>,
         _id: &usb::DeviceId,
         _info: &Self::IdInfo,
     ) -> impl PinInit<Self, Error> {
         Err(ENODEV)
     }

     fn disconnect(_interface: &usb::Interface<Core>, _data: Pin<&Self>) {}
 }

Required Associated Types§

source

type IdInfo: 'static

The type holding information about each one of the device ids supported by the driver.

Required Associated Constants§

source

const ID_TABLE: IdTable<Self::IdInfo>

The table of device ids supported by the driver.

Required Methods§

source

fn probe( interface: &Interface<Core>, id: &DeviceId, id_info: &Self::IdInfo ) -> impl PinInit<Self, Error>

USB driver probe.

Called when a new USB interface is bound to this driver. Implementers should attempt to initialize the interface here.

source

fn disconnect(interface: &Interface<Core>, data: Pin<&Self>)

USB driver disconnect.

Called when the USB interface is about to be unbound from this driver.

Object Safety§

This trait is not object safe.

Implementors§