Skip to main content

Module host

Module host 

Source
Expand description

Host-side USB stack.

The host stack is split the same way as the device stack: everything below the controller is hardware independent, and a peripheral driver implements HostController.

  application                  class::hid::Keyboard, your own class driver
  ────────────────────────
  Device                       enumeration, control transfers
  Pipe                         bulk and interrupt transfers
  ────────────────────────
  HostController               trait: port, channels, transactions
  ────────────────────────
  (a peripheral driver)        implements HostController

Transfers are expressed at transaction level and driven synchronously: a call blocks until the controller halts the channel, so no interrupts, no DMA and no async are involved. Enumeration is a fixed sequence of control transfers (Host::enumerate runs it), and everything a device offers afterwards is reachable through Device::control and Pipe.

§What is covered

  • Root port only: hubs are not supported, so a device must be plugged into the controller’s own port
  • Control, bulk and interrupt transfers at low, full and high speed
  • Device, configuration, interface, endpoint and string descriptors
  • Classes: HID boot keyboards (class::hid::Keyboard)

Isochronous transfers and the hub class are not implemented.

§Example

ⓘ
use usb_stack::host::{Host, class::hid::Keyboard};

let bus = Host::new(&my_controller);

loop {
    let device = match bus.enumerate() {
        Ok(device) => device,
        Err(error) => continue, // nothing attached, or a device that misbehaves
    };
    if let Ok(keyboard) = Keyboard::open(&device) {
        let mut previous = Default::default();
        while let Ok(report) = keyboard.read() {
            for key in report.new_keys(&previous) {
                defmt::info!("key {}", key);
            }
            previous = report;
        }
    }
}

Re-exports§

pub use crate::request::Request;
pub use controller::Channel;
pub use controller::DeviceAddress;
pub use controller::EndpointConfig;
pub use controller::HostController;
pub use controller::PortStatus;
pub use controller::Speed;
pub use controller::Toggle;
pub use descriptor::Configuration;
pub use descriptor::Descriptor;
pub use descriptor::Descriptors;
pub use descriptor::DeviceDescriptor;
pub use descriptor::EndpointDescriptor;
pub use descriptor::Endpoints;
pub use descriptor::Interface;
pub use descriptor::Interfaces;
pub use device::CONFIG_MAX;
pub use device::Device;
pub use error::HostError;
pub use error::HostResult;
pub use pipe::Pipe;

Modules§

class
The classes that drive a device through the host stack.
controller
The hardware abstraction the host protocol layer runs on.
descriptor
Parsing of the descriptors a device returns.
device
Enumeration and control transfers.
error
Errors reported by the host stack.
pipe
Bulk and interrupt pipes.

Structs§

Host
The root port of a host controller.