#[repr(C)]pub struct SetupPacket {
pub bmRequestType: u8,
pub bRequest: u8,
pub wValue: u16,
pub wIndex: u16,
pub wLength: u16,
}Expand description
A SETUP packet as transmitted on control endpoints.
All transactions on control endpoints start with a SETUP packet of this format. (Some are then followed by IN or OUT data packets, but others are not).
The format of this packet (and the un-Rust-like names of its fields) are defined in the USB 2.0 specification, section 9.3. Other sections of the USB specification, and of the specifications of particular device classes, dictate what to put in these fields.
Control transactions are performed using
UsbBus::control_transfer().
For instance, here is how to read the MAC address of an AX88772 USB-to-Ethernet adaptor:
let mut data = [0u8; 6];
let rc = bus.control_transfer(
&device,
SetupPacket {
bmRequestType: DEVICE_TO_HOST | VENDOR_REQUEST,
bRequest: 0x13,
wValue: 0,
wIndex: 0,
wLength: 6,
},
DataPhase::In(&mut data),
)
.await;Here, the “Request Type” indicates a vendor-specific (AX88772-specific)
request, and the “0x13” is taken from the AX88772 datasheet and is the
code for “read MAC address”. And a MAC address is 6 bytes long, as seen
in wLength.
Fields§
§bmRequestType: u8The type and specific target of the request.
bRequest: u8The particular request.
wValue: u16A parameter to the request.
wIndex: u16A second parameter to the request.
wLength: u16The length of the subsequent IN or OUT data phase; can be zero if the setup packet itself contains all the required information.