Skip to main content

Driver

Trait Driver 

Source
pub trait Driver {
    type IdInfo: 'static;
    type Data<'bound>: Send + 'bound;

    const ID_TABLE: IdTable<Self::IdInfo>;

    // Required methods
    fn probe<'bound>(
        interface: &'bound Interface<Core<'_>>,
        id: &DeviceId,
        id_info: &'bound Self::IdInfo,
    ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;
    fn disconnect<'bound>(
        interface: &'bound Interface<Core<'_>>,
        data: Pin<&Self::Data<'bound>>,
    );
}
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 = ();
     type Data<'bound> = Self;
     const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;

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

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

Required Associated Constants§

Source

const ID_TABLE: IdTable<Self::IdInfo>

The table of device ids supported by the driver.

Required Associated Types§

Source

type IdInfo: 'static

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

Source

type Data<'bound>: Send + 'bound

The type of the driver’s bus device private data.

Required Methods§

Source

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

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<'bound>( interface: &'bound Interface<Core<'_>>, data: Pin<&Self::Data<'bound>>, )

USB driver disconnect.

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§