usb: merge alloc_control_pipe
and into_bus
into start
.
This prevents calling `alloc_control_pipe` twice at compile time, which was always an error.
This commit is contained in:
@ -14,7 +14,7 @@ pub trait Driver<'a> {
|
||||
|
||||
/// Allocates an endpoint and specified endpoint parameters. This method is called by the device
|
||||
/// and class implementations to allocate endpoints, and can only be called before
|
||||
/// [`enable`](UsbBus::enable) is called.
|
||||
/// [`start`](UsbBus::start) is called.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@ -37,14 +37,15 @@ pub trait Driver<'a> {
|
||||
interval: u8,
|
||||
) -> Result<Self::EndpointIn, EndpointAllocError>;
|
||||
|
||||
fn alloc_control_pipe(
|
||||
&mut self,
|
||||
max_packet_size: u16,
|
||||
) -> Result<Self::ControlPipe, EndpointAllocError>;
|
||||
|
||||
/// Enables and initializes the USB peripheral. Soon after enabling the device will be reset, so
|
||||
/// there is no need to perform a USB reset in this method.
|
||||
fn into_bus(self) -> Self::Bus;
|
||||
/// Start operation of the USB device.
|
||||
///
|
||||
/// This returns the `Bus` and `ControlPipe` instances that are used to operate
|
||||
/// the USB device. Additionally, this makes all the previously allocated endpoints
|
||||
/// start operating.
|
||||
///
|
||||
/// This consumes the `Driver` instance, so it's no longer possible to allocate more
|
||||
/// endpoints.
|
||||
fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe);
|
||||
|
||||
/// Indicates that `set_device_address` must be called before accepting the corresponding
|
||||
/// control transfer, not after.
|
||||
|
@ -126,7 +126,7 @@ struct Inner<'d, D: Driver<'d>> {
|
||||
|
||||
impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
|
||||
pub(crate) fn build(
|
||||
mut driver: D,
|
||||
driver: D,
|
||||
config: Config<'d>,
|
||||
handler: Option<&'d dyn DeviceStateHandler>,
|
||||
device_descriptor: &'d [u8],
|
||||
@ -135,13 +135,9 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
|
||||
interfaces: Vec<Interface<'d>, MAX_INTERFACE_COUNT>,
|
||||
control_buf: &'d mut [u8],
|
||||
) -> 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.
|
||||
// Start the USB bus.
|
||||
// This prevent further allocation by consuming the driver.
|
||||
let bus = driver.into_bus();
|
||||
let (bus, control) = driver.start(config.max_packet_size_0 as u16);
|
||||
|
||||
Self {
|
||||
control_buf,
|
||||
|
Reference in New Issue
Block a user