Core Types

USB types – defines enumerations that describe standard USB types

class usb_construct.types.USBDirection(value)

Class representing USB directions.

classmethod parse(value) → USBDirection

Helper that converts a numeric field into a direction.

Return type:

USBDirection

classmethod from_request_type(request_type_int: int) → USBDirection

Helper method that extracts the direction from a request_type integer.

Return type:

USBDirection

classmethod from_endpoint_address(address: int) → USBDirection

Helper method that extracts the direction from an endpoint address.

Return type:

USBDirection

token() → USBPacketID

Generates the token corresponding to the given direction.

Return type:

USBPacketID

reverse() → Literal[0, 1]

Returns the reverse of the given direction.

Return type:

Literal[0, 1]

to_endpoint_address(endpoint_number: int) → int

Helper method that converts and endpoint_number to an address, given direction.

Return type:

int

class usb_construct.types.USBPIDCategory(value)

Category constants for each of the groups that PIDs can fall under.

class usb_construct.types.USBPacketID(value)

Enumeration specifying all of the valid USB PIDs we can handle.

classmethod from_byte(byte: Iterable[SupportsIndex] | SupportsBytes, skip_checks: bool = False) → USBPacketID

Creates a PID object from a byte.

Return type:

USBPacketID

classmethod from_int(value: int, skip_checks: bool = True) → USBPacketID

Create a PID object from an integer.

Return type:

USBPacketID

classmethod from_name(name: str) → USBPacketID

Create a PID object from a string representation of its name.

Return type:

USBPacketID

classmethod parse(value: bytes | str | int) → USBPacketID

Attempt to create a PID object from a number, byte, or string.

Return type:

USBPacketID

category() → USBPIDCategory

Returns the USBPIDCategory that each given PID belongs to.

Return type:

USBPIDCategory

is_data() → bool

Returns true iff the given PID represents a DATA packet.

Return type:

bool

is_token() → bool

Returns true iff the given PID represents a token packet.

Return type:

bool

is_handshake() → bool

Returns true iff the given PID represents a handshake packet.

Return type:

bool

is_invalid() → bool

Returns true if this object is an attempt to encapsulate an invalid PID.

Return type:

bool

direction() → Literal[USBDirection.IN, USBDirection.OUT] | None

Get a USB direction from a PacketID.

Return type:

Literal[<USBDirection.IN: 1>, <USBDirection.OUT: 0>] | None

summarize() → str | None

Return a summary of the given packet.

Return type:

str | None

byte() → int

Return the PID’s value with its upper nibble.

Return type:

int

class usb_construct.types.USBRequestRecipient(value)

Enumeration that describes each ‘recipient’ of a USB request field.

classmethod from_integer(value: int) → USBRequestRecipient

Special factory that correctly handles reserved values.

Return type:

USBRequestRecipient

classmethod from_request_type(request_type_int: int) → USBRequestRecipient

Helper method that extracts the type from a request_type integer.

Return type:

USBRequestRecipient

class usb_construct.types.USBRequestType(value)

Enumeration that describes each possible Type field for a USB request.

classmethod from_request_type(request_type_int: int) → USBRequestType

Helper method that extracts the type from a request_type integer.

Return type:

USBRequestType

class usb_construct.types.USBTransferType(value)
class usb_construct.types.LanguageIDs(value)
class usb_construct.types.DescriptorTypes(value)
class usb_construct.types.USBSynchronizationType(value)
class usb_construct.types.USBUsageType(value)
class usb_construct.types.USBStandardRequests(value)