pub struct SetupPacket {
pub request_type: RequestType,
pub request: u8,
pub value: u16,
pub index: u16,
pub length: u16,
}Expand description
USB Control Setup Packet.
Convenience type for building SETUP packets; serialize with
SetupPacket::to_bytes before passing to a USB driver.
Setup data format is described in USB spec Table 9-2.
Fields§
§request_type: RequestTypebmRequestType - Request characteristics: direction, type, recipient.
See RequestType for details.
request: u8bRequest - Request code.
See Table 9-3 of USB spec for standard ones.
value: u16wValue - Use depending on request field.
index: u16wIndex - Use depending on request field.
length: u16wLength - Number of bytes to transfer in data stage if there is one.
Implementations§
Source§impl SetupPacket
impl SetupPacket
Sourcepub const fn to_bytes(self) -> [u8; 8]
pub const fn to_bytes(self) -> [u8; 8]
Serialize this SETUP packet to its 8-byte wire format.
Multi-byte fields are emitted in little-endian order, as required by USB 2.0 spec §8.1.
Sourcepub const fn from_bytes(wire: [u8; 8]) -> Self
pub const fn from_bytes(wire: [u8; 8]) -> Self
Deserialize a wire format SETUP packet.
Multi-byte fields are interpreted in little-endian order, as required by USB 2.0 spec §8.1.
Sourcepub const fn get_descriptor(
class: bool,
desc_type: u8,
index: u8,
max_len: u16,
) -> Self
pub const fn get_descriptor( class: bool, desc_type: u8, index: u8, max_len: u16, ) -> Self
Build a GET_DESCRIPTOR SETUP packet delivered to the Device recipient.
class selects Standard (false) vs Class (true) request type.
Sourcepub const fn get_device_descriptor(max_len: u16) -> Self
pub const fn get_device_descriptor(max_len: u16) -> Self
Build a GET_DESCRIPTOR(Device) SETUP packet.
Sourcepub const fn get_config_descriptor(index: u8, max_len: u16) -> Self
pub const fn get_config_descriptor(index: u8, max_len: u16) -> Self
Build a GET_DESCRIPTOR(Configuration) SETUP packet.
Sourcepub const fn get_interface_descriptor(
desc_type: u8,
interface: u16,
max_len: u16,
) -> Self
pub const fn get_interface_descriptor( desc_type: u8, interface: u16, max_len: u16, ) -> Self
Build a standard GET_DESCRIPTOR SETUP packet delivered to an Interface recipient.
Used for interface-owned descriptors such as the HID Report Descriptor.
Sourcepub const fn get_hid_report_descriptor(interface: u8, len: u16) -> Self
pub const fn get_hid_report_descriptor(interface: u8, len: u16) -> Self
Build a GET_DESCRIPTOR(HID Report Descriptor) SETUP packet.
interface is the HID interface number; len is from HidInfo::report_descriptor_len.
Sourcepub const fn set_address(address: u8) -> Self
pub const fn set_address(address: u8) -> Self
Build a SET_ADDRESS SETUP packet.
Sourcepub const fn set_configuration(config_value: u8) -> Self
pub const fn set_configuration(config_value: u8) -> Self
Build a SET_CONFIGURATION SETUP packet.
Sourcepub const fn get_configuration() -> Self
pub const fn get_configuration() -> Self
Build a GET_CONFIGURATION SETUP packet.
Sourcepub const fn class_interface_out(
request: u8,
value: u16,
interface: u16,
length: u16,
) -> Self
pub const fn class_interface_out( request: u8, value: u16, interface: u16, length: u16, ) -> Self
Build a class-specific interface request SETUP packet, host-to-device.
Pass length = 0 for requests with no data stage.
Sourcepub const fn class_interface_in(
request: u8,
value: u16,
interface: u16,
length: u16,
) -> Self
pub const fn class_interface_in( request: u8, value: u16, interface: u16, length: u16, ) -> Self
Build a class-specific interface request SETUP packet, device-to-host.
Trait Implementations§
Source§impl Clone for SetupPacket
impl Clone for SetupPacket
Source§fn clone(&self) -> SetupPacket
fn clone(&self) -> SetupPacket
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more