pub trait Driver<G: BankPins>: DriverMeta {
// Required method
fn create(
gpio_bank: GpioBank<G>,
slot: ModuleSlot,
registry: &mut Registry,
bus_allocator: &mut BusAllocator,
) -> impl Future<Output = Result<(), DriverError>>;
}Expand description
Initializes a module and publishes the capabilities it provides.
The platform transfers ownership of the complete GpioBank to the driver.
Bus resources allocated through BusAllocator are startup allocations and
remain owned by the resulting capability for the rest of the boot.
Drivers are run on core 0, so any task spawn will also run on core 0
§Example
A two-button module can consume GPIO 0 and GPIO 1 and publish each button as an independent resource:
use xpanse_api::{
bus::allocator::BusAllocator,
driver::{Driver, DriverError, DriverMeta},
gpio_bank::{BankPins, GpioBank},
interfaces::buttons::{A, B, pin_button},
metadata::{ModuleDetectResistor, ModuleID, ModuleSlot},
registry::Registry,
};
struct TwoButtonDriver;
impl DriverMeta for TwoButtonDriver {
const ID: ModuleID = ModuleID {
md0: ModuleDetectResistor::R1K6,
md1: ModuleDetectResistor::R1K5,
};
}
impl<G: BankPins> Driver<G> for TwoButtonDriver {
async fn create(
bank: GpioBank<G>,
slot: ModuleSlot,
registry: &mut Registry,
buses: &mut BusAllocator,
) -> Result<(), DriverError> {
registry.register(slot, Self::ID, pin_button::<A>(bank.gpio0.into()));
registry.register(slot, Self::ID, pin_button::<B>(bank.gpio1.into()));
let _ = buses;
Ok(())
}
}Required Methods§
Sourcefn create(
gpio_bank: GpioBank<G>,
slot: ModuleSlot,
registry: &mut Registry,
bus_allocator: &mut BusAllocator,
) -> impl Future<Output = Result<(), DriverError>>
fn create( gpio_bank: GpioBank<G>, slot: ModuleSlot, registry: &mut Registry, bus_allocator: &mut BusAllocator, ) -> impl Future<Output = Result<(), DriverError>>
Consumes a module’s pins, initializes its hardware, and registers its capabilities.
Implementations should avoid publishing partially initialized resources
and return DriverError::InitFailed if setup cannot complete.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".