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§
Sourceconst USE_VTABLE_ATTR: ()
const USE_VTABLE_ATTR: ()
A marker to prevent implementors from forgetting to use #[vtable]
attribute when implementing this trait.
Provided Associated Constants§
Sourceconst OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None
const OF_ID_TABLE: Option<IdTable<Self::IdInfo>> = None
The table of OF device ids supported by the driver.
Sourceconst ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None
const ACPI_ID_TABLE: Option<IdTable<Self::IdInfo>> = None
The table of ACPI device ids supported by the driver.
Sourceconst HAS_UNBIND: bool = false
const HAS_UNBIND: bool = false
Indicates if the unbind method is overridden by the implementor.
Sourceconst HAS_RECEIVE: bool = false
const HAS_RECEIVE: bool = false
Indicates if the receive method is overridden by the implementor.
Required Associated Types§
Required Methods§
Sourcefn probe<'bound>(
sdev: &'bound Device<Core<'_>>,
id_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound
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§
Sourcefn unbind<'bound>(
sdev: &'bound Device<Core<'_>>,
this: Pin<&Self::Data<'bound>>,
)
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".