Skip to main content

SetupPacket

Struct SetupPacket 

Source
#[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: u8

The type and specific target of the request.

§bRequest: u8

The particular request.

§wValue: u16

A parameter to the request.

§wIndex: u16

A second parameter to the request.

§wLength: u16

The length of the subsequent IN or OUT data phase; can be zero if the setup packet itself contains all the required information.

Trait Implementations§

Source§

impl Debug for SetupPacket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Format for SetupPacket

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.