Async-ify Driver::enable and UsbDeviceBuilder::build

This commit is contained in:
alexmoon
2022-04-06 22:10:18 -04:00
parent a1754ac8a8
commit 6abbfa9a92
8 changed files with 53 additions and 39 deletions

View File

@ -72,7 +72,7 @@ pub struct UsbDevice<'d, D: Driver<'d>> {
}
impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
pub(crate) fn build(
pub(crate) async fn build(
mut driver: D,
config: Config<'d>,
device_descriptor: &'d [u8],
@ -80,17 +80,17 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
bos_descriptor: &'d [u8],
interfaces: Vec<(u8, &'d mut dyn ControlHandler), MAX_INTERFACE_COUNT>,
control_buf: &'d mut [u8],
) -> Self {
) -> UsbDevice<'d, D> {
let control = driver
.alloc_control_pipe(config.max_packet_size_0 as u16)
.expect("failed to alloc control endpoint");
// Enable the USB bus.
// This prevent further allocation by consuming the driver.
let driver = driver.enable();
let bus = driver.enable().await;
Self {
bus: driver,
bus,
config,
control: ControlPipe::new(control),
device_descriptor,