pub struct Request {
pub direction: Direction,
pub request_type: RequestType,
pub recipient: Recipient,
pub request: u8,
pub value: u16,
pub index: u16,
pub length: u16,
}Expand description
A parsed USB SETUP packet.
Fields§
§direction: DirectionTransfer direction (from host’s perspective).
request_type: RequestTypeWho defined this request.
recipient: RecipientWho the request is directed at.
request: u8Request code (bRequest).
value: u16Request-specific value (wValue).
index: u16Request-specific index (wIndex).
length: u16Number of bytes in the data stage (wLength).
Implementations§
Source§impl Request
impl Request
Sourcepub fn parse(buf: &[u8]) -> Option<Self>
pub fn parse(buf: &[u8]) -> Option<Self>
Parse a SETUP packet from its 8-byte wire encoding.
Returns None when fewer than eight bytes are available.
Sourcepub const fn custom(
direction: Direction,
request_type: RequestType,
recipient: Recipient,
request: u8,
value: u16,
index: u16,
length: u16,
) -> Self
pub const fn custom( direction: Direction, request_type: RequestType, recipient: Recipient, request: u8, value: u16, index: u16, length: u16, ) -> Self
Build a request from its fields.
Sourcepub const fn get_descriptor(
kind: u8,
index: u8,
language: u16,
length: u16,
) -> Self
pub const fn get_descriptor( kind: u8, index: u8, language: u16, length: u16, ) -> Self
GET_DESCRIPTOR, which always reads from the device.
Sourcepub const fn set_address(address: u8) -> Self
pub const fn set_address(address: u8) -> Self
SET_ADDRESS.
Sourcepub const fn set_configuration(value: u8) -> Self
pub const fn set_configuration(value: u8) -> Self
SET_CONFIGURATION.
Sourcepub const fn set_interface(interface: u8, alternate: u8) -> Self
pub const fn set_interface(interface: u8, alternate: u8) -> Self
SET_INTERFACE.
Sourcepub const fn get_status(recipient: Recipient, index: u16) -> Self
pub const fn get_status(recipient: Recipient, index: u16) -> Self
GET_STATUS, which always returns two bytes.
Sourcepub const fn clear_feature(
recipient: Recipient,
feature: u16,
index: u16,
) -> Self
pub const fn clear_feature( recipient: Recipient, feature: u16, index: u16, ) -> Self
CLEAR_FEATURE.
Sourcepub const fn set_feature(recipient: Recipient, feature: u16, index: u16) -> Self
pub const fn set_feature(recipient: Recipient, feature: u16, index: u16) -> Self
SET_FEATURE.
Sourcepub const fn clear_halt(endpoint: u8) -> Self
pub const fn clear_halt(endpoint: u8) -> Self
CLEAR_FEATURE(ENDPOINT_HALT) for an endpoint.
Sourcepub fn descriptor_type_index(&self) -> (u8, u8)
pub fn descriptor_type_index(&self) -> (u8, u8)
Extract (descriptor_type, descriptor_index) from wValue as used in
GET_DESCRIPTOR requests.
Sourcepub fn endpoint_address(&self) -> EndpointAddress
pub fn endpoint_address(&self) -> EndpointAddress
Extract the endpoint address from wIndex for endpoint-directed requests.