Skip to main content

Driver

Trait Driver 

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

    const USE_VTABLE_ATTR: ();
    const OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;
    const ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;
    const HAS_PROBE: bool = false;
    const HAS_UNBIND: bool = false;
    const HAS_RECEIVE: bool = false;

    // Required method
    fn probe<'bound>(
        sdev: &'bound Device<Core<'_>>,
        id_info: Option<&'bound Self::IdInfo>,
    ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;

    // Provided methods
    fn unbind<'bound>(
        sdev: &'bound Device<Core<'_>>,
        this: Pin<&Self::Data<'bound>>,
    ) { ... }
    fn receive<'bound>(
        sdev: &'bound Device<Bound>,
        this: Pin<&Self::Data<'bound>>,
        data: &[u8],
    ) -> usize { ... }
}
Expand description

The serial device bus device driver trait.

Drivers must implement this trait in order to get a serial device bus device driver registered.

§Examples

     acpi,
     bindings,
     device::{
         Bound,
         Core, //
     },
     of,
     serdev, //
 };

 struct MyDriver;

 kernel::of_device_table!(
     OF_TABLE,
     <MyDriver as serdev::Driver>::IdInfo,
     [
         (of::DeviceId::new(c"test,device"), ())
     ]
 );

 kernel::acpi_device_table!(
     ACPI_TABLE,
     <MyDriver as serdev::Driver>::IdInfo,
     [
         (acpi::DeviceId::new(c"LNUXBEEF"), ())
     ]
 );

 #[vtable]
 impl serdev::Driver for MyDriver {
     type IdInfo = ();
     type Data<'bound> = Self;
     const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
     const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);

     fn probe<'bound>(
         sdev: &'bound serdev::Device<Core<'_>>,
         _id_info: Option<&'bound Self::IdInfo>,
     ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
         sdev.set_baudrate(115200);
         sdev.write_all(b"Hello\n", 0)?;
         Ok(MyDriver)
     }
 }

Required Associated Constants§

Source

const USE_VTABLE_ATTR: ()

A marker to prevent implementors from forgetting to use #[vtable] attribute when implementing this trait.

Provided Associated Constants§

Source

const OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None

The table of OF device ids supported by the driver.

Source

const ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None

The table of ACPI device ids supported by the driver.

Source

const HAS_PROBE: bool = false

Indicates if the probe method is overridden by the implementor.

Source

const HAS_UNBIND: bool = false

Indicates if the unbind method is overridden by the implementor.

Source

const HAS_RECEIVE: bool = false

Indicates if the receive method is overridden by the implementor.

Required Associated Types§

Source

type IdInfo: 'static

The type holding driver private data about each device id supported by the driver.

Source

type Data<'bound>: Send + Sync + 'bound

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

Required Methods§

Source

fn probe<'bound>( sdev: &'bound Device<Core<'_>>, id_info: Option<&'bound Self::IdInfo>, ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound

Serial device bus device driver probe.

Called when a new serial device bus device is added or discovered. Implementers should attempt to initialize the device here.

Provided Methods§

Source

fn unbind<'bound>( sdev: &'bound Device<Core<'_>>, this: Pin<&Self::Data<'bound>>, )

Serial device bus device driver unbind.

Called when a Device is unbound from its bound Driver. Implementing this callback is optional.

This callback serves as a place for drivers to perform teardown operations that require a &Device<Core> or &Device<Bound> reference. For instance.

Otherwise, release operations for driver resources should be performed in Drop.

Source

fn receive<'bound>( sdev: &'bound Device<Bound>, this: Pin<&Self::Data<'bound>>, data: &[u8], ) -> usize

Serial device bus device data receive callback.

Called when data got received from device.

Returns the number of bytes accepted.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§